public abstract class CtClass extends Object
CtClass represents a class.
 It is obtained from ClassPool.ClassPool.get(String)| Modifier and Type | Field and Description | 
|---|---|
| static CtClass | booleanTypeThe  CtClassobject representing
 thebooleantype. | 
| static CtClass | byteTypeThe  CtClassobject representing
 thebytetype. | 
| static CtClass | charTypeThe  CtClassobject representing
 thechartype. | 
| static String | debugDumpIf the value of this field is not null, then all class
 files modified by Javassist are saved under the directory
 specified by this variable. | 
| static CtClass | doubleTypeThe  CtClassobject representing
 thedoubletype. | 
| static CtClass | floatTypeThe  CtClassobject representing
 thefloattype. | 
| static CtClass | intTypeThe  CtClassobject representing
 theinttype. | 
| static CtClass | longTypeThe  CtClassobject representing
 thelongtype. | 
| protected String | qualifiedName | 
| static CtClass | shortTypeThe  CtClassobject representing
 theshorttype. | 
| static String | versionThe version number of this release. | 
| static CtClass | voidTypeThe  CtClassobject representing
 thevoidtype. | 
| Modifier | Constructor and Description | 
|---|---|
| protected  | CtClass(String name) | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addConstructor(CtConstructor c)Adds a constructor. | 
| void | addField(CtField f)Adds a field. | 
| void | addField(CtField f,
        CtField.Initializer init)Adds a field with an initial value. | 
| void | addField(CtField f,
        String init)Adds a field with an initial value. | 
| void | addInterface(CtClass anInterface)Adds an interface. | 
| void | addMethod(CtMethod m)Adds a method. | 
| void | debugWriteFile()Writes a class file as  writeFile()does although this
 method does not prune or freeze the class after writing the class
 file. | 
| void | debugWriteFile(String directoryName)Writes a class file as  writeFile()does although this
 method does not prune or freeze the class after writing the class
 file. | 
| void | defrost()Defrosts the class so that the class can be modified again. | 
| void | detach()Removes this  CtClassobject from theClassPool. | 
| protected void | extendToString(StringBuffer buffer)Implemented in subclasses to add to the  toString()result. | 
| void | freeze()Makes the class frozen. | 
| AccessorMaker | getAccessorMaker()Undocumented method. | 
| Object | getAnnotation(Class clz)Returns the annotation if the class has the specified annotation type. | 
| Object[] | getAnnotations()Returns the annotations associated with this class. | 
| byte[] | getAttribute(String name)Obtains an attribute with the given name. | 
| Object[] | getAvailableAnnotations()Returns the annotations associated with this class. | 
| ClassFile | getClassFile()Returns a class file for this class. | 
| ClassFile | getClassFile2()Returns a class file for this class (read only). | 
| CtConstructor | getClassInitializer()Gets the class initializer (static constructor)
 declared in the class. | 
| ClassPool | getClassPool()Returns a  ClassPoolfor this class. | 
| CtClass | getComponentType()If this object represents an array, this method returns the component
 type of the array. | 
| CtConstructor | getConstructor(String desc)Returns the constructor with the given signature,
 which is represented by a character string
 called method descriptor. | 
| CtConstructor[] | getConstructors()Returns an array containing  CtConstructorobjects
 representing all the non-private constructors of the class. | 
| CtBehavior[] | getDeclaredBehaviors()Gets all the constructors and methods declared in the class. | 
| CtClass[] | getDeclaredClasses()Returns an array of nested classes declared in the class. | 
| CtConstructor | getDeclaredConstructor(CtClass[] params)Returns a constructor receiving the specified parameters. | 
| CtConstructor[] | getDeclaredConstructors()Gets all the constructors declared in the class. | 
| CtField | getDeclaredField(String name)Retrieves the field with the specified name among the fields
 declared in the class. | 
| CtField | getDeclaredField(String name,
                String desc)Retrieves the field with the specified name and type among the fields
 declared in the class. | 
| CtField[] | getDeclaredFields()Gets all the fields declared in the class. | 
| CtMethod | getDeclaredMethod(String name)Retrieves the method with the specified name among the methods
 declared in the class. | 
