Package edu.umd.cs.findbugs
Class FieldAnnotation
- java.lang.Object
-
- edu.umd.cs.findbugs.BugAnnotationWithSourceLines
-
- edu.umd.cs.findbugs.PackageMemberAnnotation
-
- edu.umd.cs.findbugs.FieldAnnotation
-
- All Implemented Interfaces:
BugAnnotation
,XMLWriteable
,XMLWriteableWithMessages
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<BugAnnotation>
public class FieldAnnotation extends PackageMemberAnnotation
A BugAnnotation specifying a particular field in particular class.- Author:
- David Hovemeyer
- See Also:
BugAnnotation
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ARGUMENT_ROLE
static java.lang.String
DEFAULT_ROLE
static java.lang.String
DID_YOU_MEAN_ROLE
static java.lang.String
INVOKED_ON_ROLE
static java.lang.String
LOADED_FROM_ROLE
static java.lang.String
STORED_ROLE
static java.lang.String
VALUE_OF_ROLE
-
Fields inherited from class edu.umd.cs.findbugs.PackageMemberAnnotation
className, description
-
Fields inherited from class edu.umd.cs.findbugs.BugAnnotationWithSourceLines
sourceFileName, sourceLines
-
Fields inherited from interface edu.umd.cs.findbugs.BugAnnotation
MESSAGE_TAG
-
-
Constructor Summary
Constructors Constructor Description FieldAnnotation(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, boolean isStatic)
Constructor.FieldAnnotation(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, int accessFlags)
Constructor.FieldAnnotation(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, java.lang.String fieldSourceSig, boolean isStatic)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(BugAnnotationVisitor visitor)
Accept a BugAnnotationVisitor.int
compareTo(BugAnnotation o)
boolean
equals(java.lang.Object o)
protected java.lang.String
formatPackageMember(java.lang.String key, ClassAnnotation primaryClass)
Do default and subclass-specific formatting.static FieldAnnotation
fromBCELField(java.lang.String className, org.apache.bcel.classfile.Field field)
Factory method.static FieldAnnotation
fromBCELField(org.apache.bcel.classfile.JavaClass jClass, org.apache.bcel.classfile.Field field)
Factory method.static FieldAnnotation
fromFieldDescriptor(FieldDescriptor fieldDescriptor)
Factory method.static FieldAnnotation
fromReferencedField(DismantleBytecode visitor)
Factory method.static FieldAnnotation
fromVisitedField(PreorderVisitor visitor)
Factory method.static FieldAnnotation
fromXField(XField fieldDescriptor)
java.lang.String
getFieldName()
Get the field name.java.lang.String
getFieldSignature()
Get the type signature of the field.SourceLineAnnotation
getSourceLines()
Get the SourceLineAnnotation describing the source lines where the method is defined.int
hashCode()
static FieldAnnotation
isRead(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
Is the given instruction a read of a field?boolean
isStatic()
Return whether or not the field is static.static FieldAnnotation
isWrite(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
Is the instruction a write of a field?FieldDescriptor
toFieldDescriptor()
XField
toXField()
void
writeXML(XMLOutput xmlOutput)
Write this object to given XMLOutput.void
writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary)
-
Methods inherited from class edu.umd.cs.findbugs.PackageMemberAnnotation
format, getClassDescriptor, getClassName, getDescription, getPackageName, getSimpleClassName, getSlashedClassName, isSignificant, removePackage, removePackageName, setDescription, shorten, toString, toString
-
Methods inherited from class edu.umd.cs.findbugs.BugAnnotationWithSourceLines
clone, getSourceFileName, setSourceLines
-
-
-
-
Field Detail
-
DEFAULT_ROLE
public static final java.lang.String DEFAULT_ROLE
- See Also:
- Constant Field Values
-
DID_YOU_MEAN_ROLE
public static final java.lang.String DID_YOU_MEAN_ROLE
- See Also:
- Constant Field Values
-
VALUE_OF_ROLE
public static final java.lang.String VALUE_OF_ROLE
- See Also:
- Constant Field Values
-
LOADED_FROM_ROLE
public static final java.lang.String LOADED_FROM_ROLE
- See Also:
- Constant Field Values
-
STORED_ROLE
public static final java.lang.String STORED_ROLE
- See Also:
- Constant Field Values
-
INVOKED_ON_ROLE
public static final java.lang.String INVOKED_ON_ROLE
- See Also:
- Constant Field Values
-
ARGUMENT_ROLE
public static final java.lang.String ARGUMENT_ROLE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FieldAnnotation
public FieldAnnotation(@DottedClassName java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, boolean isStatic)
Constructor.- Parameters:
className
- the name of the class containing the fieldfieldName
- the name of the fieldfieldSig
- the type signature of the field
-
FieldAnnotation
public FieldAnnotation(@DottedClassName java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, java.lang.String fieldSourceSig, boolean isStatic)
-
FieldAnnotation
public FieldAnnotation(@DottedClassName java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, int accessFlags)
Constructor.- Parameters:
className
- the name of the class containing the fieldfieldName
- the name of the fieldfieldSig
- the type signature of the fieldaccessFlags
- accessFlags for the field
-
-
Method Detail
-
fromVisitedField
public static FieldAnnotation fromVisitedField(PreorderVisitor visitor)
Factory method. Class name, field name, and field signatures are taken from the given visitor, which is visiting the field.- Parameters:
visitor
- the visitor which is visiting the field- Returns:
- the FieldAnnotation object
-
fromReferencedField
public static FieldAnnotation fromReferencedField(DismantleBytecode visitor)
Factory method. Class name, field name, and field signatures are taken from the given visitor, which is visiting a reference to the field (i.e., a getfield or getstatic instruction).- Parameters:
visitor
- the visitor which is visiting the field reference- Returns:
- the FieldAnnotation object
-
fromBCELField
public static FieldAnnotation fromBCELField(@DottedClassName java.lang.String className, org.apache.bcel.classfile.Field field)
Factory method. Construct from class name and BCEL Field object.- Parameters:
className
- the name of the class which defines the fieldfield
- the BCEL Field object- Returns:
- the FieldAnnotation
-
fromBCELField
public static FieldAnnotation fromBCELField(org.apache.bcel.classfile.JavaClass jClass, org.apache.bcel.classfile.Field field)
Factory method. Construct from class name and BCEL Field object.- Parameters:
jClass
- the class which defines the fieldfield
- the BCEL Field object- Returns:
- the FieldAnnotation
-
fromFieldDescriptor
public static FieldAnnotation fromFieldDescriptor(FieldDescriptor fieldDescriptor)
Factory method. Construct from a FieldDescriptor.- Parameters:
fieldDescriptor
- the FieldDescriptor- Returns:
- the FieldAnnotation
-
fromXField
public static FieldAnnotation fromXField(XField fieldDescriptor)
-
toXField
public XField toXField()
-
toFieldDescriptor
public FieldDescriptor toFieldDescriptor()
-
getFieldName
public java.lang.String getFieldName()
Get the field name.
-
getFieldSignature
public java.lang.String getFieldSignature()
Get the type signature of the field.
-
isStatic
public boolean isStatic()
Return whether or not the field is static.
-
isRead
public static FieldAnnotation isRead(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
Is the given instruction a read of a field?- Parameters:
ins
- the Instruction to checkcpg
- ConstantPoolGen of the method containing the instruction- Returns:
- the Field if the instruction is a read of a field, null otherwise
-
isWrite
public static FieldAnnotation isWrite(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
Is the instruction a write of a field?- Parameters:
ins
- the Instruction to checkcpg
- ConstantPoolGen of the method containing the instruction- Returns:
- the Field if instruction is a write of a field, null otherwise
-
accept
public void accept(BugAnnotationVisitor visitor)
Description copied from interface:BugAnnotation
Accept a BugAnnotationVisitor.- Parameters:
visitor
- the visitor to accept
-
formatPackageMember
protected java.lang.String formatPackageMember(java.lang.String key, ClassAnnotation primaryClass)
Description copied from class:PackageMemberAnnotation
Do default and subclass-specific formatting.- Specified by:
formatPackageMember
in classPackageMemberAnnotation
- Parameters:
key
- the key specifying how to do the formattingprimaryClass
- TODO
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(BugAnnotation o)
-
getSourceLines
public SourceLineAnnotation getSourceLines()
Description copied from class:BugAnnotationWithSourceLines
Get the SourceLineAnnotation describing the source lines where the method is defined.- Overrides:
getSourceLines
in classBugAnnotationWithSourceLines
- Returns:
- the SourceLineAnnotation, or null if there is no source information for this package element
-
writeXML
public void writeXML(XMLOutput xmlOutput) throws java.io.IOException
Description copied from interface:XMLWriteable
Write this object to given XMLOutput.- Parameters:
xmlOutput
- the XMLOutput for the document- Throws:
java.io.IOException
-
writeXML
public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws java.io.IOException
- Throws:
java.io.IOException
-
-