Class ClassEditor
java.lang.Object
EDU.purdue.cs.bloat.editor.ClassEditor
A ClassEditor provides finer-grain access to a class than a CLassInfo object
does. A ClassEditor takes a ClassInfo and extracts the class's constant pool,
type, super class type, and the types of its interfaces. When editing is
finished, changes are committed with the commit method.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionClassEditor(EditorContext context, int modifiers, String className, Type superType, Type[] interfaces) Creates a newClassEditorfor editing a class (or interface) from scratch.ClassEditor(EditorContext context, ClassInfo classInfo) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInterface(Type interfaceType) Adds an interface of a given Type to the set of interfaces that the class implements.voidaddInterface(Class interfaceClass) Adds an interface of the given class to the set of interfaces that the class implements.Get the ClassInfo object representing the class that being edited.voidcommit()Commit any changes to the class since creation time.voidcommitOnly(Set methods, Set fields) Commits only certain methods and fields.Returns the constant pool for the class.context()Obtain the EditorContext for this ClassEditor.booleanTwo ClassEditors are equal if they edit the same class.fields()Returns an array of FieldInfo structures for each field in the class.inthashCode()A ClassEditor's hash code is based upon the hash code of the name of the class it edits.Type[]Returns the interfaces the class implements.booleanbooleanisDirty()Returns true if the class has been modified.booleanisFinal()booleanbooleanbooleanbooleanisPublic()booleanisStatic()booleanisSuper()methods()Returns an array of MethodInfo structures for each method in the class.intReturns the modifiers of the class.name()Returns the name of the class represented by this ClassEditor.voidsetAbstract(boolean flag) voidsetDirty(boolean dirty) Sets this class's dirty flag.voidsetFinal(boolean flag) voidsetInterface(boolean flag) voidsetInterfaces(Type[] interfaces) Returns the interfaces the class implements.voidsetPrivate(boolean flag) voidsetProtected(boolean flag) voidsetPublic(boolean flag) voidsetStatic(boolean flag) voidsetSuper(boolean flag) voidSets the Type (descriptor) object for the class.Returns a Type object for the class's superclass.toString()type()Returns the Type (descriptor) for the class.voidvisit(EditorVisitor visitor) This class is visited by an EditorVisitor.
-
Field Details
-
DEBUG
public static boolean DEBUG
-
-
Constructor Details
-
ClassEditor
Constructor. Create a new ClassEditor based on information in a ClassInfo object. It extracts the class's constant pool, and the types of the class, its superclass, and any interfaces it implements.- Parameters:
context- The EditorContext used to edit fields and methods.classInfo- The ClassInfo structure of the class to edit.- See Also:
-
ClassEditor
public ClassEditor(EditorContext context, int modifiers, String className, Type superType, Type[] interfaces) Creates a newClassEditorfor editing a class (or interface) from scratch. This constructor should not be invoked direcly. UseEditorContext.newClass(int, String, Type, Type[])instead.
-
-
Method Details
-
isDirty
public boolean isDirty()Returns true if the class has been modified. -
setDirty
public void setDirty(boolean dirty) Sets this class's dirty flag. The dirty flag is true if the class has been modified. -
name
Returns the name of the class represented by this ClassEditor. -
context
Obtain the EditorContext for this ClassEditor. -
classInfo
Get the ClassInfo object representing the class that being edited. -
isPublic
public boolean isPublic() -
isPrivate
public boolean isPrivate() -
isProtected
public boolean isProtected() -
isStatic
public boolean isStatic() -
isFinal
public boolean isFinal() -
isSuper
public boolean isSuper() -
isAbstract
public boolean isAbstract() -
isInterface
public boolean isInterface() -
setPublic
public void setPublic(boolean flag) -
setPrivate
public void setPrivate(boolean flag) -
setProtected
public void setProtected(boolean flag) -
setStatic
public void setStatic(boolean flag) -
setFinal
public void setFinal(boolean flag) -
setSuper
public void setSuper(boolean flag) -
setAbstract
public void setAbstract(boolean flag) -
setInterface
public void setInterface(boolean flag) -
setType
Sets the Type (descriptor) object for the class.- Parameters:
type- A Type.
-
type
Returns the Type (descriptor) for the class. -
superclass
Returns a Type object for the class's superclass. -
addInterface
Adds an interface of the given class to the set of interfaces that the class implements.- Throws:
IllegalArgumentException-interfaceClassis not an interface
-
addInterface
Adds an interface of a given Type to the set of interfaces that the class implements. -
setInterfaces
Returns the interfaces the class implements.- Parameters:
interfaces- An array of Types.
-
interfaces
Returns the interfaces the class implements. -
modifiers
public int modifiers()Returns the modifiers of the class. The values correspond to the constants in the Modifiers class.- Returns:
- A bit vector of modifier flags for the class.
- See Also:
-
fields
Returns an array of FieldInfo structures for each field in the class. -
methods
Returns an array of MethodInfo structures for each method in the class. -
constants
Returns the constant pool for the class. -
commit
public void commit()Commit any changes to the class since creation time. Note that committal will occur regardless of whether or not the class is dirty. -
commitOnly
Commits only certain methods and fields. Note that committal will occur regardless of whether or not the class is dirty.- Parameters:
methods- Methods (MethodInfos) to commit. If null, all methods are committed.fields- Fields (FieldInfos) to commit. If null, all fields are committed.
-
visit
This class is visited by an EditorVisitor. First, this ClassEditor itself is visited. Then, all of this class's fields (FieldEditors) are visited. Finally, each of this class's methods (MethodEditors) are visited. Constructors are visited before regular methods. -
equals
-
hashCode
-
toString
-