| CtMethod | getDeclaredMethod(String name,
                 CtClass[] params)Retrieves the method with the specified name and parameter types
 among the methods declared in the class. | 
| CtMethod[] | getDeclaredMethods()Gets all methods declared in the class. | 
| CtMethod[] | getDeclaredMethods(String name)Retrieves methods with the specified name among the methods
 declared in the class. | 
| CtClass | getDeclaringClass()If this class is a member class or interface of another class,
 then the class enclosing this class is returned. | 
| CtBehavior | getEnclosingBehavior()Returns the immediately enclosing method of this class. | 
| CtMethod | getEnclosingMethod()Deprecated. 
 The enclosing method might be a constructor.
             Use  getEnclosingBehavior(). | 
| CtField | getField(String name)Returns the field with the specified name. | 
| CtField | getField(String name,
        String desc)Returns the field with the specified name and type. | 
| CtField[] | getFields()Returns an array containing  CtFieldobjects
 representing all the non-private fields of the class. | 
| String | getGenericSignature()Returns the generic signature of the class. | 
| CtClass[] | getInterfaces()Obtains the class objects representing the interfaces implemented
 by the class or, if this object represents an interface, the interfaces
 extended by that interface. | 
| CtMethod | getMethod(String name,
         String desc)Returns the method with the given name and signature. | 
| CtMethod[] | getMethods()Returns an array containing  CtMethodobjects
 representing all the non-private methods of the class. | 
| int | getModifiers()Returns the modifiers for this class, encoded in an integer. | 
| String | getName()Obtains the fully-qualified name of the class. | 
| CtClass[] | getNestedClasses()Returns an array of nested classes declared in the class. | 
| String | getPackageName()Obtains the package name. | 
| Collection | getRefClasses()Returns a collection of the names of all the classes
 referenced in this class. | 
| String | getSimpleName()Obtains the not-qualified class name. | 
| CtClass | getSuperclass()Obtains the class object representing the superclass of the
 class. | 
| URL | getURL()Returns the uniform resource locator (URL) of the class file. | 
| boolean | hasAnnotation(Class annotationType)Returns true if the class has the specified annotation type. | 
| boolean | hasAnnotation(String annotationTypeName)Returns true if the class has the specified annotation type. | 
| void | instrument(CodeConverter converter)Applies the given converter to all methods and constructors
 declared in the class. | 
| void | instrument(ExprEditor editor)Modifies the bodies of all methods and constructors
 declared in the class. | 
| boolean | isAnnotation()Determines whether this object represents an annotation type. | 
| boolean | isArray()Returns  trueif this object represents an array type. | 
| boolean | isEnum()Determines whether this object represents an enum. | 
| boolean | isFrozen()Returns true if the class has been loaded or written out
 and thus it cannot be modified any more. | 
| boolean | isInterface()Determines whether this object represents a class or an interface. | 
| boolean | isModified()Returns true if the definition of the class has been modified. | 
| boolean | isPrimitive()Returns  trueif this object represents a primitive
 Java type: boolean, byte, char, short, int, long, float, double,
 or void. | 
| static void | main(String[] args)Prints the version number and the copyright notice. | 
| CtConstructor | makeClassInitializer()Makes an empty class initializer (static constructor). | 
| protected DataOutputStream | makeFileOutput(String directoryName) | 
| CtClass | makeNestedClass(String name,
               boolean isStatic)Makes a new public nested class. | 
| String | makeUniqueName(String prefix)Makes a unique member name. | 
| void | prune()Discards unnecessary attributes, in particular,
  CodeAttributes (method bodies) of the class,
 to minimize the memory footprint. | 
| void | rebuildClassFile()If this method is called, the class file will be
 rebuilt when it is finally generated by
  toBytecode()andwriteFile(). | 
| void | removeConstructor(CtConstructor c)Removes a constructor declared in this class. | 
| void | removeField(CtField f)Removes a field declared in this class. | 
| void | removeMethod(CtMethod m)Removes a method declared in this class. | 
| void | replaceClassName(ClassMap map)Changes class names appearing in the class file according to the
 given  map. | 
| void | replaceClassName(String oldName,
                String newName)Substitutes  newNamefor all occurrences of a class
 nameoldNamein the class file. | 
