Class FieldEditor


  • public class FieldEditor
    extends java.lang.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:
    FieldInfo
    • Constructor Summary

      Constructors 
      Constructor Description
      FieldEditor​(ClassEditor editor, int modifiers, Type type, java.lang.String name)
      Creates a new FieldEditor for editing a field in a given class with the given modifiers, type and name
      FieldEditor​(ClassEditor editor, int modifiers, Type type, java.lang.String name, java.lang.Object constantValue)
      Creates a new FieldEditor for editing a field in a given class with the given modifiers, type, name, and constant value.
      FieldEditor​(ClassEditor editor, int modifiers, java.lang.Class type, java.lang.String name)  
      FieldEditor​(ClassEditor editor, int modifiers, java.lang.Class type, java.lang.String name, java.lang.Object constantValue)  
      FieldEditor​(ClassEditor editor, FieldInfo fieldInfo)
      Constructor.
    • Constructor Detail

      • FieldEditor

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

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

        public FieldEditor​(ClassEditor editor,
                           int modifiers,
                           java.lang.Class type,
                           java.lang.String name)
      • FieldEditor

        public FieldEditor​(ClassEditor editor,
                           int modifiers,
                           Type type,
                           java.lang.String name,
                           java.lang.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:
        java.lang.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:
        ClassEditor, FieldInfo
    • Method Detail

      • 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:
        java.lang.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 java.lang.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:
        java.lang.IllegalStateException - This field has been marked for deletion
      • setPrivate

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

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

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

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

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

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

        public java.lang.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​(java.io.PrintStream out)
        Print the field.
        Parameters:
        out - Stream to which to print.
      • fullName

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object