Class ClassEditor

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

public class ClassEditor extends Object
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 Details

    • DEBUG

      public static boolean DEBUG
  • Constructor Details

    • 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:
    • ClassEditor

      public ClassEditor(EditorContext context, int modifiers, String className, Type superType, Type[] interfaces)
      Creates a new ClassEditor for editing a class (or interface) from scratch. This constructor should not be invoked direcly. Use EditorContext.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

      public 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(Class interfaceClass)
      Adds an interface of the given class to the set of interfaces that the class implements.
      Throws:
      IllegalArgumentException - interfaceClass is 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:
    • 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(Set methods, 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(Object o)
      Two ClassEditors are equal if they edit the same class.
      Overrides:
      equals in class 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:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object