edu.umd.cs.findbugs

Class SourceLineAnnotation

public class SourceLineAnnotation extends Object implements BugAnnotation

A BugAnnotation that records a range of source lines in a class.

Author: David Hovemeyer

See Also: BugAnnotation

Field Summary
static StringDEFAULT_ROLE
static StringDEFAULT_ROLE_UNKNOWN_LINE
static StringROLE_ANOTHER_INSTANCE
static StringUNKNOWN_SOURCE_FILE
String returned if the source file is unknown.
Constructor Summary
SourceLineAnnotation(String className, String sourceFile, int startLine, int endLine, int startBytecode, int endBytecode)
Constructor.
Method Summary
voidaccept(BugAnnotationVisitor visitor)
intcompareTo(BugAnnotation o)
static SourceLineAnnotationcreateReallyUnknown(String className)
Factory method to create an unknown source line annotation.
static SourceLineAnnotationcreateUnknown(String className, String sourceFile)
Factory method to create an unknown source line annotation.
static SourceLineAnnotationcreateUnknown(String className)
Factory method to create an unknown source line annotation.
static SourceLineAnnotationcreateUnknown(String className, String sourceFile, int startBytecode, int endBytecode)
Factory method to create an unknown source line annotation.
static SourceLineAnnotationforEntireMethod(String className, String sourceFile, LineNumberTable lineNumberTable, int codeSize)
Create a SourceLineAnnotation covering an entire method.
static SourceLineAnnotationforEntireMethod(JavaClass javaClass, Method method)
Create a SourceLineAnnotation covering an entire method.
static SourceLineAnnotationforEntireMethod(JavaClass javaClass, XMethod xmethod)
Create a SourceLineAnnotation covering an entire method.
Stringformat(String key, ClassAnnotation primaryClass)
static SourceLineAnnotationfromRawData(String className, String sourceFile, int startLine, int endLine, int startPC, int endPC)
static SourceLineAnnotationfromVisitedInstruction(BytecodeScanningDetector visitor, int pc)
Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.
static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, PreorderVisitor visitor, int pc)
Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.
static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, Method method, Location loc)
Create from Method and Location in a visited class.
static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, Method method, InstructionHandle handle)
Create from Method and InstructionHandle in a visited class.
static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, Method method, int pc)
Create from Method and bytecode offset in a visited class.
static SourceLineAnnotationfromVisitedInstruction(BytecodeScanningDetector visitor)
Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.
static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle handle)
Factory method for creating a source line annotation describing the source line number for a visited instruction.
static SourceLineAnnotationfromVisitedInstructionRange(BytecodeScanningDetector visitor, int startPC, int endPC)
Factory method for creating a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor.
static SourceLineAnnotationfromVisitedInstructionRange(ClassContext classContext, PreorderVisitor visitor, int startPC, int endPC)
Factory method for creating a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor.
static SourceLineAnnotationfromVisitedInstructionRange(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end)
Factory method for creating a source line annotation describing the source line numbers for a range of instruction in a method.
static SourceLineAnnotationfromVisitedMethod(PreorderVisitor visitor)
Factory method for creating a source line annotation describing an entire method.
static SourceLineAnnotationfromVisitedMethod(MethodGen methodGen, String sourceFile)
Factory method for creating a source line annotation describing an entire method.
StringgetClassName()
Get the class name.
StringgetDescription()
intgetEndBytecode()
Get end bytecode (inclusive).
intgetEndLine()
Get the ending line (inclusive).
StringgetPackageName()
Get the package name.
StringgetSimpleClassName()
Get the simple class name (the part of the name after the dot)
StringgetSourceFile()
Get the source file name.
intgetStartBytecode()
Get start bytecode (inclusive).
intgetStartLine()
Get the start line (inclusive).
booleanisSignificant()
booleanisSourceFileKnown()
Is the source file known?
booleanisSynthetic()
booleanisUnknown()
Is this an unknown source line annotation?
voidsetDescription(String description)
voidsetSourceFile(String sourceFile)
Set the source file name.
voidsetSynthetic(boolean synthetic)
voidwriteXML(XMLOutput xmlOutput)
voidwriteXML(XMLOutput xmlOutput, boolean addMessages)

