Package serp.bytecode

Class BCClass

  • All Implemented Interfaces:
    BCEntity, VisitAcceptor

    public class BCClass
    extends Annotated
    implements VisitAcceptor
    The BCClass represents a class object in the bytecode framework, in many ways mirroring the Class class of Java reflection. The represented class might be a primitive, array, existing object type, or some new user- defined type. As with most entities in the bytecode framework, the BCClass contains methods to manipulate the low-level state of the class (constant pool indexes, etc), but these can and should be ignored in favor of the available high-level methods.

    A BCClass instance is loaded from a Project and remains attached to that project for its lifetime. If a BCClass is removed from its project, the result of any further operations on the class are undefined.

    Note that if a BCClass represents a primitive or array type, all of the available mutator methods and any methods that access the constant pool will throw UnsupportedOperationExceptions.

    • Constructor Summary

      Constructors 
      Constructor Description
      BCClass​(Project project)
      Hide constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acceptVisit​(BCVisitor visit)
      Accept a visit from a BCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.
      BCMethod addDefaultConstructor()
      Convenience method to add a default constructor to this class.
      private void beforeRename​(java.lang.String oldName, java.lang.String newName)
      Attempts to change the class name with the owning project.
      void clearDeclaredFields()
      Clear all fields from this class.
      void clearDeclaredInterfaces()
      Clear this class of all interface declarations.
      void clearDeclaredMethods()
      Clear all declared methods from this class.
      BCField declareField​(java.lang.String name, java.lang.Class type)
      Add a field to this class.
      BCField declareField​(java.lang.String name, java.lang.String type)
      Add a field to this class.
      BCField declareField​(java.lang.String name, BCClass type)
      Add a field to this class.
      BCField declareField​(BCField field)
      Import the information from given field as a new field in this class.
      void declareInterface​(java.lang.Class type)
      Add an interface to those declared by this class.
      void declareInterface​(java.lang.String name)
      Add an interface to those declared by this class.
      void declareInterface​(BCClass type)
      Add an interface to those declared by this class.
      BCMethod declareMethod​(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)
      Add a method to this class.
      BCMethod declareMethod​(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)
      Add a method to this class.
      BCMethod declareMethod​(java.lang.String name, BCClass returnType, BCClass[] paramTypes)
      Add a method to this class.
      BCMethod declareMethod​(BCMethod method)
      Import the information in the given method as a new method of this class.
      int getAccessFlags()
      Return the access flags for this class as a bit array of ACCESS_XXX constants from Constants.
      (package private) java.util.Collection getAttributesHolder()
      Return the collection used to hold the attributes of this entity.
      (package private) BCClass getBCClass()
      Internal access to the owning class.
      java.lang.ClassLoader getClassLoader()
      Return the class loader to use when loading related classes.
      java.lang.String getClassName()
      Return the name of the class only, without package.
      BCClass getComponentBC()
      Return the component type of this class, or null if not an array.
      java.lang.String getComponentName()
      Return the component type name of this class, or null if not an array.
      java.lang.Class getComponentType()
      Return the component type of this class, or null if not an array.
      BCField getDeclaredField​(java.lang.String name)
      Return the declared field with the given name, or null if none.
      BCField[] getDeclaredFields()
      Return all the declared fields of this class, or an empty array if none.
      BCClass[] getDeclaredInterfaceBCs()
      Return the bytecode for the declared interfaces of this class, or an empty array if none.
      int[] getDeclaredInterfaceIndexes()
      Return the list of ConstantPool indexes of the ClassEntrys describing all the interfaces this class declares that it implements/extends.
      java.lang.String[] getDeclaredInterfaceNames()
      Return the names of the interfaces declared for this class, including package names, or an empty array if none.
      java.lang.Class[] getDeclaredInterfaceTypes()
      Return the Class objects for the declared interfaces of this class, or an empty array if none.
      BCMethod getDeclaredMethod​(java.lang.String name)
      Return the declared method with the given name, or null if none.
      BCMethod getDeclaredMethod​(java.lang.String name, java.lang.Class[] paramTypes)
      Return the declared method with the given name and parameter types, or null if none.
      BCMethod getDeclaredMethod​(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)
      Return the declared method with the given name and signature, or null if none.
      BCMethod getDeclaredMethod​(java.lang.String name, java.lang.String[] paramTypes)
      Return the declared method with the given name and parameter types, or null if none.
      BCMethod getDeclaredMethod​(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)
      Return the declared method with the given name and signature, or null if none.
      BCMethod getDeclaredMethod​(java.lang.String name, BCClass[] paramTypes)
      Return the declared method with the given name and parameter types, or null if none.
      BCMethod getDeclaredMethod​(java.lang.String name, BCClass returnType, BCClass[] paramTypes)
      Return the declared method with the given name and signature, or null if none.
      BCMethod[] getDeclaredMethods()
      Return all methods declared by this class.
      BCMethod[] getDeclaredMethods​(java.lang.String name)
      Return all the declared methods with the given name, or an empty array if none.
      BCMethod[] getDeclaredMethods​(java.lang.String name, java.lang.Class[] paramTypes)
      Return all declared methods with the given name and parameter types.
      BCMethod[] getDeclaredMethods​(java.lang.String name, java.lang.String[] paramTypes)
      Return all declared methods with the given name and parameter types.
      BCMethod[] getDeclaredMethods​(java.lang.String name, BCClass[] paramTypes)
      Return all declared methods with the given name and parameter types.
      BCField[] getFields()
      Return all the fields of this class, including those of all superclasses, or an empty array if none.
      BCField[] getFields​(java.lang.String name)
      Return all fields with the given name, including those of all superclasses, or an empty array if none.
      int getIndex()
      Return the ConstantPool index of the ClassEntry for this class.
      InnerClasses getInnerClasses​(boolean add)
      Return inner classes information for the class.
      BCClass[] getInterfaceBCs()
      Return the bytecode of all unique interfaces implemented by this class, including those of all superclasses.
      java.lang.String[] getInterfaceNames()
      Return the names of all unique interfaces implemented by this class, including those of all superclasses.
      java.lang.Class[] getInterfaceTypes()
      Return the Class objects of all unique interfaces implemented by this class, including those of all superclasses.
      int getMagic()
      Return the magic number for this class; if this is a valid type, this should be equal to Constants.VALID_MAGIC (the default value).
      int getMajorVersion()
      Return the major version of the bytecode spec used for this class.
      BCMethod[] getMethods()
      Return the methods of this class, including those of all superclasses, or an empty array if none.
      BCMethod[] getMethods​(java.lang.String name)
      Return the methods with the given name, including those of all superclasses, or an empty array if none.
      BCMethod[] getMethods​(java.lang.String name, java.lang.Class[] paramTypes)
      Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none.
      BCMethod[] getMethods​(java.lang.String name, java.lang.String[] paramTypes)
      Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none.
      BCMethod[] getMethods​(java.lang.String name, BCClass[] paramTypes)
      Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none.
      int getMinorVersion()
      Get the minor version of the bytecode spec used for this class.
      java.lang.String getName()
      Return the name of this class, including package name.
      java.lang.String getPackageName()
      Return the package name only, without class, or null if none.
      ConstantPool getPool()
      Return the constant pool of the current class.
      Project getProject()
      Return the project of the current class.
      SourceFile getSourceFile​(boolean add)
      Return source file information for the class.
      BCClass getSuperclassBC()
      Return the bytecode of the superclass of this class, or null for types without superclasses.
      int getSuperclassIndex()
      Return the ConstantPool index of the ClassEntry for the superclass of this class.
      java.lang.String getSuperclassName()
      Return the name of the superclass for this class, including package name.
      java.lang.Class getSuperclassType()
      Return the Class object for the superclass of this class, if it is loadable.
      java.lang.Class getType()
      Return the Class object for this class, if it is loadable.
      (package private) void invalidate()
      Invalidate this class.
      boolean isAbstract()
      Manipulate the class access flags.
      boolean isAnnotation()
      Manipulate the class access flags.
      boolean isArray()
      Return true if this class is an array type.
      boolean isDeprecated()
      Convenience method to return deprecation information for the class.
      boolean isEnum()
      Manipulate the class access flags.
      boolean isFinal()
      Manipulate the class access flags.
      boolean isInstanceOf​(java.lang.Class type)
      Return true if this class or any of its superclasses implement/extend the given interface/class.
      boolean isInstanceOf​(java.lang.String name)
      Return true if this class or any of its superclasses implement/extend the given interface/class.
      boolean isInstanceOf​(BCClass type)
      Return true if this class or any of its superclasses implement/extend the given interface/class.
      boolean isInterface()
      Manipulate the class access flags.
      boolean isPackage()
      Manipulate the class access flags.
      boolean isPrimitive()
      Return true if this class is a primitive type.
      boolean isPublic()
      Manipulate the class access flags.
      boolean isSynthetic()
      Manipulate the class access flags.
      boolean isValid()
      Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.
      void makePackage()
      Manipulate the class access flags.
      void makePublic()
      Manipulate the class access flags.
      void moveDeclaredField​(int fromIdx, int toIdx)
      Rearrange declared field order.
      void moveDeclaredInterface​(int fromIdx, int toIdx)
      Rearrange declared interface order.
      void moveDeclaredMethod​(int fromIdx, int toIdx)
      Rearrange method order.
      private boolean paramsMatch​(BCMethod meth, java.lang.String[] params)
      Return true iff the given method's parameters match params.
      (package private) void read​(java.io.File classFile, java.lang.ClassLoader loader)
      Initialize from the class definition in the given file.
      (package private) void read​(java.io.InputStream instream, java.lang.ClassLoader loader)
      Initialize from the class definition in the given stream.
      (package private) void read​(java.lang.Class type)
      Initialize from the bytecode of the definition of the given class.
      (package private) void read​(BCClass orig)
      Initialize from the given parsed bytecode.
      boolean removeDeclaredField​(java.lang.String name)
      Remove a field from this class.
      boolean removeDeclaredField​(BCField field)
      Remove a field from this class.
      boolean removeDeclaredInterface​(java.lang.Class type)
      Remove an interface declared by this class.
      boolean removeDeclaredInterface​(java.lang.String name)
      Remove an interface declared by this class.
      boolean removeDeclaredInterface​(BCClass type)
      Remove an interface declared by this class.
      boolean removeDeclaredMethod​(java.lang.String name)
      Remove a method from this class.
      boolean removeDeclaredMethod​(java.lang.String name, java.lang.Class[] paramTypes)
      Removes a method from this class.
      boolean removeDeclaredMethod​(java.lang.String name, java.lang.String[] paramTypes)
      Removes a method from this class.
      boolean removeDeclaredMethod​(java.lang.String name, BCClass[] paramTypes)
      Removes a method from this class.
      boolean removeDeclaredMethod​(BCMethod method)
      Removes a method from this class.
      boolean removeInnerClasses()
      Remove the inner classes attribute for the class.
      boolean removeSourceFile()
      Remove the source file attribute for the class.
      void setAbstract​(boolean on)
      Manipulate the class access flags.
      void setAccessFlags​(int access)
      Set the access flags for this class as a bit array of ACCESS_XXX constants from Constants.
      void setAnnotation​(boolean on)
      Manipulate the class access flags.
      void setDeclaredFields​(BCField[] fields)
      Set the fields for this class; this method is useful for importing all fields from another class.
      void setDeclaredInterfaceIndexes​(int[] interfaceIndexes)
      Set the list of ConstantPool indexes of the ClassEntrys describing all the interfaces this class declares it implements/extends; set to null or an empty array if none.
      void setDeclaredInterfaces​(java.lang.Class[] interfaces)
      Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
      void setDeclaredInterfaces​(java.lang.String[] interfaces)
      Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
      void setDeclaredInterfaces​(BCClass[] interfaces)
      Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
      void setDeclaredMethods​(BCMethod[] methods)
      Set the methods for this class; this method is useful for importing all methods from another class.
      void setDeprecated​(boolean on)
      Convenience method to set whether this class should be considered deprecated.
      void setEnum​(boolean on)
      Manipulate the class access flags.
      void setFinal​(boolean on)
      Manipulate the class access flags.
      void setIndex​(int index)
      Set the ConstantPool index of the ClassEntry for this class.
      void setInterface​(boolean on)
      Manipulate the class access flags.
      void setMagic​(int magic)
      Set the magic number for this class; if this is a valid type, this should be equal to Constants.VALID_MAGIC (the default value).
      void setMajorVersion​(int majorVersion)
      Set the major version of the bytecode spec used for this class.
      void setMinorVersion​(int minorVersion)
      Set the minor version of the bytecode spec used for this class.
      void setName​(java.lang.String name)
      Set the name of this class, including package name.
      (package private) void setState​(State state)
      Set the class state.
      void setSuperclass​(java.lang.Class type)
      Set the superclass of this class.
      void setSuperclass​(java.lang.String name)
      Set the superclass of this class.
      void setSuperclass​(BCClass type)
      Set the superclass of this class.
      void setSuperclassIndex​(int index)
      Set the ConstantPool index of the ClassEntry for the superclass of this class.
      void setSynthetic​(boolean on)
      Manipulate the class access flags.
      byte[] toByteArray()
      Return the bytecode of this class as a byte array, possibly for use in a custom ClassLoader.
      void write()
      Write the class bytecode to the .class file in the proper directory of the CLASSPATH.
      void write​(java.io.File classFile)
      Write the class bytecode to the specified file.
      void write​(java.io.OutputStream outstream)
      Write the class bytecode to the specified stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _project

        private Project _project
      • _state

        private State _state
      • _loader

        private java.lang.ClassLoader _loader
    • Constructor Detail

      • BCClass

        BCClass​(Project project)
        Hide constructor. For use by the owning project only.
    • Method Detail

      • setState

        void setState​(State state)
        Set the class state. For use by the owning project only.
      • invalidate

        void invalidate()
        Invalidate this class.
      • read

        void read​(java.io.File classFile,
                  java.lang.ClassLoader loader)
           throws java.io.IOException
        Initialize from the class definition in the given file. For use by the owning project only.
        Throws:
        java.io.IOException
      • read

        void read​(java.io.InputStream instream,
                  java.lang.ClassLoader loader)
           throws java.io.IOException
        Initialize from the class definition in the given stream. For use by the owning project only.
        Throws:
        java.io.IOException
      • read

        void read​(java.lang.Class type)
           throws java.io.IOException
        Initialize from the bytecode of the definition of the given class. For use by the owning project only.
        Throws:
        java.io.IOException
      • read

        void read​(BCClass orig)
        Initialize from the given parsed bytecode. For use by the owning project only.
      • write

        public void write()
                   throws java.io.IOException
        Write the class bytecode to the .class file in the proper directory of the CLASSPATH. The file must exist already, so this method only works on existing classes.
        Throws:
        java.io.IOException
      • write

        public void write​(java.io.File classFile)
                   throws java.io.IOException
        Write the class bytecode to the specified file.
        Throws:
        java.io.IOException
      • write

        public void write​(java.io.OutputStream outstream)
                   throws java.io.IOException
        Write the class bytecode to the specified stream.
        Throws:
        java.io.IOException
      • toByteArray

        public byte[] toByteArray()
        Return the bytecode of this class as a byte array, possibly for use in a custom ClassLoader.
      • getMagic

        public int getMagic()
        Return the magic number for this class; if this is a valid type, this should be equal to Constants.VALID_MAGIC (the default value).
      • setMagic

        public void setMagic​(int magic)
        Set the magic number for this class; if this is a valid type, this should be equal to Constants.VALID_MAGIC (the default value).
      • getMajorVersion

        public int getMajorVersion()
        Return the major version of the bytecode spec used for this class. JVMs are only required to operate with versions that they understand; leaving the default value of Constants.MAJOR_VERSION is safe.
      • setMajorVersion

        public void setMajorVersion​(int majorVersion)
        Set the major version of the bytecode spec used for this class. JVMs are only required to operate with versions that they understand; leaving the default value of Constants.MAJOR_VERSION is safe.
      • getMinorVersion

        public int getMinorVersion()
        Get the minor version of the bytecode spec used for this class. JVMs are only required to operate with versions that they understand; leaving the default value of Constants.MINOR_VERSION is safe.
      • setMinorVersion

        public void setMinorVersion​(int minorVersion)
        Set the minor version of the bytecode spec used for this class. JVMs are only required to operate with versions that they understand; leaving the default value of Constants.MINOR_VERSION is safe.
      • getAccessFlags

        public int getAccessFlags()
        Return the access flags for this class as a bit array of ACCESS_XXX constants from Constants. This can be used to transfer access flags between classes without getting/setting each possible flag.
      • setAccessFlags

        public void setAccessFlags​(int access)
        Set the access flags for this class as a bit array of ACCESS_XXX constants from Constants. This can be used to transfer access flags between classes without getting/setting each possible flag.
      • isPublic

        public boolean isPublic()
        Manipulate the class access flags.
      • makePublic

        public void makePublic()
        Manipulate the class access flags.
      • isPackage

        public boolean isPackage()
        Manipulate the class access flags.
      • makePackage

        public void makePackage()
        Manipulate the class access flags.
      • isFinal

        public boolean isFinal()
        Manipulate the class access flags.
      • setFinal

        public void setFinal​(boolean on)
        Manipulate the class access flags.
      • isInterface

        public boolean isInterface()
        Manipulate the class access flags.
      • setInterface

        public void setInterface​(boolean on)
        Manipulate the class access flags.
      • isAbstract

        public boolean isAbstract()
        Manipulate the class access flags.
      • setAbstract

        public void setAbstract​(boolean on)
        Manipulate the class access flags.
      • isSynthetic

        public boolean isSynthetic()
        Manipulate the class access flags.
      • setSynthetic

        public void setSynthetic​(boolean on)
        Manipulate the class access flags.
      • isAnnotation

        public boolean isAnnotation()
        Manipulate the class access flags.
      • setAnnotation

        public void setAnnotation​(boolean on)
        Manipulate the class access flags. Setting to true also makes this an interface.
      • isEnum

        public boolean isEnum()
        Manipulate the class access flags.
      • setEnum

        public void setEnum​(boolean on)
        Manipulate the class access flags.
      • isPrimitive

        public boolean isPrimitive()
        Return true if this class is a primitive type.
      • isArray

        public boolean isArray()
        Return true if this class is an array type.
      • getIndex

        public int getIndex()
        Return the ConstantPool index of the ClassEntry for this class. Returns 0 if the class does not have a constant pool (such as a primitive or array).
      • setIndex

        public void setIndex​(int index)
        Set the ConstantPool index of the ClassEntry for this class. Unlike most other low-level methods, the index will be checked against the pool immediately; classes must have a valid name at all times.
      • getName

        public java.lang.String getName()
        Return the name of this class, including package name. The name will be in a form suitable for a Class.forName(java.lang.String) call.
      • getClassName

        public java.lang.String getClassName()
        Return the name of the class only, without package.
      • getPackageName

        public java.lang.String getPackageName()
        Return the package name only, without class, or null if none.
      • setName

        public void setName​(java.lang.String name)
        Set the name of this class, including package name.
      • getType

        public java.lang.Class getType()
        Return the Class object for this class, if it is loadable.
      • getComponentName

        public java.lang.String getComponentName()
        Return the component type name of this class, or null if not an array. The name will be in a form suitable for a Class.forName(java.lang.String) call.
      • getComponentType

        public java.lang.Class getComponentType()
        Return the component type of this class, or null if not an array.
      • getComponentBC

        public BCClass getComponentBC()
        Return the component type of this class, or null if not an array.
      • getSuperclassIndex

        public int getSuperclassIndex()
        Return the ConstantPool index of the ClassEntry for the superclass of this class. Returns -1 if the class does not have a constant pool (such as a primitive or array).
      • setSuperclassIndex

        public void setSuperclassIndex​(int index)
        Set the ConstantPool index of the ClassEntry for the superclass of this class.
      • getSuperclassName

        public java.lang.String getSuperclassName()
        Return the name of the superclass for this class, including package name. The name will be in a form suitable for a Class.forName(java.lang.String) call, or null for types without superclasses.
      • getSuperclassType

        public java.lang.Class getSuperclassType()
        Return the Class object for the superclass of this class, if it is loadable. Returns null for types without superclasses.
      • getSuperclassBC

        public BCClass getSuperclassBC()
        Return the bytecode of the superclass of this class, or null for types without superclasses.
      • setSuperclass

        public void setSuperclass​(java.lang.String name)
        Set the superclass of this class.
      • setSuperclass

        public void setSuperclass​(java.lang.Class type)
        Set the superclass of this class.
      • setSuperclass

        public void setSuperclass​(BCClass type)
        Set the superclass of this class.
      • getDeclaredInterfaceIndexes

        public int[] getDeclaredInterfaceIndexes()
        Return the list of ConstantPool indexes of the ClassEntrys describing all the interfaces this class declares that it implements/extends.
        Returns:
        the implmented interfaces, or an empty array if none
      • setDeclaredInterfaceIndexes

        public void setDeclaredInterfaceIndexes​(int[] interfaceIndexes)
        Set the list of ConstantPool indexes of the ClassEntrys describing all the interfaces this class declares it implements/extends; set to null or an empty array if none.
      • getDeclaredInterfaceNames

        public java.lang.String[] getDeclaredInterfaceNames()
        Return the names of the interfaces declared for this class, including package names, or an empty array if none. The names will be in a form suitable for a Class.forName(java.lang.String) call.
      • getDeclaredInterfaceTypes

        public java.lang.Class[] getDeclaredInterfaceTypes()
        Return the Class objects for the declared interfaces of this class, or an empty array if none.
      • getDeclaredInterfaceBCs

        public BCClass[] getDeclaredInterfaceBCs()
        Return the bytecode for the declared interfaces of this class, or an empty array if none.
      • setDeclaredInterfaces

        public void setDeclaredInterfaces​(java.lang.String[] interfaces)
        Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
      • setDeclaredInterfaces

        public void setDeclaredInterfaces​(java.lang.Class[] interfaces)
        Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
      • setDeclaredInterfaces

        public void setDeclaredInterfaces​(BCClass[] interfaces)
        Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
      • getInterfaceNames

        public java.lang.String[] getInterfaceNames()
        Return the names of all unique interfaces implemented by this class, including those of all superclasses. The names will be returned in a form suitable for a Class.forName(java.lang.String) call. This method does not recurse into interfaces-of-interfaces.
      • getInterfaceTypes

        public java.lang.Class[] getInterfaceTypes()
        Return the Class objects of all unique interfaces implemented by this class, including those of all superclasses. This method does not recurse into interfaces-of-interfaces.
      • getInterfaceBCs

        public BCClass[] getInterfaceBCs()
        Return the bytecode of all unique interfaces implemented by this class, including those of all superclasses. This method does not recurse into interfaces-of-interfaces.
      • clearDeclaredInterfaces

        public void clearDeclaredInterfaces()
        Clear this class of all interface declarations.
      • removeDeclaredInterface

        public boolean removeDeclaredInterface​(java.lang.String name)
        Remove an interface declared by this class.
        Returns:
        true if the class had the interface, false otherwise
      • removeDeclaredInterface

        public boolean removeDeclaredInterface​(java.lang.Class type)
        Remove an interface declared by this class.
        Returns:
        true if the class had the interface, false otherwise
      • removeDeclaredInterface

        public boolean removeDeclaredInterface​(BCClass type)
        Remove an interface declared by this class.
        Returns:
        true if the class had the interface, false otherwise
      • moveDeclaredInterface

        public void moveDeclaredInterface​(int fromIdx,
                                          int toIdx)
        Rearrange declared interface order.
      • declareInterface

        public void declareInterface​(java.lang.String name)
        Add an interface to those declared by this class.
      • declareInterface

        public void declareInterface​(java.lang.Class type)
        Add an interface to those declared by this class.
      • declareInterface

        public void declareInterface​(BCClass type)
        Add an interface to those declared by this class.
      • isInstanceOf

        public boolean isInstanceOf​(java.lang.String name)
        Return true if this class or any of its superclasses implement/extend the given interface/class. This method does not recurse into interfaces-of-interfaces.
      • isInstanceOf

        public boolean isInstanceOf​(java.lang.Class type)
        Return true if this class or any of its superclasses implement/extend the given interface/class. This method does not recurse into interfaces-of-interfaces.
      • isInstanceOf

        public boolean isInstanceOf​(BCClass type)
        Return true if this class or any of its superclasses implement/extend the given interface/class. This method does not recurse into interfaces-of-interfaces.
      • getDeclaredFields

        public BCField[] getDeclaredFields()
        Return all the declared fields of this class, or an empty array if none.
      • getDeclaredField

        public BCField getDeclaredField​(java.lang.String name)
        Return the declared field with the given name, or null if none.
      • getFields

        public BCField[] getFields()
        Return all the fields of this class, including those of all superclasses, or an empty array if none.
      • getFields

        public BCField[] getFields​(java.lang.String name)
        Return all fields with the given name, including those of all superclasses, or an empty array if none.
      • setDeclaredFields

        public void setDeclaredFields​(BCField[] fields)
        Set the fields for this class; this method is useful for importing all fields from another class. Set to null or empty array if none.
      • declareField

        public BCField declareField​(BCField field)
        Import the information from given field as a new field in this class.
        Returns:
        the added field
      • declareField

        public BCField declareField​(java.lang.String name,
                                    java.lang.String type)
        Add a field to this class.
        Returns:
        the added field
      • declareField

        public BCField declareField​(java.lang.String name,
                                    java.lang.Class type)
        Add a field to this class.
        Returns:
        the added field
      • declareField

        public BCField declareField​(java.lang.String name,
                                    BCClass type)
        Add a field to this class.
        Returns:
        the added field
      • clearDeclaredFields

        public void clearDeclaredFields()
        Clear all fields from this class.
      • removeDeclaredField

        public boolean removeDeclaredField​(java.lang.String name)
        Remove a field from this class. After this method, the removed field will be invalid, and the result of any operations on it is undefined.
        Returns:
        true if this class contained the field, false otherwise
      • removeDeclaredField

        public boolean removeDeclaredField​(BCField field)
        Remove a field from this class. After this method, the removed field will be invalid, and the result of any operations on it is undefined.
        Returns:
        true if this class contained the field, false otherwise
      • moveDeclaredField

        public void moveDeclaredField​(int fromIdx,
                                      int toIdx)
        Rearrange declared field order.
      • getDeclaredMethods

        public BCMethod[] getDeclaredMethods()
        Return all methods declared by this class. Constructors and static initializers are included.
      • getDeclaredMethod

        public BCMethod getDeclaredMethod​(java.lang.String name)
        Return the declared method with the given name, or null if none. If multiple methods are declared with the given name, which is returned is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethods

        public BCMethod[] getDeclaredMethods​(java.lang.String name)
        Return all the declared methods with the given name, or an empty array if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethod

        public BCMethod getDeclaredMethod​(java.lang.String name,
                                          java.lang.String[] paramTypes)
        Return the declared method with the given name and parameter types, or null if none. If multiple methods are declared with the given name and parameters, which is returned is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • paramsMatch

        private boolean paramsMatch​(BCMethod meth,
                                    java.lang.String[] params)
        Return true iff the given method's parameters match params.
      • getDeclaredMethod

        public BCMethod getDeclaredMethod​(java.lang.String name,
                                          java.lang.Class[] paramTypes)
        Return the declared method with the given name and parameter types, or null if none. If multiple methods are declared with the given name and parameters, which is returned is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethod

        public BCMethod getDeclaredMethod​(java.lang.String name,
                                          BCClass[] paramTypes)
        Return the declared method with the given name and parameter types, or null if none. If multiple methods are declared with the given name and parameters, which is returned is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethods

        public BCMethod[] getDeclaredMethods​(java.lang.String name,
                                             java.lang.String[] paramTypes)
        Return all declared methods with the given name and parameter types. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethods

        public BCMethod[] getDeclaredMethods​(java.lang.String name,
                                             java.lang.Class[] paramTypes)
        Return all declared methods with the given name and parameter types. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethods

        public BCMethod[] getDeclaredMethods​(java.lang.String name,
                                             BCClass[] paramTypes)
        Return all declared methods with the given name and parameter types. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethod

        public BCMethod getDeclaredMethod​(java.lang.String name,
                                          java.lang.String returnType,
                                          java.lang.String[] paramTypes)
        Return the declared method with the given name and signature, or null if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethod

        public BCMethod getDeclaredMethod​(java.lang.String name,
                                          java.lang.Class returnType,
                                          java.lang.Class[] paramTypes)
        Return the declared method with the given name and signature, or null if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getDeclaredMethod

        public BCMethod getDeclaredMethod​(java.lang.String name,
                                          BCClass returnType,
                                          BCClass[] paramTypes)
        Return the declared method with the given name and signature, or null if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getMethods

        public BCMethod[] getMethods()
        Return the methods of this class, including those of all superclasses, or an empty array if none. The base version of methods that are overridden will be included, as will all constructors and static initializers. The methods will be ordered from those in the most-specific type up to those in Object.
      • getMethods

        public BCMethod[] getMethods​(java.lang.String name)
        Return the methods with the given name, including those of all superclasses, or an empty array if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getMethods

        public BCMethod[] getMethods​(java.lang.String name,
                                     java.lang.String[] paramTypes)
        Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getMethods

        public BCMethod[] getMethods​(java.lang.String name,
                                     java.lang.Class[] paramTypes)
        Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • getMethods

        public BCMethod[] getMethods​(java.lang.String name,
                                     BCClass[] paramTypes)
        Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
      • setDeclaredMethods

        public void setDeclaredMethods​(BCMethod[] methods)
        Set the methods for this class; this method is useful for importing all methods from another class. Set to null or empty array if none.
      • declareMethod

        public BCMethod declareMethod​(BCMethod method)
        Import the information in the given method as a new method of this class.
        Returns:
        the added method
      • declareMethod

        public BCMethod declareMethod​(java.lang.String name,
                                      java.lang.String returnType,
                                      java.lang.String[] paramTypes)
        Add a method to this class. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
        Returns:
        the added method
      • declareMethod

        public BCMethod declareMethod​(java.lang.String name,
                                      java.lang.Class returnType,
                                      java.lang.Class[] paramTypes)
        Add a method to this class. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
        Returns:
        the added method
      • declareMethod

        public BCMethod declareMethod​(java.lang.String name,
                                      BCClass returnType,
                                      BCClass[] paramTypes)
        Add a method to this class. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
        Returns:
        the added method
      • clearDeclaredMethods

        public void clearDeclaredMethods()
        Clear all declared methods from this class.
      • removeDeclaredMethod

        public boolean removeDeclaredMethod​(java.lang.String name)
        Remove a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. If multiple methods match the given name, which is removed is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
        Returns:
        true if this class contained the method, false otherwise
      • removeDeclaredMethod

        public boolean removeDeclaredMethod​(BCMethod method)
        Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined.
        Returns:
        true if this class contained the method, false otherwise
      • removeDeclaredMethod

        public boolean removeDeclaredMethod​(java.lang.String name,
                                            java.lang.String[] paramTypes)
        Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
        Returns:
        true if this class contained the method, false otherwise
      • removeDeclaredMethod

        public boolean removeDeclaredMethod​(java.lang.String name,
                                            java.lang.Class[] paramTypes)
        Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
        Returns:
        true if this class contained the method, false otherwise
      • removeDeclaredMethod

        public boolean removeDeclaredMethod​(java.lang.String name,
                                            BCClass[] paramTypes)
        Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. Note that in bytecode, constructors are named <init> and static initializers are named <clinit>.
        Returns:
        true if this class contained the method, false otherwise
      • moveDeclaredMethod

        public void moveDeclaredMethod​(int fromIdx,
                                       int toIdx)
        Rearrange method order.
      • addDefaultConstructor

        public BCMethod addDefaultConstructor()
        Convenience method to add a default constructor to this class. If a default constructor already exists, this method will return it without modification. This method can only be called if the superclass has been set.
        Returns:
        the default constructor
      • getSourceFile

        public SourceFile getSourceFile​(boolean add)
        Return source file information for the class. Acts internally through the Attributes interface.
        Parameters:
        add - if true, a new source file attribute will be added if not already present
        Returns:
        the source file information, or null if none and the add param is set to false
      • removeSourceFile

        public boolean removeSourceFile()
        Remove the source file attribute for the class. Acts internally through the Attributes interface.
        Returns:
        true if there was a file to remove
      • getInnerClasses

        public InnerClasses getInnerClasses​(boolean add)
        Return inner classes information for the class. Acts internally through the Attributes interface.
        Parameters:
        add - if true, a new inner classes attribute will be added if not already present
        Returns:
        the inner classes information, or null if none and the add param is set to false
      • removeInnerClasses

        public boolean removeInnerClasses()
        Remove the inner classes attribute for the class. Acts internally through the Attributes interface.
        Returns:
        true if there was an attribute to remove
      • isDeprecated

        public boolean isDeprecated()
        Convenience method to return deprecation information for the class. Acts internally through the Attributes interface.
      • setDeprecated

        public void setDeprecated​(boolean on)
        Convenience method to set whether this class should be considered deprecated. Acts internally through the Attributes interface.
      • acceptVisit

        public void acceptVisit​(BCVisitor visit)
        Description copied from interface: VisitAcceptor
        Accept a visit from a BCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.
        Specified by:
        acceptVisit in interface VisitAcceptor
      • getProject

        public Project getProject()
        Description copied from interface: BCEntity
        Return the project of the current class.
        Specified by:
        getProject in interface BCEntity
      • getPool

        public ConstantPool getPool()
        Description copied from interface: BCEntity
        Return the constant pool of the current class.
        Specified by:
        getPool in interface BCEntity
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Description copied from interface: BCEntity
        Return the class loader to use when loading related classes.
        Specified by:
        getClassLoader in interface BCEntity
      • isValid

        public boolean isValid()
        Description copied from interface: BCEntity
        Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.
        Specified by:
        isValid in interface BCEntity
      • getAttributesHolder

        java.util.Collection getAttributesHolder()
        Description copied from class: Attributes
        Return the collection used to hold the attributes of this entity.
        Specified by:
        getAttributesHolder in class Attributes
      • beforeRename

        private void beforeRename​(java.lang.String oldName,
                                  java.lang.String newName)
        Attempts to change the class name with the owning project. The project can reject the change if a class with the given new name already exists; therefore this method should be called before the change is recorded in the class.