Package EDU.purdue.cs.bloat.editor
Class ClassEditor
- java.lang.Object
-
- EDU.purdue.cs.bloat.editor.ClassEditor
-
public class ClassEditor extends java.lang.ObjectA 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:
ClassInfo,MethodEditor
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUG
-
Constructor Summary
Constructors Constructor Description ClassEditor(EditorContext context, int modifiers, java.lang.String className, Type superType, Type[] interfaces)Creates a newClassEditorfor editing a class (or interface) from scratch.ClassEditor(EditorContext context, ClassInfo classInfo)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddInterface(Type interfaceType)Adds an interface of a given Type to the set of interfaces that the class implements.voidaddInterface(java.lang.Class interfaceClass)Adds an interface of the given class to the set of interfaces that the class implements.ClassInfoclassInfo()Get the ClassInfo object representing the class that being edited.voidcommit()Commit any changes to the class since creation time.voidcommitOnly(java.util.Set methods, java.util.Set fields)Commits only certain methods and fields.ConstantPoolconstants()Returns the constant pool for the class.EditorContextcontext()Obtain the EditorContext for this ClassEditor.booleanequals(java.lang.Object o)Two ClassEditors are equal if they edit the same class.FieldInfo[]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[]interfaces()Returns the interfaces the class implements.booleanisAbstract()booleanisDirty()Returns true if the class has been modified.booleanisFinal()booleanisInterface()booleanisPrivate()booleanisProtected()booleanisPublic()booleanisStatic()booleanisSuper()MethodInfo[]methods()Returns an array of MethodInfo structures for each method in the class.intmodifiers()Returns the modifiers of the class.java.lang.Stringname()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)voidsetType(Type type)Sets the Type (descriptor) object for the class.Typesuperclass()Returns a Type object for the class's superclass.java.lang.StringtoString()Typetype()Returns the Type (descriptor) for the class.voidvisit(EditorVisitor visitor)This class is visited by an EditorVisitor.
-
-
-
Constructor Detail
-
ClassEditor
public ClassEditor(EditorContext context, ClassInfo classInfo)
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:
ClassInfo,ConstantPool,Type
-
ClassEditor
public ClassEditor(EditorContext context, int modifiers, java.lang.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 Detail
-
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
public java.lang.String name()
Returns the name of the class represented by this ClassEditor.
-
context
public EditorContext context()
Obtain the EditorContext for this ClassEditor.
-
classInfo
public ClassInfo 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
public void setType(Type type)
Sets the Type (descriptor) object for the class.- Parameters:
type- A Type.
-
type
public Type type()
Returns the Type (descriptor) for the class.
-
superclass
public Type superclass()
Returns a Type object for the class's superclass.
-
addInterface
public void addInterface(java.lang.Class interfaceClass)
Adds an interface of the given class to the set of interfaces that the class implements.- Throws:
java.lang.IllegalArgumentException-interfaceClassis not an interface
-
addInterface
public void addInterface(Type interfaceType)
Adds an interface of a given Type to the set of interfaces that the class implements.
-
setInterfaces
public void setInterfaces(Type[] interfaces)
Returns the interfaces the class implements.- Parameters:
interfaces- An array of Types.
-
interfaces
public Type[] 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:
Modifiers
-
fields
public FieldInfo[] fields()
Returns an array of FieldInfo structures for each field in the class.
-
methods
public MethodInfo[] methods()
Returns an array of MethodInfo structures for each method in the class.
-
constants
public ConstantPool 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
public void commitOnly(java.util.Set methods, java.util.Set fields)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
public void visit(EditorVisitor visitor)
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
public boolean equals(java.lang.Object o)
Two ClassEditors are equal if they edit the same class.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
A ClassEditor's hash code is based upon the hash code of the name of the class it edits.- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-