Package EDU.purdue.cs.bloat.editor
Class FieldEditor
- java.lang.Object
-
- EDU.purdue.cs.bloat.editor.FieldEditor
-
public class FieldEditor extends java.lang.ObjectFieldEditor 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 newFieldEditorfor editing a field in a given class with the given modifiers, type and nameFieldEditor(ClassEditor editor, int modifiers, Type type, java.lang.String name, java.lang.Object constantValue)Creates a newFieldEditorfor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit()Commit changes to the field back to the ClassEditor.java.lang.ObjectconstantValue()ClassEditordeclaringClass()Returns the ClassEditor used to edit the class in which this field resides.voiddelete()Marks this field for deletion.FieldInfofieldInfo()Returns the raw FieldInfo of the field being edited.java.lang.StringfullName()Returns a String that contains the declaring class name and the name of the fieldbooleanisDirty()Returns true if this field has been modified.booleanisFinal()booleanisPackage()Returns true, if the field has package level visibility.booleanisPrivate()booleanisProtected()booleanisPublic()booleanisStatic()booleanisTransient()booleanisVolatile()MemberRefmemberRef()Returns aMemberReffor the fieldjava.lang.Stringname()Returns the name of the field.NameAndTypenameAndType()Returns a NameAndType of the field.voidprint(java.io.PrintStream out)Print the field.voidsetDirty(boolean isDirty)Sets the dirty flag of this method.voidsetFinal(boolean flag)voidsetPrivate(boolean flag)voidsetProtected(boolean flag)voidsetPublic(boolean flag)voidsetStatic(boolean flag)voidsetTransient(boolean flag)voidsetVolatile(boolean flag)java.lang.StringtoString()Typetype()Returns the type of the field.
-
-
-
Constructor Detail
-
FieldEditor
public FieldEditor(ClassEditor editor, int modifiers, Type type, java.lang.String name)
Creates a newFieldEditorfor 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 newFieldEditorfor 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 bestaticandfinal- Throws:
java.lang.IllegalArgumentException- If a field with the desired name already exists in the class or ifconstantValueis non-null and neither aString,Integer,Long,Float, norDouble.
-
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 anIllegalStateException.
-
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 aMemberReffor 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:
toStringin classjava.lang.Object
-
-