classUtils.javassist
Class CompileTimeClassType

java.lang.Object
  extended by classUtils.javassist.CompileTimeClass
      extended by classUtils.javassist.CompileTimeClassType
Direct Known Subclasses:
CompileTimeNewClass

public class CompileTimeClassType
extends CompileTimeClass

Class types.


Field Summary
 
Fields inherited from class classUtils.javassist.CompileTimeClass
booleanType, byteType, charType, doubleType, floatType, intType, longType, shortType, version, voidType
 
Method Summary
 void addConstructor(CtConstructor c)
          Adds a constructor.
 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 getClassFile2()
          Undocumented method.
 CtConstructor getClassInitializer()
          Gets the class initializer (static constructor) declared in the class.
 ClassPool getClassPool()
          Returns a ClassPool for this class.
 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 CtConstructor objects representing all the public constructors of the class.
 CtBehavior[] getDeclaredBehaviors()
          Gets all the constructors and methods declared in the class.
 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 CtField objects 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 CtMethod objects representing all the public methods of the class.
 int getModifiers()
          Returns the modifiers for this class, encoded in an integer.
 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 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.
 CtConstructor makeClassInitializer()
          Makes a class initializer (static constructor).
 void replaceClassName(ClassMap classnames)
          Changes class names appearing in the class file according to the given map.
 void replaceClassName(java.lang.String oldname, java.lang.String newname)
          Substitutes newName for all occurrences of a class name oldName in 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 true if this class extends or implements clazz.
 
Methods inherited from class classUtils.javassist.CompileTimeClass
addField, getClassFile, getComponentType, getDeclaredConstructor, getName, getPackageName, getRefClasses, getSimpleName, isArray, isPrimitive, toBytecode, toClass, writeFile
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getClassFile2

public JAClassFile getClassFile2()
Description copied from class: CompileTimeClass
Undocumented method. Do not use; internal-use only.

Overrides:
getClassFile2 in class CompileTimeClass

getClassPool

public ClassPool getClassPool()
Description copied from class: CompileTimeClass
Returns a ClassPool for this class.

Overrides:
getClassPool in class CompileTimeClass

isModified

public boolean isModified()
Description copied from class: CompileTimeClass
Returns true if the definition of the class has been modified.

Overrides:
isModified in class CompileTimeClass

isFrozen

public boolean isFrozen()
Description copied from class: CompileTimeClass
Returns true if the class has been loaded or written out and thus it cannot be modified any more.

Overrides:
isFrozen in class CompileTimeClass
See Also:
CompileTimeClass.defrost()

defrost

public void defrost()
Description copied from class: CompileTimeClass
Defrosts the class so that the class can be modified again. 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.

Overrides:
defrost in class CompileTimeClass
See Also:
CompileTimeClass.isFrozen()

subtypeOf

public boolean subtypeOf(CompileTimeClass clazz)
                  throws NotFoundException
Description copied from class: CompileTimeClass
Returns true if this class extends or implements clazz. It also returns true if this class is the same as clazz.

Overrides:
subtypeOf in class CompileTimeClass
Throws:
NotFoundException

setName

public void setName(java.lang.String name)
             throws java.lang.RuntimeException
Description copied from class: CompileTimeClass
Sets the class name

Overrides:
setName in class CompileTimeClass
Parameters:
name - fully-qualified name
Throws:
java.lang.RuntimeException

replaceClassName

public void replaceClassName(ClassMap classnames)
                      throws java.lang.RuntimeException
Description copied from class: CompileTimeClass
Changes class names appearing in the class file according to the given 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.

Overrides:
replaceClassName in class CompileTimeClass
Parameters:
classnames - the hashtable associating replaced class names with substituted names.
Throws:
java.lang.RuntimeException

replaceClassName

public void replaceClassName(java.lang.String oldname,
                             java.lang.String newname)
                      throws java.lang.RuntimeException
Description copied from class: CompileTimeClass
Substitutes newName for all occurrences of a class name oldName in the class file.

Overrides:
replaceClassName in class CompileTimeClass
Parameters:
oldname - replaced class name
newname - substituted class name
Throws:
java.lang.RuntimeException

isInterface

public boolean isInterface()
Description copied from class: CompileTimeClass
Determines whether this object represents a class or an interface. It returns true if this object represents an interface.

Overrides:
isInterface in class CompileTimeClass

getModifiers

public int getModifiers()
Description copied from class: CompileTimeClass
Returns the modifiers for this class, encoded in an integer. For decoding, use javassist.Modifier.

Overrides:
getModifiers in class CompileTimeClass
See Also:
Modifier

setModifiers

public void setModifiers(int mod)
Description copied from class: CompileTimeClass
Sets the modifiers.

