Java Code Examples for org.apache.bcel.generic.MethodGen#getLineNumberTable()

The following examples show how to use org.apache.bcel.generic.MethodGen#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 6 votes vote down vote up
/**
 * Factory method for creating a source line annotation describing the
 * source line number for a visited instruction.
 *
 * @param classContext
 *            the ClassContext
 * @param methodGen
 *            the MethodGen object representing the method
 * @param handle
 *            the InstructionHandle containing the visited instruction
 * @return the SourceLineAnnotation, or null if we do not have line number
 *         information for the instruction
 */
@Nonnull
public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, MethodGen methodGen, String sourceFile,
        @Nonnull InstructionHandle handle) {
    LineNumberTable table = methodGen.getLineNumberTable(methodGen.getConstantPool());
    String className = methodGen.getClassName();

    int bytecodeOffset = handle.getPosition();

    if (table == null) {
        return createUnknown(className, sourceFile, bytecodeOffset, bytecodeOffset);
    }

    int lineNumber = table.getSourceLine(handle.getPosition());
    return new SourceLineAnnotation(className, sourceFile, lineNumber, lineNumber, bytecodeOffset, bytecodeOffset);
}
 
Example 2
Source File: SourceLineAnnotation.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Factory method for creating a source line annotation describing an entire
 * method.
 *
 * @param methodGen
 *            the method being visited
 * @return the SourceLineAnnotation, or null if we do not have line number
 *         information for the method
 */
public static SourceLineAnnotation fromVisitedMethod(MethodGen methodGen, String sourceFile) {
    LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool());
    String className = methodGen.getClassName();
    int codeSize = methodGen.getInstructionList().getLength();
    if (lineNumberTable == null) {
        return createUnknown(className, sourceFile, 0, codeSize - 1);
    }
    return forEntireMethod(className, sourceFile, lineNumberTable, codeSize);
}
 
Example 3
Source File: SourceLineAnnotation.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Factory method for creating a source line annotation describing the
 * source line numbers for a range of instruction in a method.
 *
 * @param classContext
 *            theClassContext
 * @param methodGen
 *            the method
 * @param start
 *            the start instruction
 * @param end
 *            the end instruction (inclusive)
 */
public static SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, MethodGen methodGen,
        String sourceFile, InstructionHandle start, InstructionHandle end) {
    LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool());
    String className = methodGen.getClassName();

    if (lineNumberTable == null) {
        return createUnknown(className, sourceFile, start.getPosition(), end.getPosition());
    }

    int startLine = lineNumberTable.getSourceLine(start.getPosition());
    int endLine = lineNumberTable.getSourceLine(end.getPosition());
    return new SourceLineAnnotation(className, sourceFile, startLine, endLine, start.getPosition(), end.getPosition());
}