| void | setAttribute(String name,
            byte[] data)Adds a named attribute. | 
| void | setGenericSignature(String sig)Sets the generic signature of the class. | 
| void | setInterfaces(CtClass[] list)Sets implemented interfaces. | 
| void | setModifiers(int mod)Sets the modifiers. | 
| void | setName(String name)Sets the class name | 
| void | setSuperclass(CtClass clazz)Changes a super class unless this object represents an interface. | 
| boolean | stopPruning(boolean stop)Disallows (or allows) automatically pruning this  CtClassobject. | 
| boolean | subclassOf(CtClass superclass)Determines whether the class directly or indirectly extends
 the given class. | 
| boolean | subtypeOf(CtClass clazz)Returns  trueif this class extends or implementsclazz. | 
| byte[] | toBytecode()Converts this class to a class file. | 
| void | toBytecode(DataOutputStream out)Converts this class to a class file. | 
| Class | toClass()Converts this class to a  java.lang.Classobject. | 
| Class | toClass(ClassLoader loader)Deprecated. 
 Replaced by  toClass(ClassLoader,ProtectionDomain) | 
| Class | toClass(ClassLoader loader,
       ProtectionDomain domain)Converts this class to a  java.lang.Classobject. | 
| String | toString()Converts the object to a string. | 
| void | writeFile()Writes a class file represented by this  CtClassobject in the current directory. | 
| void | writeFile(String directoryName)Writes a class file represented by this  CtClassobject on a local disk. | 
protected String qualifiedName
public static String debugDump
"./debug", then all class files are saved
 there.  The directory name must not end with a directory
 separator such as /.
 The default value is null.
debugWriteFile(String)public static final String version
public static CtClass booleanType
CtClass object representing
 the boolean type.public static CtClass charType
CtClass object representing
 the char type.public static CtClass byteType
CtClass object representing
 the byte type.public static CtClass shortType
CtClass object representing
 the short type.public static CtClass intType
CtClass object representing
 the int type.public static CtClass longType
CtClass object representing
 the long type.public static CtClass floatType
CtClass object representing
 the float type.public static CtClass doubleType
CtClass object representing
 the double type.public static CtClass voidType
CtClass object representing
 the void type.protected CtClass(String name)
public static void main(String[] args)
The following command invokes this method:
java -jar javassist.jar
public String toString()
protected void extendToString(StringBuffer buffer)
toString() result.
 Subclasses should put a space before each token added to the buffer.public ClassPool getClassPool()
ClassPool for this class.public ClassFile getClassFile()
This method is not available if isFrozen()
 is true.
public ClassFile getClassFile2()
getClassFile().
 The ClassFile object obtained by this method
 is read only.  Changes to this object might not be reflected
 on a class file generated by toBytecode(),
 toClass(), etc.
 
This method is available even if isFrozen()
 is true.  However, if the class is frozen, it might be also
 pruned.
getClassFile(), 
isFrozen(), 
prune()public AccessorMaker getAccessorMaker()
public URL getURL() throws NotFoundException
NotFoundExceptionpublic boolean isModified()
public boolean isFrozen()
public void freeze()
isFrozen(), 
defrost()public void defrost()
To avoid changes that will be never reflected, the class is frozen to be unmodifiable if it is loaded or written out. This method should be called only in a case that the class will be reloaded or written out later again.
If defrost() will be called later, pruning
 must be disallowed in advance.
isFrozen(), 
stopPruning(boolean), 
detach()public boolean isPrimitive()
true if this object represents a primitive
 Java type: boolean, byte, char, short, int, long, float, double,
 or void.public boolean isArray()
true if this object represents an array type.public CtClass getComponentType() throws NotFoundException
null.NotFoundExceptionpublic boolean subtypeOf(CtClass clazz) throws NotFoundException
true if this class extends or implements
 clazz.  It also returns true if
 this class is the same as clazz.NotFoundExceptionpublic String getName()
