edu.umd.cs.findbugs
Class FieldAnnotation

java.lang.Object
  extended by edu.umd.cs.findbugs.PackageMemberAnnotation
      extended by edu.umd.cs.findbugs.FieldAnnotation
All Implemented Interfaces:
BugAnnotation, XMLWriteable, java.lang.Comparable<BugAnnotation>

public class FieldAnnotation
extends PackageMemberAnnotation

A BugAnnotation specifying a particular field in particular class.

Author:
David Hovemeyer
See Also:
BugAnnotation

Field Summary
private static java.lang.String DEFAULT_ROLE
           
private static java.lang.String ELEMENT_NAME
           
private  java.lang.String fieldName
           
private  java.lang.String fieldSig
           
private  boolean isStatic
           
 
Fields inherited from class edu.umd.cs.findbugs.PackageMemberAnnotation
className, description
 
Constructor Summary
FieldAnnotation(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, boolean isStatic)
          Constructor.
 
Method Summary
 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)
          Do default and subclass-specific formatting.
static FieldAnnotation fromBCELField(java.lang.String className, org.apache.bcel.classfile.Field field)
          Factory method.
static FieldAnnotation fromReferencedField(DismantleBytecode visitor)
          Factory method.
static FieldAnnotation fromVisitedField(PreorderVisitor visitor)
          Factory method.
 java.lang.String getFieldName()
          Get the field name.
 java.lang.String getFieldSignature()
          Get the type signature of the field.
 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?
 void writeXML(XMLOutput xmlOutput)
          Write this object to given XMLOutput.
 
Methods inherited from class edu.umd.cs.findbugs.PackageMemberAnnotation
format, getClassName, getDescription, getPackageName, setDescription, shorten, toString
 
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

fieldName

private java.lang.String fieldName

fieldSig

private java.lang.String fieldSig

isStatic

private boolean isStatic

ELEMENT_NAME

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

FieldAnnotation

public FieldAnnotation(java.lang.String className,
                       java.lang.String fieldName,
                       java.lang.String fieldSig,
                       boolean isStatic)
Constructor.

Parameters:
className - the name of the class containing the field
fieldName - the name of the field
fieldSig - the type signature of 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(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 field
field - the BCEL Field object

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 check
cpg - 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 check
cpg - 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)
Description copied from class: PackageMemberAnnotation
Do default and subclass-specific formatting.

Specified by:
formatPackageMember in class PackageMemberAnnotation
Parameters:
key - the key specifying how to do the formatting

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

compareTo

public int compareTo(BugAnnotation o)

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