@Override public IFigure getTooltip(Object element) { if (element instanceof BasicBlock) { BasicBlock bb = (BasicBlock) element; IR ir = irView.getIR(); IDocument doc = irView.getDocument(); IMethod method = ir.getMethod(); StringBuffer result = new StringBuffer(); int start = bb.getFirstInstructionIndex(); int end = bb.getLastInstructionIndex(); SSAInstruction[] instructions = ir.getInstructions(); for (int j = start; j <= end; j++) { if (instructions[j] != null) { int sourceLineNum = method.getLineNumber(j); int lineNumber = sourceLineNum - 1; // IDocument indexing is 0-based try { int lineOffset = doc.getLineOffset(lineNumber); int lineLength = doc.getLineLength(lineNumber); String sourceCode = doc.get(lineOffset, lineLength).trim(); result.append(sourceCode); } catch (BadLocationException e) { } result.append("\n"); } } return new Label(result.toString()); } return null; }
/** Taken from com.ibm.wala.viz.PDFViewUtil */ @Override public String getText(Object element) { if (element instanceof BasicBlock) { BasicBlock bb = (BasicBlock) element; IR ir = irView.getIR(); StringBuilder result = new StringBuilder(); int start = bb.getFirstInstructionIndex(); int end = bb.getLastInstructionIndex(); result.append("BB").append(bb.getNumber()); if (bb.isEntryBlock()) { result.append(" (en)\n"); } else if (bb.isExitBlock()) { result.append(" (ex)\n"); } if (bb instanceof ExceptionHandlerBasicBlock) { result.append("<Handler>"); } result.append("\n"); for (Iterator<SSAPhiInstruction> it = bb.iteratePhis(); it.hasNext(); ) { SSAPhiInstruction phi = it.next(); if (phi != null) { result.append(phi.toString(ir.getSymbolTable())).append("\n"); } } if (bb instanceof ExceptionHandlerBasicBlock) { ExceptionHandlerBasicBlock ebb = (ExceptionHandlerBasicBlock) bb; SSAGetCaughtExceptionInstruction s = ebb.getCatchInstruction(); if (s != null) { result.append(s.toString(ir.getSymbolTable())).append("\n"); } else { result.append(" No catch instruction. Unreachable?\n"); } } SSAInstruction[] instructions = ir.getInstructions(); IMethod method = ir.getMethod(); for (int j = start; j <= end; j++) { if (instructions[j] != null) { String x; int sourceLineNum = method.getLineNumber(j); x = String.format( j + " [L%03d] " + instructions[j].toString(ir.getSymbolTable()), sourceLineNum); String padded = String.format("%1$-35s", x); result.append(padded); result.append("\n"); result.append(SSAValuesToLocalVariables(instructions[j], j, ir)); result.append("\n"); } } for (Iterator<SSAPiInstruction> it = bb.iteratePis(); it.hasNext(); ) { SSAPiInstruction pi = it.next(); if (pi != null) { result.append(" " + pi.toString(ir.getSymbolTable())).append("\n"); } } return result.toString(); } if (element instanceof EntityConnectionData) { return "\n"; } return ""; }