Package edu.umd.cs.findbugs
Class SourceLineAnnotation
- java.lang.Object
-
- edu.umd.cs.findbugs.SourceLineAnnotation
-
- All Implemented Interfaces:
BugAnnotation,XMLWriteable,XMLWriteableWithMessages,java.io.Serializable,java.lang.Cloneable,java.lang.Comparable<BugAnnotation>
public class SourceLineAnnotation extends java.lang.Object implements BugAnnotation
A BugAnnotation that records a range of source lines in a class.- Author:
- David Hovemeyer
- See Also:
BugAnnotation, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static charCANONICAL_PACKAGE_SEPARATORstatic java.lang.StringDEFAULT_ROLEstatic java.lang.StringDEFAULT_ROLE_UNKNOWN_LINEstatic java.lang.StringDESCRIPTION_LAST_CHANGEstatic java.lang.StringDESCRIPTION_LOOP_BOTTOMstatic java.lang.StringROLE_ANOTHER_INSTANCEstatic java.lang.StringROLE_CALLED_FROM_SUPERCLASS_ATstatic java.lang.StringROLE_FIELD_SET_TOO_LATE_ATstatic java.lang.StringROLE_GENERATED_ATstatic java.lang.StringROLE_LOCK_OBTAINED_ATstatic java.lang.StringROLE_OBLIGATION_CREATEDstatic java.lang.StringROLE_OBLIGATION_CREATED_BY_WILLCLOSE_PARAMETERstatic java.lang.StringROLE_PATH_CONTINUESstatic java.lang.StringROLE_UNREACHABLE_CODEstatic java.lang.StringUNKNOWN_SOURCE_FILEString returned if the source file is unknown.-
Fields inherited from interface edu.umd.cs.findbugs.BugAnnotation
MESSAGE_TAG
-
-
Constructor Summary
Constructors Constructor Description SourceLineAnnotation(java.lang.String className, java.lang.String sourceFile, int startLine, int endLine, int startBytecode, int endBytecode)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(BugAnnotationVisitor visitor)Accept a BugAnnotationVisitor.static voidclearGenerateRelativeSource()java.lang.Objectclone()intcompareTo(BugAnnotation o)static SourceLineAnnotationcreateReallyUnknown(java.lang.String className)Factory method to create an unknown source line annotation.static SourceLineAnnotationcreateUnknown(java.lang.String className)Factory method to create an unknown source line annotation.static SourceLineAnnotationcreateUnknown(java.lang.String className, java.lang.String sourceFile)Factory method to create an unknown source line annotation.static SourceLineAnnotationcreateUnknown(java.lang.String className, java.lang.String sourceFile, int startBytecode, int endBytecode)Factory method to create an unknown source line annotation.booleanequals(java.lang.Object o)static SourceLineAnnotationforEntireMethod(java.lang.String className, java.lang.String sourceFile, org.apache.bcel.classfile.LineNumberTable lineNumberTable, int codeSize)Create a SourceLineAnnotation covering an entire method.static SourceLineAnnotationforEntireMethod(org.apache.bcel.classfile.JavaClass javaClass, XMethod xmethod)Create a SourceLineAnnotation covering an entire method.static SourceLineAnnotationforEntireMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)Create a SourceLineAnnotation covering an entire method.static SourceLineAnnotationforFirstLineOfMethod(MethodDescriptor methodDescriptor)Make a best-effort attempt to create a SourceLineAnnotation for the first line of a method.java.lang.Stringformat(java.lang.String key, ClassAnnotation primaryClass)Format the annotation as a String.static SourceLineAnnotationfromRawData(java.lang.String className, java.lang.String sourceFile, int startLine, int endLine, int startPC, int endPC)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, org.apache.bcel.classfile.Method method, int pc)Create from Method and bytecode offset in a visited class.static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, org.apache.bcel.classfile.Method method, Location loc)Create from Method and Location in a visited class.static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle)Create from Method and InstructionHandle in a visited class.static SourceLineAnnotationfromVisitedInstruction(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, java.lang.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 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(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(MethodDescriptor methodDescriptor, int position)static SourceLineAnnotationfromVisitedInstruction(MethodDescriptor methodDescriptor, Location location)Create from MethodDescriptor and Location of visited instruction.static SourceLineAnnotationfromVisitedInstruction(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 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, org.apache.bcel.generic.MethodGen methodGen, java.lang.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 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 SourceLineAnnotationfromVisitedMethod(PreorderVisitor visitor)Factory method for creating a source line annotation describing an entire method.static SourceLineAnnotationfromVisitedMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)Factory method for creating a source line annotation describing an entire method.static voidgenerateRelativeSource(java.io.File relativeSourceBase, Project project)java.lang.StringgetClassName()java.lang.StringgetDescription()Get a description of this bug annotation.intgetEndBytecode()Get end bytecode (inclusive).intgetEndLine()Get the ending line (inclusive).java.lang.StringgetPackageName()java.lang.StringgetSimpleClassName()Get the simple class name (the part of the name after the dot)java.lang.StringgetSourceFile()Get the source file name.java.lang.StringgetSourcePath()intgetStartBytecode()Get start bytecode (inclusive).intgetStartLine()Get the start line (inclusive).inthashCode()booleanisSignificant()Is this annotation used to compute instance hashes or match bug instances across versionsbooleanisSourceFileKnown()Is the source file known?booleanisSynthetic()booleanisUnknown()Is this an unknown source line annotation?voidsetDescription(java.lang.String description)Set a description of this bug annotation.voidsetSourceFile(java.lang.String sourceFile)Set the source file name.voidsetSynthetic(boolean synthetic)java.lang.StringtoString()java.lang.StringtoString(ClassAnnotation primaryClass)voidwriteXML(XMLOutput xmlOutput)Write this object to given XMLOutput.voidwriteXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary)
-
-
-
Field Detail
-
DEFAULT_ROLE
public static final java.lang.String DEFAULT_ROLE
- See Also:
- Constant Field Values
-
DEFAULT_ROLE_UNKNOWN_LINE
public static final java.lang.String DEFAULT_ROLE_UNKNOWN_LINE
- See Also:
- Constant Field Values
-
ROLE_ANOTHER_INSTANCE
public static final java.lang.String ROLE_ANOTHER_INSTANCE
- See Also:
- Constant Field Values
-
ROLE_CALLED_FROM_SUPERCLASS_AT
public static final java.lang.String ROLE_CALLED_FROM_SUPERCLASS_AT
- See Also:
- Constant Field Values
-
ROLE_FIELD_SET_TOO_LATE_AT
public static final java.lang.String ROLE_FIELD_SET_TOO_LATE_AT
- See Also:
- Constant Field Values
-
ROLE_GENERATED_AT
public static final java.lang.String ROLE_GENERATED_AT
- See Also:
- Constant Field Values
-
ROLE_OBLIGATION_CREATED
public static final java.lang.String ROLE_OBLIGATION_CREATED
- See Also:
- Constant Field Values
-
ROLE_OBLIGATION_CREATED_BY_WILLCLOSE_PARAMETER
public static final java.lang.String ROLE_OBLIGATION_CREATED_BY_WILLCLOSE_PARAMETER
- See Also:
- Constant Field Values
-
ROLE_PATH_CONTINUES
public static final java.lang.String ROLE_PATH_CONTINUES
- See Also:
- Constant Field Values
-
ROLE_LOCK_OBTAINED_AT
public static final java.lang.String ROLE_LOCK_OBTAINED_AT
- See Also:
- Constant Field Values
-
ROLE_UNREACHABLE_CODE
public static final java.lang.String ROLE_UNREACHABLE_CODE
- See Also:
- Constant Field Values
-
UNKNOWN_SOURCE_FILE
public static final java.lang.String 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:
- Constant Field Values
-
CANONICAL_PACKAGE_SEPARATOR
public static final char CANONICAL_PACKAGE_SEPARATOR
- See Also:
- Constant Field Values
-
DESCRIPTION_LAST_CHANGE
public static final java.lang.String DESCRIPTION_LAST_CHANGE
- See Also:
- Constant Field Values
-
DESCRIPTION_LOOP_BOTTOM
public static final java.lang.String DESCRIPTION_LOOP_BOTTOM
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SourceLineAnnotation
public SourceLineAnnotation(@Nonnull @DottedClassName java.lang.String className, @Nonnull java.lang.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 Detail
-
clone
public java.lang.Object clone()
- Specified by:
clonein interfaceBugAnnotation- Overrides:
clonein classjava.lang.Object
-
createUnknown
public static SourceLineAnnotation createUnknown(@DottedClassName java.lang.String className, java.lang.String sourceFile)
Factory method to create an unknown source line annotation.- Parameters:
className- the class namesourceFile- the source file name- Returns:
- the SourceLineAnnotation
-
createUnknown
public static SourceLineAnnotation createUnknown(@DottedClassName java.lang.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
-
createReallyUnknown
public static SourceLineAnnotation createReallyUnknown(@DottedClassName java.lang.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
@Nonnull public static SourceLineAnnotation createUnknown(@DottedClassName java.lang.String className, java.lang.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
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(org.apache.bcel.generic.MethodGen methodGen, java.lang.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 java.lang.String className, java.lang.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
public static SourceLineAnnotation forFirstLineOfMethod(MethodDescriptor methodDescriptor)
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
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 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(java.lang.String className, java.lang.String sourceFile, int startLine, int endLine, int startPC, int endPC)
-
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
@Nonnull public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, java.lang.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, java.lang.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
@Nonnull @DottedClassName public java.lang.String getClassName()
-
getSourceFile
@Nonnull public java.lang.String getSourceFile()
Get the source file name.
-
isSourceFileKnown
public boolean isSourceFileKnown()
Is the source file known?
-
setSourceFile
public void setSourceFile(java.lang.String sourceFile)
Set the source file name.- Parameters:
sourceFile- the source file name
-
getSimpleClassName
public java.lang.String getSimpleClassName()
Get the simple class name (the part of the name after the dot)
-
getPackageName
public java.lang.String 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
public void accept(BugAnnotationVisitor visitor)
Description copied from interface:BugAnnotationAccept a BugAnnotationVisitor.- Specified by:
acceptin interfaceBugAnnotation- Parameters:
visitor- the visitor to accept
-
format
public java.lang.String format(java.lang.String key, ClassAnnotation primaryClass)Description copied from interface:BugAnnotationFormat 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:
formatin 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
public java.lang.String getDescription()
Description copied from interface:BugAnnotationGet a description of this bug annotation. The description is a key for the FindBugsAnnotationDescriptions resource bundle.- Specified by:
getDescriptionin interfaceBugAnnotation
-
setDescription
public void setDescription(java.lang.String description)
Description copied from interface:BugAnnotationSet a description of this bug annotation. The description is a key for the FindBugsAnnotationDescriptions resource bundle.- Specified by:
setDescriptionin interfaceBugAnnotation
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(BugAnnotation o)
- Specified by:
compareToin interfacejava.lang.Comparable<BugAnnotation>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
writeXML
public void writeXML(XMLOutput xmlOutput) throws java.io.IOException
Description copied from interface:XMLWriteableWrite this object to given XMLOutput.- Specified by:
writeXMLin interfaceXMLWriteable- Parameters:
xmlOutput- the XMLOutput for the document- Throws:
java.io.IOException
-
generateRelativeSource
public static void generateRelativeSource(java.io.File relativeSourceBase, Project project)
-
clearGenerateRelativeSource
public static void clearGenerateRelativeSource()
-
writeXML
public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws java.io.IOException
- Specified by:
writeXMLin interfaceXMLWriteableWithMessages- Throws:
java.io.IOException
-
getSourcePath
public java.lang.String getSourcePath()
-
setSynthetic
public void setSynthetic(boolean synthetic)
-
isSynthetic
public boolean isSynthetic()
-
isSignificant
public boolean isSignificant()
Description copied from interface:BugAnnotationIs this annotation used to compute instance hashes or match bug instances across versions- Specified by:
isSignificantin interfaceBugAnnotation- Returns:
- true if significant
-
toString
public java.lang.String toString(ClassAnnotation primaryClass)
- Specified by:
toStringin interfaceBugAnnotation
-
-