Field Detail

DEFAULT_ROLE

public static final String DEFAULT_ROLE

DEFAULT_ROLE_UNKNOWN_LINE

public static final String DEFAULT_ROLE_UNKNOWN_LINE

ROLE_ANOTHER_INSTANCE

public static final String ROLE_ANOTHER_INSTANCE

UNKNOWN_SOURCE_FILE

public static final String UNKNOWN_SOURCE_FILE
String returned if the source file is unknown. This must match what BCEL uses when the source file is unknown.

Constructor Detail

SourceLineAnnotation

public SourceLineAnnotation(String className, String sourceFile, int startLine, int endLine, int startBytecode, int endBytecode)
Constructor.

Parameters: className the class to which the line number(s) refer sourceFile the name of the source file startLine the first line (inclusive) endLine the ending line (inclusive) startBytecode the first bytecode offset (inclusive) endBytecode the end bytecode offset (inclusive)

Method Detail

accept

public void accept(BugAnnotationVisitor visitor)

compareTo

public int compareTo(BugAnnotation o)

createReallyUnknown

public static SourceLineAnnotation createReallyUnknown(String className)
Factory method to create an unknown source line annotation. This doesn't use the analysis context.

Parameters: className the class name

Returns: the SourceLineAnnotation

createUnknown

public static SourceLineAnnotation createUnknown(String className, String sourceFile)
Factory method to create an unknown source line annotation.

Parameters: className the class name sourceFile the source file name

Returns: the SourceLineAnnotation

createUnknown

public static SourceLineAnnotation createUnknown(String className)
Factory method to create an unknown source line annotation. This variant looks up the source filename automatically based on the class using best effort.

Parameters: className the class name

Returns: the SourceLineAnnotation

createUnknown

public static SourceLineAnnotation createUnknown(String className, String sourceFile, int startBytecode, int endBytecode)
Factory method to create an unknown source line annotation. This variant is used when bytecode offsets are known, but not source lines.

Parameters: className the class name sourceFile the source file name

Returns: the SourceLineAnnotation

forEntireMethod

public static SourceLineAnnotation forEntireMethod(String className, String sourceFile, LineNumberTable lineNumberTable, int codeSize)
Create a SourceLineAnnotation covering an entire method.

Parameters: className name of the class the method is in sourceFile source file containing the method lineNumberTable the method's LineNumberTable codeSize size in bytes of the method's code

Returns: a SourceLineAnnotation covering the entire method

forEntireMethod

public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, Method method)
Create a SourceLineAnnotation covering an entire method.

Parameters: javaClass JavaClass containing the method method the method

Returns: a SourceLineAnnotation for the entire method

forEntireMethod

public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, XMethod xmethod)
Create a SourceLineAnnotation covering an entire method.

Parameters: javaClass JavaClass containing the method xmethod the method

Returns: a SourceLineAnnotation for the entire method

format

public String format(String key, ClassAnnotation primaryClass)

fromRawData

public static SourceLineAnnotation fromRawData(String className, String sourceFile, int startLine, int endLine, int startPC, int endPC)

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(BytecodeScanningDetector visitor, int pc)
Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.

Parameters: visitor a BetterVisitor which is visiting the method pc the bytecode offset of the instruction in the method

Returns: the SourceLineAnnotation, or null if we do not have line number information for the instruction

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, PreorderVisitor visitor, int pc)
Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.

Parameters: classContext the ClassContext visitor a BetterVisitor which is visiting the method pc the bytecode offset of the instruction in the method

Returns: the SourceLineAnnotation, or null if we do not have line number information for the instruction

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, Location loc)
Create from Method and Location in a visited class.

Parameters: classContext ClassContext of visited class method Method in visited class loc Location in visited class

