|
||||||||||
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 CompileTimeClass
public ClassPool getClassPool()
CompileTimeClass
ClassPool
for this class.
getClassPool
in class CompileTimeClass
public boolean isModified()
CompileTimeClass
isModified
in class CompileTimeClass
public boolean isFrozen()
CompileTimeClass
isFrozen
in class CompileTimeClass
CompileTimeClass.defrost()
public void defrost()
CompileTimeClass
defrost
in class CompileTimeClass
CompileTimeClass.isFrozen()
public boolean subtypeOf(CompileTimeClass clazz) throws NotFoundException
CompileTimeClass
true
if this class extends or implements
clazz
. It also returns true
if
this class is the same as clazz
.
subtypeOf
in class CompileTimeClass
NotFoundException
public void setName(java.lang.String name) throws java.lang.RuntimeException
CompileTimeClass
setName
in class CompileTimeClass
name
- fully-qualified name
java.lang.RuntimeException
public void replaceClassName(ClassMap classnames) throws java.lang.RuntimeException
CompileTimeClass
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.
replaceClassName
in class CompileTimeClass
classnames
- 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
CompileTimeClass
newName
for all occurrences of a class
name oldName
in the class file.
replaceClassName
in class CompileTimeClass
oldname
- replaced class namenewname
- substituted class name
java.lang.RuntimeException
public boolean isInterface()
CompileTimeClass
true
if this object represents an interface.
isInterface
in class CompileTimeClass
public int getModifiers()
CompileTimeClass
javassist.Modifier
.
getModifiers
in class CompileTimeClass
Modifier
public void setModifiers(int mod)
CompileTimeClass
setModifiers
in class CompileTimeClass
mod
- modifiers encoded by
javassist.Modifier
Modifier
public boolean subclassOf(CompileTimeClass superclass)
CompileTimeClass
This 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
CompileTimeClass
java.lang.Object
class and thus it does not have
the super class.
getSuperclass
in class CompileTimeClass
NotFoundException
public void setSuperclass(CompileTimeClass clazz) throws CannotCompileException
CompileTimeClass
setSuperclass
in class CompileTimeClass
CannotCompileException
public CompileTimeClass[] getInterfaces() throws NotFoundException
CompileTimeClass
getInterfaces
in class CompileTimeClass
NotFoundException
public void setInterfaces(CompileTimeClass[] list)
CompileTimeClass
setInterfaces
in class CompileTimeClass
list
- 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 CompileTimeClass
anInterface
- the added interface.public CtField[] getFields()
CompileTimeClass
CtField
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 CompileTimeClass
NotFoundException
public CtField[] getDeclaredFields()
CompileTimeClass
Note: the result does not include inherited fields.
getDeclaredFields
in class CompileTimeClass
public CtField getDeclaredField(java.lang.String name) throws NotFoundException
CompileTimeClass
Note: this method does not search the superclasses.
getDeclaredField
in class CompileTimeClass
NotFoundException
public CtBehavior[] getDeclaredBehaviors()
CompileTimeClass
getDeclaredBehaviors
in class CompileTimeClass
public CtConstructor[] getConstructors()
CompileTimeClass
CtConstructor
objects
representing all the public constructors of the class.
getConstructors
in class CompileTimeClass
public CtConstructor getConstructor(java.lang.String desc) throws NotFoundException
CompileTimeClass
javassist.bytecode.Descriptor
.
getConstructor
in class CompileTimeClass
desc
- method descriptor
NotFoundException
Descriptor
public CtConstructor[] getDeclaredConstructors()
CompileTimeClass
getDeclaredConstructors
in class CompileTimeClass
CtConstructor
public CtConstructor getClassInitializer()
CompileTimeClass
null
if
no class initializer is not declared.
getClassInitializer
in class CompileTimeClass
CompileTimeClass.makeClassInitializer()
,
CtConstructor
public CtMethod[] getMethods()
CompileTimeClass
CtMethod
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 CompileTimeClass
name
- method namedesc
- method descriptor
NotFoundException
Descriptor
public CtMethod[] getDeclaredMethods()
CompileTimeClass
getDeclaredMethods
in class CompileTimeClass
CtMethod
public CtMethod getDeclaredMethod(java.lang.String name) throws NotFoundException
CompileTimeClass
Note: this method does not search the superclasses.
getDeclaredMethod
in class CompileTimeClass
NotFoundException
CtMethod
public CtMethod getDeclaredMethod(java.lang.String name, CompileTimeClass[] params) throws NotFoundException
CompileTimeClass
Note: this method does not search the superclasses.
getDeclaredMethod
in class CompileTimeClass
name
- method nameparams
- parameter types
NotFoundException
CtMethod
public void addField(CtField f, java.lang.String init) throws CannotCompileException
CompileTimeClass
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
.
addField
in class CompileTimeClass
init
- an expression for the initial value.
CannotCompileException
CtField.Initializer.byExpr(String)
,
CtField.CtField(CtField,CompileTimeClass)
public void addField(CtField f, CtField.Initializer init) throws CannotCompileException
CompileTimeClass
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.
addField
in class CompileTimeClass
init
- specifies the initial value of the field.
CannotCompileException
CtField.CtField(CtField,CompileTimeClass)
public CtConstructor makeClassInitializer() throws CannotCompileException
CompileTimeClass
makeClassInitializer
in class CompileTimeClass
CannotCompileException
CompileTimeClass.getClassInitializer()
public void addConstructor(CtConstructor c) throws CannotCompileException
CompileTimeClass
addConstructor
in class CompileTimeClass
CannotCompileException
public void addMethod(CtMethod m) throws CannotCompileException
CompileTimeClass
addMethod
in class CompileTimeClass
CannotCompileException
public byte[] getAttribute(java.lang.String name)
CompileTimeClass
getAttribute
in class CompileTimeClass
name
- attribute namepublic void setAttribute(java.lang.String name, byte[] data)
CompileTimeClass
setAttribute
in class CompileTimeClass
name
- attribute namedata
- attribute valuepublic void instrument(CodeConverter converter) throws CannotCompileException
CompileTimeClass
instrument()
on every CtMethod
and CtConstructor
object
in the class.
instrument
in class CompileTimeClass
converter
- specifies how to modify.
CannotCompileException
public void instrument(ExprEditor editor) throws CannotCompileException
CompileTimeClass
instrument()
on every CtMethod
and CtConstructor
object
in the class.
instrument
in class CompileTimeClass
editor
- specifies how to modify.
CannotCompileException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |