@Override public void visit(LineNumber obj) { sawLineNumbers = true; int line = obj.getLineNumber(); lines.set(line); }
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(); } }
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; } }
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"); } } }
/** * 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); }
if (lineNumberTable != null) { for (LineNumber line : lineNumberTable.getLineNumberTable()) { int newLine = line.getLineNumber(); if (newLine == lineNum || newLine == -1) { continue;
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); } }
LineNumber[] entries = lnt.getLineNumberTable(); for (LineNumber entry : entries) { if (entry.getLineNumber() < firstLine) { firstLine = entry.getLineNumber(); bytecode = entry.getStartPC();
@Override public void visit(LineNumber obj) { sawLineNumbers = true; int line = obj.getLineNumber(); lines.set(line); }
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(); } }
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; } }
/** * Initialize from another object. * * @param c the object to copy */ public LineNumber(final LineNumber c) { this(c.getStartPC(), c.getLineNumber()); }
/** * Initialize from another object. */ public LineNumber(LineNumber c) { this(c.getStartPC(), c.getLineNumber()); }
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(); }
public LineNumberTableEntry(LineNumber []linums, int _nameIndex, int _length) { super(_nameIndex, _length); for (LineNumber i : linums) { getPool().add(new StartLineNumberPair(i.getStartPC(), i.getLineNumber())); } }
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"); } } }
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); }
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); } }