public static int getNextSourceLine(LineNumberTable lineNumbers, int sourceLine) { int result = Integer.MAX_VALUE; for (LineNumber ln : lineNumbers.getLineNumberTable()) { int thisLine = ln.getLineNumber(); if (sourceLine < thisLine && thisLine < result) { result = thisLine; } } return result; } }
@Override public void visitLineNumberTable(LineNumberTable obj) { super.visitLineNumberTable(obj); LineNumber[] line_number_table = obj.getLineNumberTable(); for (LineNumber aLine_number_table : line_number_table) { aLine_number_table.accept(this); } }
private void checkTable(LineNumberTable table) { if (DEBUG) { System.out.println("line number table has length " + table.getTableLength()); } LineNumber[] entries = table.getLineNumberTable(); int lastBytecode = -1; for (int i = 0; i < entries.length; ++i) { LineNumber ln = entries[i]; if (DEBUG) { System.out.println("Entry " + i + ": pc=" + ln.getStartPC() + ", line=" + ln.getLineNumber()); } int pc = ln.getStartPC(); if (pc <= lastBytecode) { throw new IllegalStateException("LineNumberTable is not sorted"); } } }
int prevStartPc = -1; if (lineNumberTable != null) { for (LineNumber line : lineNumberTable.getLineNumberTable()) { int newLine = line.getLineNumber(); if (newLine == lineNum || newLine == -1) {
private int getNextExecutableLineNumber(LineNumberTable linenumbers, int PC) { LineNumber[] entries = linenumbers.getLineNumberTable(); int beforePC = 0; int i = 0; for (; i < entries.length && entries[i].getStartPC() < PC; i++) { int line = entries[i].getLineNumber(); if (line > beforePC) { beforePC = line; } } if (i < entries.length) { int secondChoice = entries[i].getLineNumber(); for (; i < entries.length; i++) { int line = entries[i].getLineNumber(); if (line > beforePC) { return line; } } return secondChoice; } else { return entries[entries.length - 1].getLineNumber(); } }
/** * Create a SourceLineAnnotation covering an entire method. * * @param className * name of the class the method is in * @param sourceFile * source file containing the method * @param lineNumberTable * the method's LineNumberTable * @param codeSize * size in bytes of the method's code * @return a SourceLineAnnotation covering the entire method */ public static SourceLineAnnotation forEntireMethod(@DottedClassName String className, String sourceFile, LineNumberTable lineNumberTable, int codeSize) { LineNumber[] table = lineNumberTable.getLineNumberTable(); if (table != null && table.length > 0) { LineNumber first = table[0]; LineNumber last = table[table.length - 1]; return new SourceLineAnnotation(className, sourceFile, first.getLineNumber(), last.getLineNumber(), 0, codeSize - 1); } else { return createUnknown(className, sourceFile, 0, codeSize - 1); } }
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); }
for (LineNumber line : lineNumberTable.getLineNumberTable()) { if (line.getStartPC() > tightEndPC) { break;
private void foundSwitchNoDefault(SourceLineAnnotation s) { LineNumberTable table = getCode().getLineNumberTable(); if (table != null) { int startLine = s.getStartLine(); int prev = Integer.MIN_VALUE; for (LineNumber ln : table.getLineNumberTable()) { int thisLineNumber = ln.getLineNumber(); if (thisLineNumber < startLine && thisLineNumber > prev && ln.getStartPC() < s.getStartBytecode()) { prev = thisLineNumber; } } int diff = startLine - prev; if (diff > 5) { return; } bugAccumulator.accumulateBug(new BugInstance(this, "SF_SWITCH_NO_DEFAULT", NORMAL_PRIORITY).addClassAndMethod(this), s); } }
int firstLine = Integer.MAX_VALUE; int bytecode = 0; LineNumber[] entries = lnt.getLineNumberTable(); for (LineNumber entry : entries) { if (entry.getLineNumber() < firstLine) {
public static int getNextSourceLine(LineNumberTable lineNumbers, int sourceLine) { int result = Integer.MAX_VALUE; for (LineNumber ln : lineNumbers.getLineNumberTable()) { int thisLine = ln.getLineNumber(); if (sourceLine < thisLine && thisLine < result) { result = thisLine; } } return result; } }
@Override public void visitLineNumberTable(final LineNumberTable table) { stack.push(table); table.accept(visitor); final LineNumber[] numbers = table.getLineNumberTable(); for (final LineNumber number : numbers) { number.accept(this); } stack.pop(); }
public void visitLineNumberTable(LineNumberTable table) { stack.push(table); table.accept(visitor); LineNumber[] numbers = table.getLineNumberTable(); for(int i=0; i < numbers.length; i++) numbers[i].accept(this); stack.pop(); }
public LineNumberCursor(Code code) { if (code == null) return; LineNumberTable table= code.getLineNumberTable(); if (table == null) return; lineNumbers= table.getLineNumberTable(); length= lineNumbers.length; Arrays.sort(lineNumbers, new LineNumberComparator()); }
@Override public void visitLineNumberTable(LineNumberTable obj) { super.visitLineNumberTable(obj); LineNumber[] line_number_table = obj.getLineNumberTable(); for (LineNumber aLine_number_table : line_number_table) { aLine_number_table.accept(this); } }
private static Integer getMethodLineNumber(Method method) { LineNumberTable lineNumberTable = method.getLineNumberTable(); return lineNumberTable == null ? -1 : lineNumberTable.getLineNumberTable()[0].getLineNumber(); }
private static Integer getMethodLineNumber(Method method) { LineNumberTable lineNumberTable = method.getLineNumberTable(); return lineNumberTable == null ? -1 : lineNumberTable.getLineNumberTable()[0].getLineNumber(); }
// import org.apache.bcel.classfile.ClassParser; JavaClass fooClazz = new ClassParser( "Foo.class" ).parse(); for( Method m : fooClazz.getMethods() ) { LineNumberTable lnt = m.getLineNumberTable(); LineNumber[] tab = lnt.getLineNumberTable(); for( LineNumber ln : tab ) { System.out.println( ln.getLineNumber() ); } }
public LineNumberTable(LineNumberTable c) { this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool()); }
public LineNumberTable(final LineNumberTable c) { this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool()); }