Overrides:
setModifiers in class CompileTimeClass
Parameters:
mod - modifiers encoded by javassist.Modifier
See Also:
Modifier

subclassOf

public boolean subclassOf(CompileTimeClass superclass)
Description copied from class: CompileTimeClass
Determines whether the class directly or indirectly extends the given class. If this class extends a class A and the class A extends a class B, then subclassof(B) returns true.

This method returns true if the given class is identical to the class represented by this object.

Overrides:
subclassOf in class CompileTimeClass

getSuperclass

public CompileTimeClass getSuperclass()
                               throws NotFoundException
Description copied from class: CompileTimeClass
Obtains the class object representing the superclass of the class. It returns null if this object represents the java.lang.Object class and thus it does not have the super class.

Overrides:
getSuperclass in class CompileTimeClass
Throws:
NotFoundException

setSuperclass

public void setSuperclass(CompileTimeClass clazz)
                   throws CannotCompileException
Description copied from class: CompileTimeClass
Changes a super class. The new super class must be compatible with the old one.

Overrides:
setSuperclass in class CompileTimeClass
Throws:
CannotCompileException

getInterfaces

public CompileTimeClass[] getInterfaces()
                                 throws NotFoundException
Description copied from class: CompileTimeClass
Obtains the class objects representing the interfaces of the class.

Overrides:
getInterfaces in class CompileTimeClass
Throws:
NotFoundException

setInterfaces

public void setInterfaces(CompileTimeClass[] list)
Description copied from class: CompileTimeClass
Sets interfaces.

Overrides:
setInterfaces in class CompileTimeClass
Parameters:
list - a list of the CtClass objects representing interfaces, or null if the class implements no interfaces.

addInterface

public void addInterface(CompileTimeClass anInterface)
Description copied from class: CompileTimeClass
Adds an interface.

Overrides:
addInterface in class CompileTimeClass
Parameters:
anInterface - the added interface.

getFields

public CtField[] getFields()
Description copied from class: CompileTimeClass
Returns an array containing CtField objects representing all the public fields of the class. That array includes public fields inherited from the superclasses.

Overrides:
getFields in class CompileTimeClass

getField

public CtField getField(java.lang.String name)
                 throws NotFoundException
Description copied from class: CompileTimeClass
Returns the field with the specified name. The returned field may be a private field declared in a super class or interface.

Overrides:
getField in class CompileTimeClass
Throws:
NotFoundException

getDeclaredFields

public CtField[] getDeclaredFields()
Description copied from class: CompileTimeClass
Gets all the fields declared in the class. The inherited fields are not included.

Note: the result does not include inherited fields.

Overrides:
getDeclaredFields in class CompileTimeClass

getDeclaredField

public CtField getDeclaredField(java.lang.String name)
                         throws NotFoundException
Description copied from class: CompileTimeClass
Retrieves the field with the specified name among the fields declared in the class.

Note: this method does not search the superclasses.

Overrides:
getDeclaredField in class CompileTimeClass
Throws:
NotFoundException

getDeclaredBehaviors

public CtBehavior[] getDeclaredBehaviors()
Description copied from class: CompileTimeClass
Gets all the constructors and methods declared in the class.

Overrides:
getDeclaredBehaviors in class CompileTimeClass

getConstructors

public CtConstructor[] getConstructors()
Description copied from class: CompileTimeClass
Returns an array containing CtConstructor objects representing all the public constructors of the class.

Overrides:
getConstructors in class CompileTimeClass

getConstructor

public CtConstructor getConstructor(java.lang.String desc)
                             throws NotFoundException
Description copied from class: CompileTimeClass
Returns the constructor with the given signature, which is represented by a character string called method descriptor. For details of the method descriptor, see the JVM specification or javassist.bytecode.Descriptor.

Overrides:
getConstructor in class CompileTimeClass
Parameters:
desc - method descriptor
Throws:
NotFoundException
See Also:
Descriptor

getDeclaredConstructors

public CtConstructor[] getDeclaredConstructors()
Description copied from class: CompileTimeClass
Gets all the constructors declared in the class.

Overrides:
getDeclaredConstructors in class CompileTimeClass
See Also:
CtConstructor

getClassInitializer

public CtConstructor getClassInitializer()
Description copied from class: CompileTimeClass
Gets the class initializer (static constructor) declared in the class. This method returns null if no class initializer is not declared.

Overrides:
getClassInitializer in class CompileTimeClass
See Also:
CompileTimeClass.makeClassInitializer(), CtConstructor

getMethods

public CtMethod[] getMethods()
Description copied from class: CompileTimeClass
Returns an array containing CtMethod objects representing all the public methods of the class. That array includes public methods inherited from the superclasses.

Overrides:
getMethods in class CompileTimeClass

getMethod

public CtMethod getMethod(java.lang.String name,
                          java.lang.String desc)
                   throws NotFoundException
