Package edu.umd.cs.findbugs
Class SourceLineAnnotation
java.lang.Object
edu.umd.cs.findbugs.SourceLineAnnotation
- All Implemented Interfaces:
BugAnnotation
,XMLWriteable
,XMLWriteableWithMessages
,Serializable
,Cloneable
,Comparable<BugAnnotation>
A BugAnnotation that records a range of source lines in a class.
- Author:
- David Hovemeyer
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
String returned if the source file is unknown.Fields inherited from interface edu.umd.cs.findbugs.BugAnnotation
MESSAGE_TAG
-
Constructor Summary
ConstructorDescriptionSourceLineAnnotation
(String className, String sourceFile, int startLine, int endLine, int startBytecode, int endBytecode) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(BugAnnotationVisitor visitor) Accept a BugAnnotationVisitor.static void
clone()
int
static SourceLineAnnotation
createReallyUnknown
(String className) Factory method to create an unknown source line annotation.static SourceLineAnnotation
createUnknown
(String className) Factory method to create an unknown source line annotation.static SourceLineAnnotation
createUnknown
(String className, String sourceFile) Factory method to create an unknown source line annotation.static SourceLineAnnotation
createUnknown
(String className, String sourceFile, int startBytecode, int endBytecode) Factory method to create an unknown source line annotation.boolean
static SourceLineAnnotation
forEntireMethod
(String className, String sourceFile, org.apache.bcel.classfile.LineNumberTable lineNumberTable, int codeSize) Create a SourceLineAnnotation covering an entire method.static SourceLineAnnotation
forEntireMethod
(org.apache.bcel.classfile.JavaClass javaClass, XMethod xmethod) Create a SourceLineAnnotation covering an entire method.static SourceLineAnnotation
forEntireMethod
(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method) Create a SourceLineAnnotation covering an entire method.static SourceLineAnnotation
forFirstLineOfMethod
(MethodDescriptor methodDescriptor) Make a best-effort attempt to create a SourceLineAnnotation for the first line of a method.format
(String key, ClassAnnotation primaryClass) Format the annotation as a String.static SourceLineAnnotation
fromRawData
(String className, String sourceFile, int startLine, int endLine, int startPC, int endPC) 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.static SourceLineAnnotation
fromVisitedInstruction
(ClassContext classContext, org.apache.bcel.classfile.Method method, int pc) Create from Method and bytecode offset in a visited class.static SourceLineAnnotation
fromVisitedInstruction
(ClassContext classContext, org.apache.bcel.classfile.Method method, Location loc) Create from Method and Location in a visited class.static SourceLineAnnotation
fromVisitedInstruction
(ClassContext classContext, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle) Create from Method and InstructionHandle in a visited class.static SourceLineAnnotation
fromVisitedInstruction
(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, String sourceFile, org.apache.bcel.generic.InstructionHandle handle) Factory method for creating a source line annotation describing the source line number for a visited instruction.static SourceLineAnnotation
Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.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.static SourceLineAnnotation
fromVisitedInstruction
(MethodDescriptor methodDescriptor, int position) static SourceLineAnnotation
fromVisitedInstruction
(MethodDescriptor methodDescriptor, Location location) Create from MethodDescriptor and Location of visited instruction.static SourceLineAnnotation
fromVisitedInstruction
(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, int pc) Create from Method and bytecode offset in a visited class.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.static SourceLineAnnotation
fromVisitedInstructionRange
(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, String sourceFile, org.apache.bcel.generic.InstructionHandle start, org.apache.bcel.generic.InstructionHandle end) Factory method for creating a source line annotation describing the source line numbers for a range of instruction in a method.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.static SourceLineAnnotation
fromVisitedMethod
(PreorderVisitor visitor) Factory method for creating a source line annotation describing an entire method.static SourceLineAnnotation
fromVisitedMethod
(org.apache.bcel.generic.MethodGen methodGen, String sourceFile) Factory method for creating a source line annotation describing an entire method.static void
generateRelativeSource
(File relativeSourceBase, Project project) Get a description of this bug annotation.int
Get end bytecode (inclusive).int
Get the ending line (inclusive).Returns the complete path of the source file the analyzed class has been generated from, if this information is available to the current AnalysisContext, otherwise falls back to getSourcePath().Get the simple class name (the part of the name after the dot)Get the source file name.int
Get start bytecode (inclusive).int
Get the start line (inclusive).int
hashCode()
boolean
Is this annotation used to compute instance hashes or match bug instances across versionsboolean
Is the source file known?boolean
boolean
Is this an unknown source line annotation?void
setDescription
(String description) Set a description of this bug annotation.void
setSourceFile
(String sourceFile) Set the source file name.void
setSynthetic
(boolean synthetic) toString()
toString
(ClassAnnotation primaryClass) void
Write this object to given XMLOutput.void
-
Field Details
-
DEFAULT_ROLE
- See Also:
-
DEFAULT_ROLE_UNKNOWN_LINE
- See Also:
-
ROLE_ANOTHER_INSTANCE
- See Also:
-
ROLE_CALLED_FROM_SUPERCLASS_AT
- See Also:
-
ROLE_FIELD_SET_TOO_LATE_AT
- See Also:
-
ROLE_GENERATED_AT
- See Also:
-
ROLE_OBLIGATION_CREATED
- See Also:
-
ROLE_OBLIGATION_CREATED_BY_WILLCLOSE_PARAMETER
- See Also:
-
ROLE_PATH_CONTINUES
- See Also:
-
ROLE_LOCK_OBTAINED_AT
- See Also:
-
ROLE_UNREACHABLE_CODE
- See Also:
-
UNKNOWN_SOURCE_FILE
String returned if the source file is unknown. This must match what BCEL uses when the source file is unknown.- See Also:
-
CANONICAL_PACKAGE_SEPARATOR
public static final char CANONICAL_PACKAGE_SEPARATOR- See Also:
-
DESCRIPTION_LAST_CHANGE
- See Also:
-
DESCRIPTION_LOOP_BOTTOM
- See Also:
-
-
Constructor Details
-
SourceLineAnnotation
public SourceLineAnnotation(@Nonnull @DottedClassName String className, @Nonnull String sourceFile, int startLine, int endLine, int startBytecode, int endBytecode) Constructor.- Parameters:
className
- the class to which the line number(s) refersourceFile
- the name of the source filestartLine
- the first line (inclusive)endLine
- the ending line (inclusive)startBytecode
- the first bytecode offset (inclusive)endBytecode
- the end bytecode offset (inclusive)
-
-
Method Details
-
clone
- Specified by:
clone
in interfaceBugAnnotation
- Overrides:
clone
in classObject
-
createUnknown
public static SourceLineAnnotation createUnknown(@DottedClassName String className, String sourceFile) Factory method to create an unknown source line annotation.- Parameters:
className
- the class namesourceFile
- the source file name- Returns:
- the SourceLineAnnotation
-
createUnknown
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
-
createReallyUnknown
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
@Nonnull public static SourceLineAnnotation createUnknown(@DottedClassName 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 namesourceFile
- the source file name- Returns:
- the SourceLineAnnotation
-
fromVisitedMethod
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(org.apache.bcel.generic.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
-
forEntireMethod
public static SourceLineAnnotation forEntireMethod(@DottedClassName String className, String sourceFile, org.apache.bcel.classfile.LineNumberTable lineNumberTable, int codeSize) Create a SourceLineAnnotation covering an entire method.- Parameters:
className
- name of the class the method is insourceFile
- source file containing the methodlineNumberTable
- the method's LineNumberTablecodeSize
- size in bytes of the method's code- Returns:
- a SourceLineAnnotation covering the entire method
-
forEntireMethod
public static SourceLineAnnotation forEntireMethod(org.apache.bcel.classfile.JavaClass javaClass, @CheckForNull org.apache.bcel.classfile.Method method) Create a SourceLineAnnotation covering an entire method.- Parameters:
javaClass
- JavaClass containing the methodmethod
- the method- Returns:
- a SourceLineAnnotation for the entire method
-
forEntireMethod
public static SourceLineAnnotation forEntireMethod(org.apache.bcel.classfile.JavaClass javaClass, XMethod xmethod) Create a SourceLineAnnotation covering an entire method.- Parameters:
javaClass
- JavaClass containing the methodxmethod
- the method- Returns:
- a SourceLineAnnotation for the entire method
-
forFirstLineOfMethod
Make a best-effort attempt to create a SourceLineAnnotation for the first line of a method.- Parameters:
methodDescriptor
- a method- Returns:
- SourceLineAnnotation describing the first line of the method (insofar as we can actually figure that out from the bytecode)
-
fromVisitedInstruction
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 methodpc
- 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 ClassContextvisitor
- a BetterVisitor which is visiting the methodpc
- 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, org.apache.bcel.classfile.Method method, Location loc) Create from Method and Location in a visited class.- Parameters:
classContext
- ClassContext of visited classmethod
- Method in visited classloc
- Location in visited class- Returns:
- SourceLineAnnotation describing visited Location
-
fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle) Create from Method and InstructionHandle in a visited class.- Parameters:
classContext
- ClassContext of visited classmethod
- Method in visited classhandle
- InstructionHandle in visited class- Returns:
- SourceLineAnnotation describing visited instruction
-
fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(MethodDescriptor methodDescriptor, Location location) Create from MethodDescriptor and Location of visited instruction.- Parameters:
methodDescriptor
- MethodDescriptor identifying analyzed methodlocation
- Location of instruction within analyed method- Returns:
- SourceLineAnnotation describing visited instruction
-
fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(MethodDescriptor methodDescriptor, int position) -
fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, org.apache.bcel.classfile.Method method, int pc) Create from Method and bytecode offset in a visited class.- Parameters:
classContext
- ClassContext of visited classmethod
- Method in visited classpc
- bytecode offset in visited method- Returns:
- SourceLineAnnotation describing visited instruction
-
fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, int pc) Create from Method and bytecode offset in a visited class.- Parameters:
jclass
- JavaClass of visited classmethod
- Method in visited classpc
- bytecode offset in visited method- Returns:
- SourceLineAnnotation describing visited 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 methodstartPC
- the bytecode offset of the start instruction in the rangeendPC
- 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
@Nonnull 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 ClassContextvisitor
- a BetterVisitor which is visiting the methodstartPC
- the bytecode offset of the start instruction in the rangeendPC
- 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
-
fromRawData
public static SourceLineAnnotation fromRawData(String className, String sourceFile, int startLine, int endLine, int startPC, int endPC) -
fromVisitedInstruction
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
@Nonnull public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, String sourceFile, @Nonnull org.apache.bcel.generic.InstructionHandle handle) Factory method for creating a source line annotation describing the source line number for a visited instruction.- Parameters:
classContext
- the ClassContextmethodGen
- the MethodGen object representing the methodhandle
- 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(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, String sourceFile, org.apache.bcel.generic.InstructionHandle start, org.apache.bcel.generic.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
- theClassContextmethodGen
- the methodstart
- the start instructionend
- the end instruction (inclusive)
-
getClassName
-
getSourceFile
Get the source file name. -
isSourceFileKnown
public boolean isSourceFileKnown()Is the source file known? -
setSourceFile
Set the source file name.- Parameters:
sourceFile
- the source file name
-
getSimpleClassName
Get the simple class name (the part of the name after the dot) -
getPackageName
-
getStartLine
public int getStartLine()Get the start line (inclusive). -
getEndLine
public int getEndLine()Get the ending line (inclusive). -
getStartBytecode
public int getStartBytecode()Get start bytecode (inclusive). -
getEndBytecode
public int getEndBytecode()Get end bytecode (inclusive). -
isUnknown
public boolean isUnknown()Is this an unknown source line annotation? -
accept
Description copied from interface:BugAnnotation
Accept a BugAnnotationVisitor.- Specified by:
accept
in interfaceBugAnnotation
- Parameters:
visitor
- the visitor to accept
-
format
Description copied from interface:BugAnnotation
Format the annotation as a String. The given key specifies additional information about how the annotation should be formatted. If the key is empty, then the "default" format will be used.- Specified by:
format
in interfaceBugAnnotation
- Parameters:
key
- how the annotation should be formattedprimaryClass
- The primary class for the bug; some bug annotation format msgs are simplified in relation to that class.
-
getDescription
Description copied from interface:BugAnnotation
Get a description of this bug annotation. The description is a key for the FindBugsAnnotationDescriptions resource bundle.- Specified by:
getDescription
in interfaceBugAnnotation
-
setDescription
Description copied from interface:BugAnnotation
Set a description of this bug annotation. The description is a key for the FindBugsAnnotationDescriptions resource bundle.- Specified by:
setDescription
in interfaceBugAnnotation
-
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<BugAnnotation>
-
hashCode
public int hashCode() -
equals
-
writeXML
Description copied from interface:XMLWriteable
Write this object to given XMLOutput.- Specified by:
writeXML
in interfaceXMLWriteable
- Parameters:
xmlOutput
- the XMLOutput for the document- Throws:
IOException
-
generateRelativeSource
-
clearGenerateRelativeSource
public static void clearGenerateRelativeSource() -
writeXML
public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException - Specified by:
writeXML
in interfaceXMLWriteableWithMessages
- Throws:
IOException
-
getSourcePath
-
getRealSourcePath
Returns the complete path of the source file the analyzed class has been generated from, if this information is available to the current AnalysisContext, otherwise falls back to getSourcePath().- Returns:
- the complete path of the source file the analyzed class has been generated from, otherwise falls back to getSourcePath().
-
setSynthetic
public void setSynthetic(boolean synthetic) -
isSynthetic
public boolean isSynthetic() -
isSignificant
public boolean isSignificant()Description copied from interface:BugAnnotation
Is this annotation used to compute instance hashes or match bug instances across versions- Specified by:
isSignificant
in interfaceBugAnnotation
- Returns:
- true if significant
-
toString
- Specified by:
toString
in interfaceBugAnnotation
-