public final String getSimpleName()
public final String getPackageName()
null.public void setName(String name)
name - fully-qualified namepublic String getGenericSignature()
The generics of Java is implemented by the erasure technique. After compilation, all type parameters are dropped off from the main part of a class file. However, for reflection, the type parameters are encoded into generic signatures and attached to a class file.
SignatureAttribute.toClassSignature(String), 
CtMember.getGenericSignature()public void setGenericSignature(String sig)
The generics of Java is implemented by the erasure technique. After compilation, all type parameters are dropped off from the main part of a class file. However, for reflection, the type parameters must be encoded into generic signatures and attached to a class file.
For example,
class List<T> {
     T value;
     T get() { return value; }
     void set(T v) { value = v; }
 }
 
 this class is generated by the following code:
 ClassPool pool = ClassPool.getDefault();
 CtClass cc = pool.makeClass("List");
 CtClass objectClass = pool.get(CtClass.javaLangObject);
 ClassSignature cs = new ClassSignature(
                         new TypeParameter[] { new TypeParameter("T") });
 cc.setGenericSignature(cs.encode());    // <T:Ljava/lang/Object;>Ljava/lang/Object;
 CtField f = new CtField(objClass, "value", cc);
 TypeVariable tvar = new TypeVariable("T");
 f.setGenericSignature(tvar.encode());   // TT;
 cc.addField(f);
 CtMethod m = CtNewMethod.make("public Object get(){return value;}", cc);
 MethodSignature ms = new MethodSignature(null, null, tvar, null);
 m.setGenericSignature(ms.encode());     // ()TT;
 cc.addMethod(m);
 CtMethod m2 = CtNewMethod.make("public void set(Object v){value = v;}", cc);
 MethodSignature ms2 = new MethodSignature(null, new Type[] { tvar },
                                           new BaseType("void"), null);
 m2.setGenericSignature(ms2.encode());   // (TT;)V;
 cc.addMethod(m2);
 cc.writeFile();
 
 The generated class file is equivalent to the following:
class List {
     Object value;
     Object get() { return value; }
     void set(Object v) { value = v; }
 }
 but it includes generic signatures for the class, the field,
 and the methods so that the type variable T can be
 accessible through reflection.
 
MethodSignature is a utility class.  You can directly
 pass the signature string to the setGenericSignature method.
 For the specification of the signatures, see Section 4.7.9.1 Signatures
 of The Java Virtual Machine Specification (Java SE 8).
sig - a generic signature.SignatureAttribute.ClassSignature.encode(), 
SignatureAttribute.MethodSignature.encode(), 
CtMember.setGenericSignature(String)public void replaceClassName(String oldName, String newName)
newName for all occurrences of a class
 name oldName in the class file.oldName - replaced class namenewName - substituted class namepublic void replaceClassName(ClassMap map)
map.
 All the class names appearing in the class file are tested
 with map to determine whether each class name is
 replaced or not.  Thus this method can be used for collecting
 all the class names in the class file.  To do that, first define
 a subclass of ClassMap so that get()
 records all the given parameters.  Then, make an instance of
 that subclass as an empty hash-table.  Finally, pass that instance
 to this method.  After this method finishes, that instance would
 contain all the class names appearing in the class file.
map - the hashtable associating replaced class names
                  with substituted names.public Collection getRefClasses()
This method may return null.
Collection<String> object.public boolean isInterface()
true if this object represents an interface.public boolean isAnnotation()
true if this object represents an annotation type.public boolean isEnum()
true if this object represents an enum.public int getModifiers()
javassist.Modifier.
 If the class is a static nested class (a.k.a. static inner class),
 the returned modifiers include Modifier.STATIC.
Modifierpublic boolean hasAnnotation(Class annotationType)
annotationType - the annotation type.true if the annotation is found, otherwise false.public boolean hasAnnotation(String annotationTypeName)
annotationTypeName - the name of annotation type.true if the annotation is found, otherwise false.public Object getAnnotation(Class clz) throws ClassNotFoundException
@Author is associated
 with this class, an Author object is returned.
 The member values can be obtained by calling methods on
 the Author object.clz - the annotation type.null.ClassNotFoundExceptionpublic Object[] getAnnotations() throws ClassNotFoundException
@Author is associated
 with this class, the returned array contains an Author
 object.  The member values can be obtained by calling methods on
 the Author object.ClassNotFoundExceptionCtMember.getAnnotations()public Object[] getAvailableAnnotations()
getAnnotations()
 except that, if any annotations are not on the classpath,
 they are not included in the returned array.getAnnotations(), 
