|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectclassUtils.javassist.CompileTimeClass
classUtils.javassist.CompileTimeClassType
public class CompileTimeClassType
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 |
|---|
public JAClassFile getClassFile2()
CompileTimeClass
getClassFile2 in class CompileTimeClasspublic ClassPool getClassPool()
CompileTimeClassClassPool for this class.
getClassPool in class CompileTimeClasspublic boolean isModified()
CompileTimeClass
isModified in class CompileTimeClasspublic boolean isFrozen()
CompileTimeClass
isFrozen in class CompileTimeClassCompileTimeClass.defrost()public void defrost()
CompileTimeClass
defrost in class CompileTimeClassCompileTimeClass.isFrozen()
public boolean subtypeOf(CompileTimeClass clazz)
throws NotFoundException
CompileTimeClasstrue if this class extends or implements
clazz. It also returns true if
this class is the same as clazz.
subtypeOf in class CompileTimeClassNotFoundException
public void setName(java.lang.String name)
throws java.lang.RuntimeException
CompileTimeClass
setName in class CompileTimeClassname - fully-qualified name
java.lang.RuntimeException
public void replaceClassName(ClassMap classnames)
throws java.lang.RuntimeException
CompileTimeClassmap.
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.
replaceClassName in class CompileTimeClassclassnames - the hashtable associating replaced class names
with substituted names.
java.lang.RuntimeException
public void replaceClassName(java.lang.String oldname,
java.lang.String newname)
throws java.lang.RuntimeException
CompileTimeClassnewName for all occurrences of a class
name oldName in the class file.
replaceClassName in class CompileTimeClassoldname - replaced class namenewname - substituted class name
java.lang.RuntimeExceptionpublic boolean isInterface()
CompileTimeClasstrue if this object represents an interface.
isInterface in class CompileTimeClasspublic int getModifiers()
CompileTimeClassjavassist.Modifier.
getModifiers in class CompileTimeClassModifierpublic void setModifiers(int mod)
CompileTimeClass
setModifiers in class CompileTimeClassmod - modifiers encoded by
javassist.ModifierModifierpublic boolean subclassOf(CompileTimeClass superclass)
CompileTimeClassThis method returns true if the given class is identical to the class represented by this object.
subclassOf in class CompileTimeClass
public CompileTimeClass getSuperclass()
throws NotFoundException
CompileTimeClassjava.lang.Object class and thus it does not have
the super class.
getSuperclass in class CompileTimeClassNotFoundException
public void setSuperclass(CompileTimeClass clazz)
throws CannotCompileException
CompileTimeClass
setSuperclass in class CompileTimeClassCannotCompileException
public CompileTimeClass[] getInterfaces()
throws NotFoundException
CompileTimeClass
getInterfaces in class CompileTimeClassNotFoundExceptionpublic void setInterfaces(CompileTimeClass[] list)
CompileTimeClass
setInterfaces in class CompileTimeClasslist - a list of the CtClass objects
representing interfaces, or
null if the class implements
no interfaces.public void addInterface(CompileTimeClass anInterface)
CompileTimeClass
addInterface in class CompileTimeClassanInterface - the added interface.public CtField[] getFields()
CompileTimeClassCtField objects
representing all the public fields of the class.
That array includes public fields inherited from the
superclasses.
getFields in class CompileTimeClass
public CtField getField(java.lang.String name)
throws NotFoundException
CompileTimeClass
getField in class CompileTimeClassNotFoundExceptionpublic CtField[] getDeclaredFields()
CompileTimeClassNote: the result does not include inherited fields.
getDeclaredFields in class CompileTimeClass
public CtField getDeclaredField(java.lang.String name)
throws NotFoundException
CompileTimeClassNote: this method does not search the superclasses.
getDeclaredField in class CompileTimeClassNotFoundExceptionpublic CtBehavior[] getDeclaredBehaviors()
CompileTimeClass
getDeclaredBehaviors in class CompileTimeClasspublic CtConstructor[] getConstructors()
CompileTimeClassCtConstructor objects
representing all the public constructors of the class.
getConstructors in class CompileTimeClass
public CtConstructor getConstructor(java.lang.String desc)
throws NotFoundException
CompileTimeClassjavassist.bytecode.Descriptor.
getConstructor in class CompileTimeClassdesc - method descriptor
NotFoundExceptionDescriptorpublic CtConstructor[] getDeclaredConstructors()
CompileTimeClass
getDeclaredConstructors in class CompileTimeClassCtConstructorpublic CtConstructor getClassInitializer()
CompileTimeClassnull if
no class initializer is not declared.
getClassInitializer in class CompileTimeClassCompileTimeClass.makeClassInitializer(),
CtConstructorpublic CtMethod[] getMethods()
CompileTimeClassCtMethod objects
representing all the public methods of the class.
That array includes public methods inherited from the
superclasses.
getMethods in class CompileTimeClass
public CtMethod getMethod(java.lang.String name,
java.lang.String desc)
throws NotFoundException
CompileTimeClass
getMethod in class CompileTimeClassname - method namedesc - method descriptor
NotFoundExceptionDescriptorpublic CtMethod[] getDeclaredMethods()
CompileTimeClass
getDeclaredMethods in class CompileTimeClassCtMethod
public CtMethod getDeclaredMethod(java.lang.String name)
throws NotFoundException
CompileTimeClassNote: this method does not search the superclasses.
getDeclaredMethod in class CompileTimeClassNotFoundExceptionCtMethod
public CtMethod getDeclaredMethod(java.lang.String name,
CompileTimeClass[] params)
throws NotFoundException
CompileTimeClassNote: this method does not search the superclasses.
getDeclaredMethod in class CompileTimeClassname - method nameparams - parameter types
NotFoundExceptionCtMethod
public void addField(CtField f,
java.lang.String init)
throws CannotCompileException
CompileTimeClassThe 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.
addField in class CompileTimeClassinit - an expression for the initial value.
CannotCompileExceptionCtField.Initializer.byExpr(String),
CtField.CtField(CtField,CompileTimeClass)
public void addField(CtField f,
CtField.Initializer init)
throws CannotCompileException
CompileTimeClassThe 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.
addField in class CompileTimeClassinit - specifies the initial value of the field.
CannotCompileExceptionCtField.CtField(CtField,CompileTimeClass)
public CtConstructor makeClassInitializer()
throws CannotCompileException
CompileTimeClass
makeClassInitializer in class CompileTimeClassCannotCompileExceptionCompileTimeClass.getClassInitializer()
public void addConstructor(CtConstructor c)
throws CannotCompileException
CompileTimeClass
addConstructor in class CompileTimeClassCannotCompileException
public void addMethod(CtMethod m)
throws CannotCompileException
CompileTimeClass
addMethod in class CompileTimeClassCannotCompileExceptionpublic byte[] getAttribute(java.lang.String name)
CompileTimeClass
getAttribute in class CompileTimeClassname - attribute name
public void setAttribute(java.lang.String name,
byte[] data)
CompileTimeClass
setAttribute in class CompileTimeClassname - attribute namedata - attribute value
public void instrument(CodeConverter converter)
throws CannotCompileException
CompileTimeClassinstrument()
on every CtMethod and CtConstructor object
in the class.
instrument in class CompileTimeClassconverter - specifies how to modify.
CannotCompileException
public void instrument(ExprEditor editor)
throws CannotCompileException
CompileTimeClassinstrument()
on every CtMethod and CtConstructor object
in the class.
instrument in class CompileTimeClasseditor - specifies how to modify.
CannotCompileException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||