Class ClassEditor


  • public class ClassEditor
    extends java.lang.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:
    ClassInfo, MethodEditor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean DEBUG  
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassEditor​(EditorContext context, int modifiers, java.lang.String className, Type superType, Type[] interfaces)
      Creates a new ClassEditor for 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
      void addInterface​(Type interfaceType)
      Adds an interface of a given Type to the set of interfaces that the class implements.
      void addInterface​(java.lang.Class interfaceClass)
      Adds an interface of the given class to the set of interfaces that the class implements.
      ClassInfo classInfo()
      Get the ClassInfo object representing the class that being edited.
      void commit()
      Commit any changes to the class since creation time.
      void commitOnly​(java.util.Set methods, java.util.Set fields)
      Commits only certain methods and fields.
      ConstantPool constants()
      Returns the constant pool for the class.
      EditorContext context()
      Obtain the EditorContext for this ClassEditor.
      boolean equals​(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.
      int hashCode()
      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.
      boolean isAbstract()  
      boolean isDirty()
      Returns true if the class has been modified.
      boolean isFinal()  
      boolean isInterface()  
      boolean isPrivate()  
      boolean isProtected()  
      boolean isPublic()  
      boolean isStatic()  
      boolean isSuper()  
      MethodInfo[] methods()
      Returns an array of MethodInfo structures for each method in the class.
      int modifiers()
      Returns the modifiers of the class.
      java.lang.String name()
      Returns the name of the class represented by this ClassEditor.
      void setAbstract​(boolean flag)  
      void setDirty​(boolean dirty)
      Sets this class's dirty flag.
      void setFinal​(boolean flag)  
      void setInterface​(boolean flag)  
      void setInterfaces​(Type[] interfaces)
      Returns the interfaces the class implements.
      void setPrivate​(boolean flag)  
      void setProtected​(boolean flag)  
      void setPublic​(boolean flag)  
      void setStatic​(boolean flag)  
      void setSuper​(boolean flag)  
      void setType​(Type type)
      Sets the Type (descriptor) object for the class.
      Type superclass()
      Returns a Type object for the class's superclass.
      java.lang.String toString()  
      Type type()
      Returns the Type (descriptor) for the class.
      void visit​(EditorVisitor visitor)
      This class is visited by an EditorVisitor.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEBUG

        public static boolean DEBUG
    • 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
    • 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 - 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:
        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:
        equals in class java.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:
        hashCode in class java.lang.Object
      • toString

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