Class FieldEditor

java.lang.Object
EDU.purdue.cs.bloat.editor.FieldEditor

public class FieldEditor extends Object
FieldEditor provides a means to edit a field of a class. A FieldEditor is created from a ClassEditor and a reflect.FieldInfo. A FieldEditor knows its name, type (descriptor), and its constant value (if it has one).
See Also:
  • Constructor Details

    • FieldEditor

      public FieldEditor(ClassEditor editor, int modifiers, Type type, String name)
      Creates a new FieldEditor for editing a field in a given class with the given modifiers, type and name
      Throws:
      IllegalArgumentException - If a field with the desired name already exists in the class
    • FieldEditor

      public FieldEditor(ClassEditor editor, int modifiers, Class type, String name, Object constantValue)
    • FieldEditor

      public FieldEditor(ClassEditor editor, int modifiers, Class type, String name)
    • FieldEditor

      public FieldEditor(ClassEditor editor, int modifiers, Type type, String name, Object constantValue)
      Creates a new FieldEditor for editing a field in a given class with the given modifiers, type, name, and constant value.
      Parameters:
      modifiers - Fields that have a constant value must be static and final
      Throws:
      IllegalArgumentException - If a field with the desired name already exists in the class or if constantValue is non-null and neither a String, Integer, Long, Float, nor Double.
    • FieldEditor

      public FieldEditor(ClassEditor editor, FieldInfo fieldInfo)
      Constructor.
      Parameters:
      editor - The class containing the field.
      fieldInfo - The field to edit.
      See Also:
  • Method Details

    • declaringClass

      public ClassEditor declaringClass()
      Returns the ClassEditor used to edit the class in which this field resides.
    • isDirty

      public boolean isDirty()
      Returns true if this field has been modified.
    • setDirty

      public void setDirty(boolean isDirty)
      Sets the dirty flag of this method. The dirty flag is true if the method has been modified.
      Throws:
      IllegalStateException - This field has been marked for deletion
    • delete

      public void delete()
      Marks this field for deletion. Once a field has been marked for deletion all attempts to change it will throw an IllegalStateException.
    • fieldInfo

      public FieldInfo fieldInfo()
      Returns the raw FieldInfo of the field being edited.
    • constantValue

      public Object constantValue()
    • isPublic

      public boolean isPublic()
    • isPrivate

      public boolean isPrivate()
    • isProtected

      public boolean isProtected()
    • isPackage

      public boolean isPackage()
      Returns true, if the field has package level visibility.
    • isStatic

      public boolean isStatic()
    • isFinal

      public boolean isFinal()
    • isVolatile

      public boolean isVolatile()
    • isTransient

      public boolean isTransient()
    • setPublic

      public void setPublic(boolean flag)
      Throws:
      IllegalStateException - This field has been marked for deletion
    • setPrivate

      public void setPrivate(boolean flag)
      Throws:
      IllegalStateException - This field has been marked for deletion
    • setProtected

      public void setProtected(boolean flag)
      Throws:
      IllegalStateException - This field has been marked for deletion
    • setStatic

      public void setStatic(boolean flag)
      Throws:
      IllegalStateException - This field has been marked for deletion
    • setFinal

      public void setFinal(boolean flag)
      Throws:
      IllegalStateException - This field has been marked for deletion
    • setTransient

      public void setTransient(boolean flag)
      Throws:
      IllegalStateException - This field has been marked for deletion
    • setVolatile

      public void setVolatile(boolean flag)
      Throws:
      IllegalStateException - This field has been marked for deletion
    • name

      public String name()
      Returns the name of the field.
    • type

      public Type type()
      Returns the type of the field.
    • nameAndType

      public NameAndType nameAndType()
      Returns a NameAndType of the field.
    • memberRef

      public MemberRef memberRef()
      Returns a MemberRef for the field
    • commit

      public void commit()
      Commit changes to the field back to the ClassEditor. Note that the field is committed regardless of whether or not it is dirty.
    • print

      public void print(PrintStream out)
      Print the field.
      Parameters:
      out - Stream to which to print.
    • fullName

      public String fullName()
      Returns a String that contains the declaring class name and the name of the field
    • toString

      public String toString()
      Overrides:
      toString in class Object