CtMember.getAvailableAnnotations()public CtClass[] getDeclaredClasses() throws NotFoundException
getNestedClasses().NotFoundExceptiongetNestedClasses()public CtClass[] getNestedClasses() throws NotFoundException
NotFoundExceptionpublic void setModifiers(int mod)
If the class is a nested class, this method also modifies the class declaring that nested class (i.e. the enclosing class is modified).
mod - modifiers encoded by
                  javassist.ModifierModifierpublic boolean subclassOf(CtClass superclass)
This method returns true if the given class is identical to the class represented by this object.
public CtClass getSuperclass() throws NotFoundException
java.lang.Object class and thus it does not have
 the super class.
 If this object represents an interface, this method
 always returns the java.lang.Object class.
 To obtain the super interfaces
 extended by that interface, call getInterfaces().
NotFoundExceptionpublic void setSuperclass(CtClass clazz) throws CannotCompileException
If this object represents an interface, this method is equivalent
 to addInterface(); it appends clazz to
 the list of the super interfaces extended by that interface.
 Note that an interface can extend multiple super interfaces.
CannotCompileExceptionreplaceClassName(String, String), 
replaceClassName(ClassMap)public CtClass[] getInterfaces() throws NotFoundException
NotFoundExceptionpublic void setInterfaces(CtClass[] list)
list - a list of the CtClass objects
                          representing interfaces, or
                          null if the class implements
                          no interfaces.public void addInterface(CtClass anInterface)
anInterface - the added interface.public CtClass getDeclaringClass() throws NotFoundException
NotFoundExceptionpublic final CtMethod getEnclosingMethod() throws NotFoundException
getEnclosingBehavior().NotFoundExceptiongetEnclosingBehavior()public CtBehavior getEnclosingBehavior() throws NotFoundException
NotFoundExceptionpublic CtClass makeNestedClass(String name, boolean isStatic)
CtClass, which encloses the nested class, is modified
 since a class file includes a list of nested classes.  
 The current implementation only supports a static nested class.
 isStatic must be true.
name - the simple name of the nested class.isStatic - true if the nested class is static.public CtField[] getFields()
CtField objects
 representing all the non-private fields of the class.
 That array includes non-private fields inherited from the
 superclasses.public CtField getField(String name) throws NotFoundException
NotFoundExceptionpublic CtField getField(String name, String desc) throws NotFoundException
name - the field name.desc - the type descriptor of the field.  It is available by
                  CtField.getSignature().NotFoundExceptionCtField.getSignature()public CtField[] getDeclaredFields()
Note: the result does not include inherited fields.
public CtField getDeclaredField(String name) throws NotFoundException
Note: this method does not search the super classes.
NotFoundExceptionpublic CtField getDeclaredField(String name, String desc) throws NotFoundException
Note: this method does not search the super classes.
name - the field name.desc - the type descriptor of the field.  It is available by
                  CtField.getSignature().NotFoundExceptionCtField.getSignature()public CtBehavior[] getDeclaredBehaviors()
public CtConstructor[] getConstructors()
CtConstructor objects
 representing all the non-private constructors of the class.public CtConstructor getConstructor(String desc) throws NotFoundException
javassist.bytecode.Descriptor.desc - method descriptorNotFoundExceptionDescriptorpublic CtConstructor[] getDeclaredConstructors()
CtConstructorpublic CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException
params - parameter types.NotFoundExceptionpublic CtConstructor getClassInitializer()
null if
 no class initializer is not declared.makeClassInitializer(), 
CtConstructorpublic CtMethod[] getMethods()
CtMethod objects
 representing all the non-private methods of the class.
 That array includes non-private methods inherited from the
 superclasses.public CtMethod getMethod(String name, String desc) throws NotFoundException
