Class FieldAnnotation

All Implemented Interfaces:
BugAnnotation, XMLWriteable, XMLWriteableWithMessages, Serializable, Cloneable, Comparable<BugAnnotation>

public class FieldAnnotation extends PackageMemberAnnotation
A BugAnnotation specifying a particular field in particular class.
Author:
David Hovemeyer
See Also:
  • Field Details

  • Constructor Details

    • FieldAnnotation

      public FieldAnnotation(@DottedClassName String className, String fieldName, 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
    • FieldAnnotation

      public FieldAnnotation(@DottedClassName String className, String fieldName, String fieldSig, String fieldSourceSig, boolean isStatic)
    • FieldAnnotation

      public FieldAnnotation(@DottedClassName String className, String fieldName, String fieldSig, int accessFlags)
      Constructor.
      Parameters:
      className - the name of the class containing the field
      fieldName - the name of the field
      fieldSig - the type signature of the field
      accessFlags - accessFlags for the field
  • Method Details

    • 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 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
      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 field
      field - 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 String getFieldName()
      Get the field name.
    • getFieldSignature

      public 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 String formatPackageMember(String key, ClassAnnotation primaryClass)
      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
      primaryClass - TODO
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class 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 class BugAnnotationWithSourceLines
      Returns:
      the SourceLineAnnotation, or null if there is no source information for this package element
    • writeXML

      public void writeXML(XMLOutput xmlOutput) throws IOException
      Description copied from interface: XMLWriteable
      Write this object to given XMLOutput.
      Parameters:
      xmlOutput - the XMLOutput for the document
      Throws:
      IOException
    • writeXML

      public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException
      Throws:
      IOException