Class FieldInfo


  • public class FieldInfo
    extends MemberInfo
    Represents a "field_info" structure as defined by the Java VM spec.
    Version:
    1.0
    • Field Detail

      • nameIndex

        private int nameIndex
        Index into the constant pool of a ConstantUtf8Info structure representing the field name, as a simple name.
      • descriptorIndex

        private int descriptorIndex
        Index into the constant pool of a ConstantUtf8Info structure representing a valid field descriptor.
      • attributes

        private java.util.List<AttributeInfo> attributes
        An array of attributes of this field.
    • Constructor Detail

      • FieldInfo

        public FieldInfo​(ClassFile cf,
                         int accessFlags,
                         int nameIndex,
                         int descriptorIndex)
        Constructor.
        Parameters:
        cf - The class file being parsed.
        accessFlags - The access flags.
        nameIndex - The name index.
        descriptorIndex - The descriptor index.
        See Also:
        AccessFlags
    • Method Detail

      • addAttribute

        public void addAttribute​(AttributeInfo info)
        Adds the specified attribute to this field.
        Parameters:
        info - Information about the attribute.
      • getAttribute

        public AttributeInfo getAttribute​(int index)
        Returns the specified attribute.
        Parameters:
        index - The index of the attribute.
        Returns:
        The attribute.
      • getAttributeCount

        public int getAttributeCount()
        Returns the number of attributes of this field.
        Returns:
        The number of attributes.
      • getConstantValueAsString

        public java.lang.String getConstantValueAsString()
        Returns this constant value as a string.
        Returns:
        A string representation of this constant value, or null if it isn't one.
      • getConstantValueAttributeInfo

        private ConstantValue getConstantValueAttributeInfo()
        Returns the ConstantValue attribute info for this field, if any.
        Returns:
        The ConstantValue attribute, or null if there isn't one.
      • getDescriptor

        public java.lang.String getDescriptor()
        Returns the field descriptor of this field.
        Specified by:
        getDescriptor in class MemberInfo
        Returns:
        The field descriptor of this field.
      • getName

        public java.lang.String getName()
        Description copied from class: MemberInfo
        Returns the name of this member.
        Specified by:
        getName in class MemberInfo
        Returns:
        The name of this member.
      • getNameIndex

        public int getNameIndex()
        Returns the index into the constant pool of a ConstantUtf8Info structure representing the field name, as a simple name.
        Returns:
        The index into the constant pool.
      • getTypeString

        public java.lang.String getTypeString​(boolean qualified)
        Returns the type of this field, as determined from its field descriptor.
        Parameters:
        qualified - Whether the returned value should be fully-qualified.
        Returns:
        The type of this field.
      • isConstant

        public boolean isConstant()
        Returns whether this field is a constant.
        Returns:
        Whether this field is a constant.
      • read

        public static FieldInfo read​(ClassFile cf,
                                     java.io.DataInputStream in)
                              throws java.io.IOException
        Reads a FieldInfo structure from the specified input stream.
        Parameters:
        cf - The class file containing this field.
        in - The input stream to read from.
        Returns:
        The field information read.
        Throws:
        java.io.IOException - If an IO error occurs.
      • readAttribute

        private AttributeInfo readAttribute​(java.io.DataInputStream in)
                                     throws java.io.IOException
        Reads an attribute for this field from an input stream.
        Parameters:
        in - The input stream to read from.
        Returns:
        The attribute read, possibly null if it was known to be unimportant for our purposes.
        Throws:
        java.io.IOException - If an IO error occurs.