edu.umd.cs.findbugs
Class SourceLineAnnotation

java.lang.Object
  extended by edu.umd.cs.findbugs.SourceLineAnnotation
All Implemented Interfaces:
BugAnnotation, XMLWriteable, 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

Field Summary
private  java.lang.String className
           
private static java.lang.String DEFAULT_ROLE
           
private  java.lang.String description
           
private static java.lang.String ELEMENT_NAME
           
private  int endBytecode
           
private  int endLine
           
private  java.lang.String sourceFile
           
private  int startBytecode
           
private  int startLine
           
static java.lang.String UNKNOWN_SOURCE_FILE
          String returned if the source file is unknown.
 
Constructor Summary
SourceLineAnnotation(java.lang.String className, java.lang.String sourceFile, int startLine, int endLine, int startBytecode, int endBytecode)
          Constructor.
 
Method Summary
 void accept(BugAnnotationVisitor visitor)
          Accept a BugAnnotationVisitor.
private  void appendLines(java.lang.StringBuffer buf)
           
 int compareTo(BugAnnotation o)
           
static SourceLineAnnotation createUnknown(java.lang.String className, java.lang.String sourceFile)
          Factory method to create an unknown source line annotation.
static SourceLineAnnotation createUnknown(java.lang.String className, java.lang.String sourceFile, int startBytecode, int endBytecode)
           
 boolean equals(java.lang.Object o)
           
private static SourceLineAnnotation forEntireMethod(java.lang.String className, java.lang.String sourceFile, org.apache.bcel.classfile.LineNumberTable lineNumberTable, int codeSize)
           
 java.lang.String format(java.lang.String key)
          Format the annotation as a String.
static SourceLineAnnotation fromVisitedInstruction(DismantleBytecode visitor)
          Factory method for creating a source line annotation describing the source line number for the instruction being visited by given visitor.
static SourceLineAnnotation fromVisitedInstruction(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 SourceLineAnnotation fromVisitedInstruction(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 fromVisitedInstructionRange(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 SourceLineAnnotation fromVisitedInstructionRange(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 fromVisitedMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)
          Factory method for creating a source line annotation describing an entire method.
static SourceLineAnnotation fromVisitedMethod(PreorderVisitor visitor)
          Factory method for creating a source line annotation describing an entire method.
 java.lang.String getClassName()
          Get the class name.
 java.lang.String getDescription()
          Get a description of this bug annotation.
 int getEndBytecode()
          Get end bytecode (inclusive).
 int getEndLine()
          Get the ending line (inclusive).
private static org.apache.bcel.classfile.LineNumberTable getLineNumberTable(PreorderVisitor visitor)
           
 java.lang.String getPackageName()
          Get the package name.
 java.lang.String getSourceFile()
          Get the source file name.
 int getStartBytecode()
          Get start bytecode (inclusive).
 int getStartLine()
          Get the start line (inclusive).
 int hashCode()
           
 boolean isSourceFileKnown()
          Is the source file known?
 boolean isUnknown()
          Is this an unknown source line annotation?
 void setDescription(java.lang.String description)
          Set a description of this bug annotation.
 void setSourceFile(java.lang.String sourceFile)
          Set the source file name.
 java.lang.String toString()
           
 void writeXML(XMLOutput xmlOutput)
          Write this object to given XMLOutput.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ROLE

private static final java.lang.String DEFAULT_ROLE
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

description

private java.lang.String description

className

private java.lang.String className

sourceFile

private java.lang.String sourceFile

startLine

private int startLine

endLine

private int endLine

startBytecode

private int startBytecode

endBytecode

private int endBytecode

ELEMENT_NAME

private static final java.lang.String ELEMENT_NAME
See Also:
Constant Field Values
Constructor Detail

SourceLineAnnotation

public SourceLineAnnotation(java.lang.String className,
                            java.lang.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

createUnknown

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

Parameters:
className - the class name
Returns:
the SourceLineAnnotation

createUnknown

public static SourceLineAnnotation createUnknown(java.lang.String className,
                                                 java.lang.String sourceFile,
                                                 int startBytecode,
                                                 int endBytecode)

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

private static SourceLineAnnotation forEntireMethod(java.lang.String className,
                                                    java.lang.String sourceFile,
                                                    org.apache.bcel.classfile.LineNumberTable lineNumberTable,
                                                    int codeSize)

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(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:
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

fromVisitedInstructionRange

public static SourceLineAnnotation fromVisitedInstructionRange(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:
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

fromVisitedInstruction

public static SourceLineAnnotation fromVisitedInstruction(DismantleBytecode 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(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.

Parameters:
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(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:
methodGen - the method
start - the start instruction
end - the end instruction (inclusive)

getLineNumberTable

private static org.apache.bcel.classfile.LineNumberTable getLineNumberTable(PreorderVisitor visitor)

getClassName

public java.lang.String getClassName()
Get the class name.


getSourceFile

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

getPackageName

public java.lang.String getPackageName()
Get the package name.


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: BugAnnotation
Accept a BugAnnotationVisitor.

Specified by:
accept in interface BugAnnotation
Parameters:
visitor - the visitor to accept

format

public java.lang.String format(java.lang.String key)
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 interface BugAnnotation
Parameters:
key - how the annotation should be formatted

appendLines

private void appendLines(java.lang.StringBuffer buf)

getDescription

public java.lang.String 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 interface BugAnnotation

setDescription

public void setDescription(java.lang.String description)
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 interface BugAnnotation

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(BugAnnotation o)
Specified by:
compareTo in interface java.lang.Comparable<BugAnnotation>

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

writeXML

public void writeXML(XMLOutput xmlOutput)
              throws java.io.IOException
Description copied from interface: XMLWriteable
Write this object to given XMLOutput.

Specified by:
writeXML in interface XMLWriteable
Parameters:
xmlOutput - the XMLOutput for the document
Throws:
java.io.IOException