Description copied from class: CompileTimeClass
Returns the method with the given name and signature. The returned method may be declared in a super class. The method signature is represented by a character string called method descriptor, which is defined in the JVM specification.

Overrides:
getMethod in class CompileTimeClass
Parameters:
name - method name
desc - method descriptor
Throws:
NotFoundException
See Also:
Descriptor

getDeclaredMethods

public CtMethod[] getDeclaredMethods()
Description copied from class: CompileTimeClass
Gets all methods declared in the class. The inherited methods are not included.

Overrides:
getDeclaredMethods in class CompileTimeClass
See Also:
CtMethod

getDeclaredMethod

public CtMethod getDeclaredMethod(java.lang.String name)
                           throws NotFoundException
Description copied from class: CompileTimeClass
Retrieves the method with the specified name among the methods declared in the class. If there are multiple methods with the specified name, then this method returns one of them.

Note: this method does not search the superclasses.

Overrides:
getDeclaredMethod in class CompileTimeClass
Throws:
NotFoundException
See Also:
CtMethod

getDeclaredMethod

public CtMethod getDeclaredMethod(java.lang.String name,
                                  CompileTimeClass[] params)
                           throws NotFoundException
Description copied from class: CompileTimeClass
Retrieves the method with the specified name and parameter types among the methods declared in the class.

Note: this method does not search the superclasses.

Overrides:
getDeclaredMethod in class CompileTimeClass
Parameters:
name - method name
params - parameter types
Throws:
NotFoundException
See Also:
CtMethod

addField

public void addField(CtField f,
                     java.lang.String init)
              throws CannotCompileException
Description copied from class: CompileTimeClass
Adds a field with an initial value.

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.

Here, the type of variable cc is CtClass. The type of f is CtField.

Overrides:
addField in class CompileTimeClass
init - an expression for the initial value.
Throws:
CannotCompileException
See Also:
CtField.Initializer.byExpr(String), CtField.CtField(CtField,CompileTimeClass)

addField

public void addField(CtField f,
                     CtField.Initializer init)
              throws CannotCompileException
Description copied from class: CompileTimeClass
Adds a field with an initial value.

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,

This code adds an int field named "i". The initial value of this field is 1.

Overrides:
addField in class CompileTimeClass
init - specifies the initial value of the field.
Throws:
CannotCompileException
See Also:
CtField.CtField(CtField,CompileTimeClass)

makeClassInitializer

public CtConstructor makeClassInitializer()
                                   throws CannotCompileException
Description copied from class: CompileTimeClass
Makes a class initializer (static constructor). If the class already includes a class initializer, this method returns it.

Overrides:
makeClassInitializer in class CompileTimeClass
Throws:
CannotCompileException
See Also:
CompileTimeClass.getClassInitializer()

addConstructor

public void addConstructor(CtConstructor c)
                    throws CannotCompileException
Description copied from class: CompileTimeClass
Adds a constructor.

Overrides:
addConstructor in class CompileTimeClass
Throws:
CannotCompileException

addMethod

public void addMethod(CtMethod m)
               throws CannotCompileException
Description copied from class: CompileTimeClass
Adds a method.

Overrides:
addMethod in class CompileTimeClass
Throws:
CannotCompileException

getAttribute

public byte[] getAttribute(java.lang.String name)
Description copied from class: CompileTimeClass
Obtains an attribute with the given name. If that attribute is not found in the class file, this method returns null.

Overrides:
getAttribute in class CompileTimeClass
Parameters:
name - attribute name

setAttribute

public void setAttribute(java.lang.String name,
                         byte[] data)
Description copied from class: CompileTimeClass
Adds a named attribute. An arbitrary data (smaller than 64Kb) can be saved in the class file. Some attribute name are reserved by the JVM. The attributes with the non-reserved names are ignored when a class file is loaded into the JVM. If there is already an attribute with the same name, this method substitutes the new one for it.

Overrides:
setAttribute in class CompileTimeClass
Parameters:
name - attribute name
data - attribute value

instrument

public void instrument(CodeConverter converter)
                throws CannotCompileException
Description copied from class: CompileTimeClass
Applies the given converter to all methods and constructors declared in the class. This method calls instrument() on every CtMethod and CtConstructor object in the class.

Overrides:
instrument in class CompileTimeClass
Parameters:
converter - specifies how to modify.
Throws:
CannotCompileException

instrument

public void instrument(ExprEditor editor)
                throws CannotCompileException
Description copied from class: CompileTimeClass
Modifies the bodies of all methods and constructors declared in the class. This method calls instrument() on every CtMethod and CtConstructor object in the class.

Overrides:
instrument in class CompileTimeClass
Parameters:
editor - specifies how to modify.
Throws:
CannotCompileException