Returns: SourceLineAnnotation describing visited Location

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, InstructionHandle handle)
Create from Method and InstructionHandle in a visited class.

Parameters: classContext ClassContext of visited class method Method in visited class handle InstructionHandle in visited class

Returns: SourceLineAnnotation describing visited instruction

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, int pc)
Create from Method and bytecode offset in a visited class.

Parameters: classContext ClassContext of visited class method Method in visited class pc bytecode offset in visited method

Returns: SourceLineAnnotation describing visited instruction

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(BytecodeScanningDetector visitor)
Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.

Parameters: visitor a DismantleBytecode visitor which is visiting the method

Returns: the SourceLineAnnotation, or null if we do not have line number information for the instruction

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle handle)
Factory method for creating a source line annotation describing the source line number for a visited instruction.

Parameters: classContext the ClassContext methodGen the MethodGen object representing the method handle the InstructionHandle containing the visited instruction

Returns: the SourceLineAnnotation, or null if we do not have line number information for the instruction

fromVisitedInstructionRange

public static SourceLineAnnotation fromVisitedInstructionRange(BytecodeScanningDetector visitor, int startPC, int endPC)
Factory method for creating a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor.

Parameters: visitor a BetterVisitor which is visiting the method startPC the bytecode offset of the start instruction in the range endPC the bytecode offset of the end instruction in the range

Returns: the SourceLineAnnotation, or null if we do not have line number information for the instruction

fromVisitedInstructionRange

public static SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, PreorderVisitor visitor, int startPC, int endPC)
Factory method for creating a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor.

Parameters: classContext the ClassContext visitor a BetterVisitor which is visiting the method startPC the bytecode offset of the start instruction in the range endPC the bytecode offset of the end instruction in the range

Returns: the SourceLineAnnotation, or null if we do not have line number information for the instruction

fromVisitedInstructionRange

public static SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end)
Factory method for creating a source line annotation describing the source line numbers for a range of instruction in a method.

Parameters: classContext theClassContext methodGen the method start the start instruction end the end instruction (inclusive)

fromVisitedMethod

public static SourceLineAnnotation fromVisitedMethod(PreorderVisitor visitor)
Factory method for creating a source line annotation describing an entire method.

Parameters: visitor a BetterVisitor which is visiting the method

Returns: the SourceLineAnnotation

fromVisitedMethod

public static SourceLineAnnotation fromVisitedMethod(MethodGen methodGen, String sourceFile)
Factory method for creating a source line annotation describing an entire method.

Parameters: methodGen the method being visited

Returns: the SourceLineAnnotation, or null if we do not have line number information for the method

getClassName

public String getClassName()
Get the class name.

getDescription

public String getDescription()

getEndBytecode

public int getEndBytecode()
Get end bytecode (inclusive).

getEndLine

public int getEndLine()
Get the ending line (inclusive).

getPackageName

public String getPackageName()
Get the package name.

getSimpleClassName

public String getSimpleClassName()
Get the simple class name (the part of the name after the dot)

getSourceFile

public String getSourceFile()
Get the source file name.

getStartBytecode

public int getStartBytecode()
Get start bytecode (inclusive).

getStartLine

public int getStartLine()
Get the start line (inclusive).

isSignificant

public boolean isSignificant()

isSourceFileKnown

public boolean isSourceFileKnown()
Is the source file known?

isSynthetic

public boolean isSynthetic()

Returns: Returns the synthetic.

isUnknown

public boolean isUnknown()
Is this an unknown source line annotation?

setDescription

public void setDescription(String description)

setSourceFile

public void setSourceFile(String sourceFile)
Set the source file name.

Parameters: sourceFile the source file name

setSynthetic

public void setSynthetic(boolean synthetic)

Parameters: synthetic The synthetic to set.

writeXML

public void writeXML(XMLOutput xmlOutput)

writeXML

public void writeXML(XMLOutput xmlOutput, boolean addMessages)
FindBugs™ is licenced under the LGPL. Copyright © 2006 University of Maryland.