name - method namedesc - method descriptorNotFoundExceptionCtBehavior.getSignature(), 
Descriptorpublic CtMethod[] getDeclaredMethods()
CtMethodpublic CtMethod getDeclaredMethod(String name, CtClass[] params) throws NotFoundException
Note: this method does not search the superclasses.
name - method nameparams - parameter typesNotFoundExceptionCtMethodpublic CtMethod[] getDeclaredMethods(String name) throws NotFoundException
Note: this method does not search the superclasses.
name - method name.NotFoundExceptionpublic CtMethod getDeclaredMethod(String name) throws NotFoundException
Note: this method does not search the superclasses.
NotFoundExceptionCtMethodpublic CtConstructor makeClassInitializer() throws CannotCompileException
CannotCompileExceptiongetClassInitializer()public void addConstructor(CtConstructor c) throws CannotCompileException
makeClassInitializer().CannotCompileExceptionmakeClassInitializer()public void removeConstructor(CtConstructor c) throws NotFoundException
c - removed constructor.NotFoundException - if the constructor is not found.public void addMethod(CtMethod m) throws CannotCompileException
CannotCompileExceptionpublic void removeMethod(CtMethod m) throws NotFoundException
m - removed method.NotFoundException - if the method is not found.public void addField(CtField f) throws CannotCompileException
The CtField belonging to another
 CtClass cannot be directly added to this class.
 Only a field created for this class can be added.
CannotCompileExceptionCtField.CtField(CtField,CtClass)public void addField(CtField f, String init) throws CannotCompileException
The CtField belonging to another
 CtClass cannot be directly added to this class.
 Only a field created for this class can be added.
 
The initial value is given as an expression written in Java. Any regular Java expression can be used for specifying the initial value. The followings are examples.
cc.addField(f, "0") // the initial value is 0. cc.addField(f, "i + 1") // i + 1. cc.addField(f, "new Point()"); // a Point object.
Here, the type of variable cc is CtClass.
 The type of f is CtField.
 
Note: do not change the modifier of the field
 (in particular, do not add or remove static
 to/from the modifier)
 after it is added to the class by addField().
init - an expression for the initial value.CannotCompileExceptionCtField.Initializer.byExpr(String), 
CtField.CtField(CtField,CtClass)public void addField(CtField f, CtField.Initializer init) throws CannotCompileException
The CtField belonging to another
 CtClass cannot be directly added to this class.
 Only a field created for this class can be added.
 
For example,
 CtClass cc = ...;
 addField(new CtField(CtClass.intType, "i", cc),
          CtField.Initializer.constant(1));
 
 This code adds an int field named "i".  The
 initial value of this field is 1.
init - specifies the initial value of the field.CannotCompileExceptionCtField.CtField(CtField,CtClass)public void removeField(CtField f) throws NotFoundException
f - removed field.NotFoundException - if the field is not found.public byte[] getAttribute(String name)
This is a convenient method mainly for obtaining
 a user-defined attribute.  For dealing with attributes, see the
 javassist.bytecode package.  For example, the following
 expression returns all the attributes of a class file.
 
getClassFile().getAttributes()
name - attribute nameAttributeInfopublic void setAttribute(String name, byte[] data)
This is a convenient method mainly for adding
 a user-defined attribute.  For dealing with attributes, see the
 javassist.bytecode package.  For example, the following
 expression adds an attribute info to a class file.
 
getClassFile().addAttribute(info)
name - attribute namedata - attribute valueAttributeInfopublic void instrument(CodeConverter converter) throws CannotCompileException
instrument()
 on every CtMethod and CtConstructor object
 in the class.converter - specifies how to modify.CannotCompileExceptionpublic void instrument(ExprEditor editor) throws CannotCompileException
instrument()
 on every CtMethod and CtConstructor object
 in the class.editor - specifies how to modify.CannotCompileExceptionpublic Class toClass() throws CannotCompileException
java.lang.Class object.
 Once this method is called, further modifications are not
 allowed any more.
 To load the class, this method uses the context class loader
 of the current thread.  If the program is running on some application
 server, the context class loader might be inappropriate to load the
 class.
 This method is provided for convenience. If you need more complex functionality, you should write your own class loader.
Note: this method calls toClass()
 in ClassPool.
 
