Java Code Examples for org.apache.bcel.classfile.Code#getLineNumberTable()
The following examples show how to use
org.apache.bcel.classfile.Code#getLineNumberTable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceLineAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static LineNumberTable getLineNumberTable(PreorderVisitor visitor) { Code code = visitor.getMethod().getCode(); if (code == null) { return null; } return code.getLineNumberTable(); }
Example 2
Source File: SourceLineAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
static SourceLineAnnotation getSourceAnnotationForClass(String className, String sourceFileName) { int lastLine = -1; int firstLine = Integer.MAX_VALUE; try { JavaClass targetClass = AnalysisContext.currentAnalysisContext().lookupClass(className); for (Method m : targetClass.getMethods()) { Code c = m.getCode(); if (c != null) { LineNumberTable table = c.getLineNumberTable(); if (table != null) { for (LineNumber line : table.getLineNumberTable()) { lastLine = Math.max(lastLine, line.getLineNumber()); firstLine = Math.min(firstLine, line.getLineNumber()); } } } } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } if (firstLine < Integer.MAX_VALUE) { return new SourceLineAnnotation(className, sourceFileName, firstLine, lastLine, -1, -1); } return SourceLineAnnotation.createUnknown(className, sourceFileName); }
Example 3
Source File: Util.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
public static int getSizeOfSurroundingTryBlock(ConstantPool constantPool, Code code, @CheckForNull @SlashedClassName String vmNameOfExceptionClass, int pc) { int size = Integer.MAX_VALUE; int tightStartPC = 0; int tightEndPC = Integer.MAX_VALUE; if (code.getExceptionTable() == null) { return size; } for (CodeException catchBlock : code.getExceptionTable()) { if (vmNameOfExceptionClass != null) { Constant catchType = constantPool.getConstant(catchBlock.getCatchType()); if (catchType == null && !vmNameOfExceptionClass.isEmpty() || catchType instanceof ConstantClass && !((ConstantClass) catchType).getBytes(constantPool).equals(vmNameOfExceptionClass)) { continue; } } int startPC = catchBlock.getStartPC(); int endPC = catchBlock.getEndPC(); if (pc >= startPC && pc <= endPC) { int thisSize = endPC - startPC; if (size > thisSize) { size = thisSize; tightStartPC = startPC; tightEndPC = endPC; } } } if (size == Integer.MAX_VALUE) { return size; } // try to guestimate number of lines that correspond size = (size + 7) / 8; LineNumberTable lineNumberTable = code.getLineNumberTable(); if (lineNumberTable == null) { return size; } int count = 0; for (LineNumber line : lineNumberTable.getLineNumberTable()) { if (line.getStartPC() > tightEndPC) { break; } if (line.getStartPC() >= tightStartPC) { count++; } } return count; }
Example 4
Source File: FindBadForLoop.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void visit(Code obj) { lastRegStore = -1; lineNumbers = obj.getLineNumberTable(); super.visit(obj); }