Class Field

java.lang.Object
EDU.purdue.cs.bloat.file.Field
All Implemented Interfaces:
FieldInfo

public class Field extends Object implements FieldInfo
Field models a field (member variable) in a class. The Field class grants access to information such as the field's modifiers, its name and type descriptor (represented as indices into the constant pool), and any attributes of the field. Static fields have a ConstantValue attribute.
See Also:
  • Constructor Details

    • Field

      public Field(DataInputStream in, ClassInfo classInfo) throws IOException
      Constructor. Read a field from a class file.
      Parameters:
      in - The data stream of the class file.
      classInfo - The class file containing the field.
      Throws:
      IOException - If an error occurs while reading.
  • Method Details

    • declaringClass

      public ClassInfo declaringClass()
      Get the class which declared the field.
      Specified by:
      declaringClass in interface FieldInfo
      Returns:
      The ClassInfo of the class which declared the field.
    • setNameIndex

      public void setNameIndex(int name)
      Set the index into the constant pool of the name of the field.
      Specified by:
      setNameIndex in interface FieldInfo
      Parameters:
      name - The name of the field.
    • setTypeIndex

      public void setTypeIndex(int type)
      Set the index into the constant pool of the type of the field.
      Specified by:
      setTypeIndex in interface FieldInfo
      Parameters:
      type - The type of the field.
    • nameIndex

      public int nameIndex()
      Get the index into the constant pool of the name of the field.
      Specified by:
      nameIndex in interface FieldInfo
      Returns:
      The index into the constant pool of the name of the field.
    • typeIndex

      public int typeIndex()
      Get the index into the constant pool of the type of the field.
      Specified by:
      typeIndex in interface FieldInfo
      Returns:
      The index into the constant pool of the type of the field.
    • setModifiers

      public void setModifiers(int modifiers)
      Set the modifiers of the field. The values correspond to the constants in the Modifiers class.
      Specified by:
      setModifiers in interface FieldInfo
      Parameters:
      modifiers - A bit vector of modifier flags for the field.
      See Also:
    • modifiers

      public int modifiers()
      Get the modifiers of the field. The values correspond to the constants in the Modifiers class.
      Specified by:
      modifiers in interface FieldInfo
      Returns:
      A bit vector of modifier flags for the field.
      See Also:
    • constantValue

      public int constantValue()
      Get the index into the constant pool of the field's constant value, if any. Returns 0 if the field does not have a constant value.
      Specified by:
      constantValue in interface FieldInfo
      See Also:
    • setConstantValue

      public void setConstantValue(int index)
      Set the index into the constant pool of the field's constant value.
      Specified by:
      setConstantValue in interface FieldInfo
      See Also:
    • write

      public void write(DataOutputStream out) throws IOException
      Write the field to a class file.
      Parameters:
      out - The data stream of the class file.
      Throws:
      IOException - If an error occurs while writing.
    • toString

      public String toString()
      Convert the field to a string.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the field.