Warining: A Class object returned by this method may not work with a security manager or a signed jar file because a protection domain is not specified.
public Class toClass(ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
java.lang.Class object.
 Once this method is called, further modifications are not allowed
 any more.
 The class file represented by this CtClass is
 loaded by the given class loader to construct a
 java.lang.Class object.  Since a private method
 on the class loader is invoked through the reflection API,
 the caller must have permissions to do that.
 
An easy way to obtain ProtectionDomain object is
 to call getProtectionDomain()
 in java.lang.Class.  It returns the domain that
 the class belongs to.
 
This method is provided for convenience. If you need more complex functionality, you should write your own class loader.
Note: this method calls toClass()
 in ClassPool.
loader - the class loader used to load this class.
                      If it is null, the class loader returned by
                      ClassPool.getClassLoader() is used.domain - the protection domain that the class belongs to.
                      If it is null, the default domain created
                      by java.lang.ClassLoader is used.CannotCompileExceptionClassPool.toClass(CtClass,java.lang.ClassLoader)public final Class toClass(ClassLoader loader) throws CannotCompileException
toClass(ClassLoader,ProtectionDomain)java.lang.Class object.
 Warining: A Class object returned by this method may not work with a security manager or a signed jar file because a protection domain is not specified.
CannotCompileExceptionpublic void detach()
CtClass object from the
 ClassPool.
 After this method is called, any method cannot be called on the
 removed CtClass object.
 If get() in ClassPool is called
 with the name of the removed method,
 the ClassPool will read the class file again
 and constructs another CtClass object representing
 the same class.
public boolean stopPruning(boolean stop)
CtClass
 object.
 
 Javassist can automatically prune a CtClass object
 when toBytecode() (or toClass(),
 writeFile()) is called.
 Since a ClassPool holds all instances of CtClass
 even after toBytecode() (or toClass(),
 writeFile()) is called, pruning may significantly
 save memory consumption.
 
If ClassPool.doPruning is true, the automatic pruning
 is on by default.  Otherwise, it is off.  The default value of
 ClassPool.doPruning is false.
stop - disallow pruning if true.  Otherwise, allow.detach(), 
prune(), 
ClassPool.doPruningpublic void prune()
CodeAttributes (method bodies) of the class,
 to minimize the memory footprint.
 After calling this method, the class is read only.
 It cannot be modified any more.
 Furthermore, toBytecode(),
 writeFile(), toClass(),
 or instrument() cannot be called.
 However, the method names and signatures in the class etc.
 are still accessible.
 toBytecode(), writeFile(), and
 toClass() internally call this method if
 automatic pruning is on. 
 
According to some experiments, pruning does not really reduce memory consumption. Only about 20%. Since pruning takes time, it might not pay off. So the automatic pruning is off by default.
public void rebuildClassFile()
toBytecode() and writeFile().
 For a performance reason, the symbol table of the
 class file may contain unused entries, for example,
 after a method or a filed is deleted.
 This method
 removes those unused entries.  This removal will
 minimize the size of the class file.public byte[] toBytecode()
                  throws IOException,
                         CannotCompileException
IOExceptionCannotCompileExceptionpublic void writeFile()
               throws NotFoundException,
                      IOException,
                      CannotCompileException
CtClass
 object in the current directory.
 Once this method is called, further modifications are not
 possible any more.NotFoundExceptionIOExceptionCannotCompileExceptiondebugWriteFile()public void writeFile(String directoryName) throws CannotCompileException, IOException
CtClass
 object on a local disk.
 Once this method is called, further modifications are not
 possible any more.directoryName - it must end without a directory separator.CannotCompileExceptionIOExceptiondebugWriteFile(String)protected DataOutputStream makeFileOutput(String directoryName)
public void debugWriteFile()
writeFile() does although this
 method does not prune or freeze the class after writing the class
 file.  Note that, once writeFile() or toBytecode()
 is called, it cannot be called again since the class is pruned and frozen.
 This method would be useful for debugging.public void debugWriteFile(String directoryName)
writeFile() does although this
 method does not prune or freeze the class after writing the class
 file.  Note that, once writeFile() or toBytecode()
 is called, it cannot be called again since the class is pruned and frozen.
 This method would be useful for debugging.directoryName - it must end without a directory separator.public void toBytecode(DataOutputStream out) throws CannotCompileException, IOException
This method dose not close the output stream in the end.
out - the output stream that a class file is written to.CannotCompileExceptionIOExceptionpublic String makeUniqueName(String prefix)
prefix - the prefix of the member name.Copyright © 2016 Shigeru Chiba, www.javassist.org. All Rights Reserved.