| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectclassUtils.javassist.CompileTimeClass
public abstract class CompileTimeClass
An instance of CtClass represents a class.
 It is obtained from ClassPool.
ClassPool.get(String)| Field Summary | |
|---|---|
| static CompileTimeClass | booleanTypeThe CtClassobject representing
 thebooleantype. | 
| static CompileTimeClass | byteTypeThe CtClassobject representing
 thebytetype. | 
| static CompileTimeClass | charTypeThe CtClassobject representing
 thechartype. | 
| static CompileTimeClass | doubleTypeThe CtClassobject representing
 thedoubletype. | 
| static CompileTimeClass | floatTypeThe CtClassobject representing
 thefloattype. | 
| static CompileTimeClass | intTypeThe CtClassobject representing
 theinttype. | 
| static CompileTimeClass | longTypeThe CtClassobject representing
 thelongtype. | 
| static CompileTimeClass | shortTypeThe CtClassobject representing
 theshorttype. | 
| static java.lang.String | versionThe version number of this release. | 
| static CompileTimeClass | voidTypeThe CtClassobject representing
 thevoidtype. | 
| Method Summary | |
|---|---|
|  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,
         java.lang.String init)Adds a field with an initial value. | 
|  void | addInterface(CompileTimeClass anInterface)Adds an interface. | 
|  void | addMethod(CtMethod m)Adds a method. | 
|  void | defrost()Defrosts the class so that the class can be modified again. | 
|  byte[] | getAttribute(java.lang.String name)Obtains an attribute with the given name. | 
|  JAClassFile | getClassFile()Returns a class file for this class. | 
|  JAClassFile | getClassFile2()Undocumented method. | 
|  CtConstructor | getClassInitializer()Gets the class initializer (static constructor) declared in the class. | 
|  ClassPool | getClassPool()Returns a ClassPoolfor this class. | 
|  CompileTimeClass | getComponentType()If this object represents an array, this method returns the component type of the array. | 
|  CtConstructor | getConstructor(java.lang.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 public constructors of the class. | 
|  CtBehavior[] | getDeclaredBehaviors()Gets all the constructors and methods declared in the class. | 
|  CtConstructor | getDeclaredConstructor(CompileTimeClass[] params)Returns a constructor receiving the specified parameters. | 
|  CtConstructor[] | getDeclaredConstructors()Gets all the constructors declared in the class. | 
|  CtField | getDeclaredField(java.lang.String name)Retrieves the field with the specified name among the fields declared in the class. | 
|  CtField[] | getDeclaredFields()Gets all the fields declared in the class. | 
|  CtMethod | getDeclaredMethod(java.lang.String name)Retrieves the method with the specified name among the methods declared in the class. | 
|  CtMethod | getDeclaredMethod(java.lang.String name,
                  CompileTimeClass[] 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. | 
|  CtField | getField(java.lang.String name)Returns the field with the specified name. | 
|  CtField[] | getFields()Returns an array containing CtFieldobjects
 representing all the public fields of the class. | 
|  CompileTimeClass[] | getInterfaces()Obtains the class objects representing the interfaces of the class. | 
|  CtMethod | getMethod(java.lang.String name,
          java.lang.String desc)Returns the method with the given name and signature. | 
|  CtMethod[] | getMethods()Returns an array containing CtMethodobjects
 representing all the public methods of the class. | 
|  int | getModifiers()Returns the modifiers for this class, encoded in an integer. | 
|  java.lang.String | getName()Obtains the fully-qualified name of the class. | 
|  java.lang.String | getPackageName()Obtains the package name. | 
|  java.util.Collection | getRefClasses()Returns a collection of the names of all the classes referenced in this class. | 
|  java.lang.String | getSimpleName()Obtains the not-qualified class name. | 
|  CompileTimeClass | getSuperclass()Obtains the class object representing the superclass of the class. | 
|  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 | isArray()Returns trueif this object represents an array type. | 
|  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. | 
|  CtConstructor | makeClassInitializer()Makes a class initializer (static constructor). | 
|  void | replaceClassName(ClassMap map)Changes class names appearing in the class file according to the given map. | 
|  void | replaceClassName(java.lang.String oldname,
                 java.lang.String newname)Substitutes newNamefor all occurrences of a class
 nameoldNamein the class file. | 
|  void | setAttribute(java.lang.String name,
             byte[] data)Adds a named attribute. | 
|  void | setInterfaces(CompileTimeClass[] list)Sets interfaces. | 
|  void | setModifiers(int mod)Sets the modifiers. | 
|  void | setName(java.lang.String name)Sets the class name | 
|  void | setSuperclass(CompileTimeClass clazz)Changes a super class. | 
|  boolean | subclassOf(CompileTimeClass superclass)Determines whether the class directly or indirectly extends the given class. | 
|  boolean | subtypeOf(CompileTimeClass clazz)Returns trueif this class extends or implementsclazz. | 
|  byte[] | toBytecode()Converts this class to a class file. | 
|  java.lang.Class | toClass()Converts this class to a java.lang.Classobject. | 
|  void | writeFile()Writes a class file represented by this CtClassobject in the current directory. | 
| Methods inherited from class java.lang.Object | 
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static final java.lang.String version
public static CompileTimeClass booleanType
CtClass object representing
 the boolean type.
public static CompileTimeClass charType
CtClass object representing
 the char type.
public static CompileTimeClass byteType
CtClass object representing
 the byte type.
public static CompileTimeClass shortType
CtClass object representing
 the short type.
public static CompileTimeClass intType
CtClass object representing
 the int type.
public static CompileTimeClass longType
CtClass object representing
 the long type.
public static CompileTimeClass floatType
CtClass object representing
 the float type.
public static CompileTimeClass doubleType
CtClass object representing
 the double type.
public static CompileTimeClass voidType
CtClass object representing
 the void type.
| Method Detail | 
|---|
public ClassPool getClassPool()
ClassPool for this class.
public JAClassFile getClassFile()
This method is not available if isFrozen()
 is true.
public JAClassFile getClassFile2()
public boolean isModified()
public boolean isFrozen()
defrost()public void defrost()
isFrozen()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 CompileTimeClass getComponentType()
                                  throws NotFoundException
null.
NotFoundException
public boolean subtypeOf(CompileTimeClass clazz)
                  throws NotFoundException
true if this class extends or implements
 clazz.  It also returns true if
 this class is the same as clazz.
NotFoundExceptionpublic java.lang.String getName()
public final java.lang.String getSimpleName()
public final java.lang.String getPackageName()
null.
public void setName(java.lang.String name)
name - fully-qualified name
public void replaceClassName(java.lang.String oldname,
                             java.lang.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 java.util.Collection getRefClasses()
This method may return null.
public boolean isInterface()
true if this object represents an interface.
public int getModifiers()
javassist.Modifier.
Modifierpublic void setModifiers(int mod)
mod - modifiers encoded by
                  javassist.ModifierModifierpublic boolean subclassOf(CompileTimeClass superclass)
This method returns true if the given class is identical to the class represented by this object.
public CompileTimeClass getSuperclass()
                               throws NotFoundException
java.lang.Object class and thus it does not have
 the super class.
NotFoundException
public void setSuperclass(CompileTimeClass clazz)
                   throws CannotCompileException
CannotCompileException
public CompileTimeClass[] getInterfaces()
                                 throws NotFoundException
NotFoundExceptionpublic void setInterfaces(CompileTimeClass[] list)
list - a list of the CtClass objects
                          representing interfaces, or
                          null if the class implements
                          no interfaces.public void addInterface(CompileTimeClass anInterface)
anInterface - the added interface.public CtField[] getFields()
CtField objects
 representing all the public fields of the class.
 That array includes public fields inherited from the
 superclasses.
public CtField getField(java.lang.String name)
                 throws NotFoundException
NotFoundExceptionpublic CtField[] getDeclaredFields()
Note: the result does not include inherited fields.
public CtField getDeclaredField(java.lang.String name)
                         throws NotFoundException
Note: this method does not search the superclasses.
NotFoundExceptionpublic CtBehavior[] getDeclaredBehaviors()
public CtConstructor[] getConstructors()
CtConstructor objects
 representing all the public constructors of the class.
public CtConstructor getConstructor(java.lang.String desc)
                             throws NotFoundException
javassist.bytecode.Descriptor.
desc - method descriptor
NotFoundExceptionDescriptorpublic CtConstructor[] getDeclaredConstructors()
CtConstructor
public CtConstructor getDeclaredConstructor(CompileTimeClass[] 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 public methods of the class.
 That array includes public methods inherited from the
 superclasses.
public CtMethod getMethod(java.lang.String name,
                          java.lang.String desc)
                   throws NotFoundException
name - method namedesc - method descriptor
NotFoundExceptionDescriptorpublic CtMethod[] getDeclaredMethods()
CtMethod
public CtMethod getDeclaredMethod(java.lang.String name,
                                  CompileTimeClass[] params)
                           throws NotFoundException
Note: this method does not search the superclasses.
name - method nameparams - parameter types
NotFoundExceptionCtMethod
public CtMethod getDeclaredMethod(java.lang.String name)
                           throws NotFoundException
Note: this method does not search the superclasses.
NotFoundExceptionCtMethod
public CtConstructor makeClassInitializer()
                                   throws CannotCompileException
CannotCompileExceptiongetClassInitializer()
public void addConstructor(CtConstructor c)
                    throws CannotCompileException
CannotCompileException
public void addMethod(CtMethod m)
               throws CannotCompileException
CannotCompileException
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,CompileTimeClass)
public void addField(CtField f,
                     java.lang.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.
init - an expression for the initial value.
CannotCompileExceptionCtField.Initializer.byExpr(String), 
CtField.CtField(CtField,CompileTimeClass)
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,CompileTimeClass)public byte[] getAttribute(java.lang.String name)
name - attribute name
public void setAttribute(java.lang.String name,
                         byte[] data)
name - attribute namedata - attribute value
public void instrument(CodeConverter converter)
                throws CannotCompileException
instrument()
 on every CtMethod and CtConstructor object
 in the class.
converter - specifies how to modify.
CannotCompileException
public void instrument(ExprEditor editor)
                throws CannotCompileException
instrument()
 on every CtMethod and CtConstructor object
 in the class.
editor - specifies how to modify.
CannotCompileException
public java.lang.Class toClass()
                        throws NotFoundException,
                               java.io.IOException,
                               CannotCompileException
java.lang.Class object.
 Once this method is called, further modifications are not
 possible any more.
 This method is equivalent to:
this.getClassPool().writeAsClass(this.getName())
See the description of ClassPool.writeAsClass()
 before you use this method.
 This method is provided for convenience.  If you need more
 complex functionality, you should write your own class loader.
NotFoundException
java.io.IOException
CannotCompileExceptionClassPool.writeAsClass(String), 
ClassPool.forName(String)
public byte[] toBytecode()
                  throws NotFoundException,
                         java.io.IOException,
                         CannotCompileException
This method is equivalent to:
this.getClassPool().write(this.getName())
NotFoundException
java.io.IOException
CannotCompileExceptionClassPool.write(String)
public void writeFile()
               throws NotFoundException,
                      java.io.IOException,
                      CannotCompileException
CtClass
 object in the current directory.
 Once this method is called, further modifications are not
 possible any more.
 This method is equivalent to:
this.getClassPool().writeFile(this.getName())
NotFoundException
java.io.IOException
CannotCompileExceptionClassPool.writeFile(String)| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||