|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectclassUtils.javassist.CtMember
classUtils.javassist.CtBehavior
classUtils.javassist.CtConstructor
public final class CtConstructor
An instance of CtConstructor represents a constructor.
It may represent a static constructor
(class initializer). To distinguish a constructor and a class
initializer, call isClassInitializer()
.
CompileTimeClass.getDeclaredConstructors()
,
CompileTimeClass.getClassInitializer()
,
CtNewConstructor
Constructor Summary | |
---|---|
CtConstructor(CompileTimeClass[] parameters,
CompileTimeClass declaring)
Creates a constructor with no constructor body. |
|
CtConstructor(CtConstructor src,
CompileTimeClass declaring,
ClassMap map)
Creates a copy of a CtConstructor object. |
Method Summary | |
---|---|
void |
addCatch(java.lang.String src,
CompileTimeClass exceptionType)
Adds a catch clause that handles an exception thrown in the constructor body. |
byte[] |
getAttribute(java.lang.String name)
Obtains an attribute with the given name. |
CompileTimeClass |
getDeclaringClass()
Returns the class that declares this constructor. |
CompileTimeClass[] |
getExceptionTypes()
Obtains exceptions that this constructor may throw. |
MethodInfo |
getMethodInfo()
Returns the MethodInfo representing the constructor in the class file. |
int |
getModifiers()
Obtains the encoded modifiers of the constructor. |
java.lang.String |
getName()
Obtains the name of this constructor. |
CompileTimeClass[] |
getParameterTypes()
Obtains parameter types of this constructor. |
java.lang.String |
getSignature()
Returns the character string representing the parameter types. |
void |
insertAfter(java.lang.String src)
Inserts bytecode affineTransform the end of the constructor body. |
void |
insertAfter(java.lang.String src,
boolean asFinally)
Inserts bytecode affineTransform the end of the constructor body. |
void |
insertBefore(java.lang.String src)
Inserts bytecode affineTransform the beginning of the constructor body. |
void |
insertBeforeBody(java.lang.String src)
Inserts bytecode just after another constructor in the super class or this class is called. |
void |
instrument(CodeConverter converter)
Modifies the constructor body. |
void |
instrument(ExprEditor editor)
Modifies the constructor body. |
boolean |
isClassInitializer()
Returns true if this object represents a static initializer. |
boolean |
isConstructor()
Returns true if this object represents a constructor. |
boolean |
isEmpty()
Returns true if the constructor is the default one. |
void |
setAttribute(java.lang.String name,
byte[] data)
Adds an attribute. |
void |
setBody(CtConstructor src,
ClassMap map)
Copies a constructor body from another constructor. |
void |
setBody(java.lang.String src)
Sets a constructor body. |
void |
setExceptionTypes(CompileTimeClass[] types)
Sets exceptions that this constructor may throw. |
void |
setModifiers(int mod)
Sets the encoded modifiers of the constructor. |
void |
useCflow(java.lang.String name)
Declares to use $cflow for this constructor. |
Methods inherited from class classUtils.javassist.CtBehavior |
---|
addCatch, getMethodInfo2 |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CtConstructor(CompileTimeClass[] parameters, CompileTimeClass declaring)
CtClass.addConstructor()
.
The created constructor does not include a constructor body,
must be specified with setBody()
.
declaring
- the class to which the created method is added.parameters
- a list of the parameter typesCompileTimeClass.addConstructor(CtConstructor)
,
setBody(String)
,
setBody(CtConstructor,ClassMap)
public CtConstructor(CtConstructor src, CompileTimeClass declaring, ClassMap map) throws CannotCompileException
CtConstructor
object.
The created constructor must be
added to a class with CtClass.addConstructor()
.
All occurrences of class names in the created constructor
are replaced with names specified by
map
if map
is not null
.
By default, all the occurrences of the names of the class
declaring src
and the superclass are replaced
with the name of the class and the superclass that
the created constructor is added to.
This is done whichever map
is null or not.
To prevent this replacement, call ClassMap.fix()
.
Note: if the .class
notation (for example,
String.class
) is included in an expression, the
Javac compiler may produce a helper method.
Since this constructor never
copies this helper method, the programmers have the responsiblity of
copying it. Otherwise, use Class.forName()
in the
expression.
src
- the source method.declaring
- the class to which the created method is added.map
- the hashtable associating original class names
with substituted names.
It can be null
.
CannotCompileException
CompileTimeClass.addConstructor(CtConstructor)
,
ClassMap.fix(String)
Method Detail |
---|
public MethodInfo getMethodInfo()
getMethodInfo
in class CtBehavior
public boolean isConstructor()
public boolean isClassInitializer()
public int getModifiers()
getModifiers
in class CtBehavior
javassist.Modifier
.Modifier
public void setModifiers(int mod)
setModifiers
in class CtBehavior
Modifier
public java.lang.String getName()
"<clinit>"
.
getName
in class CtBehavior
getName()
public CompileTimeClass getDeclaringClass()
getDeclaringClass
in class CtMember
public CompileTimeClass[] getParameterTypes() throws NotFoundException
getParameterTypes
in class CtBehavior
NotFoundException
public java.lang.String getSignature()
getSignature()
returns the same string.
getSignature
in class CtBehavior
public CompileTimeClass[] getExceptionTypes() throws NotFoundException
getExceptionTypes
in class CtBehavior
NotFoundException
public void setExceptionTypes(CompileTimeClass[] types) throws NotFoundException
setExceptionTypes
in class CtBehavior
NotFoundException
public boolean isEmpty()
isEmpty
in class CtBehavior
public void setBody(java.lang.String src) throws CannotCompileException
setBody
in class CtBehavior
src
- the source code representing the constructor body.
It must be a single statement or block.
If it is null
, the substituted
constructor body does nothing except calling
super()
.
CannotCompileException
public void setBody(CtConstructor src, ClassMap map) throws CannotCompileException
All occurrences of the class names in the copied body
are replaced with the names specified by
map
if map
is not null
.
src
- the method that the body is copied from.map
- the hashtable associating original class names
with substituted names.
It can be null
.
CannotCompileException
public byte[] getAttribute(java.lang.String name)
getAttribute
in class CtBehavior
name
- attribute namepublic void setAttribute(java.lang.String name, byte[] data)
setAttribute
in class CtBehavior
name
- attribute namedata
- attribute valuepublic void useCflow(java.lang.String name) throws CannotCompileException
$cflow
for this constructor.
If $cflow
is used, the class files modified
with Javassist requires a support class
javassist.runtime.Cflow
affineTransform runtime
(other Javassist classes are not required affineTransform runtime).
Every $cflow
variable is given a unique name.
For example, if the given name is "Point.paint"
,
then the variable is indicated by $cflow(Point.paint)
.
useCflow
in class CtBehavior
name
- $cflow
name. It can include
alphabets, numbers, _
,
$
, and .
(dot).
CannotCompileException
Cflow
public void instrument(CodeConverter converter) throws CannotCompileException
instrument
in class CtBehavior
converter
- specifies how to modify.
CannotCompileException
public void instrument(ExprEditor editor) throws CannotCompileException
instrument
in class CtBehavior
editor
- specifies how to modify.
CannotCompileException
public void insertBefore(java.lang.String src) throws CannotCompileException
insertBefore
in class CtBehavior
src
- the source code representing the inserted bytecode.
It must be a single statement or block.
CannotCompileException
public void insertBeforeBody(java.lang.String src) throws CannotCompileException
src
- the source code representing the inserted bytecode.
It must be a single statement or block.
CannotCompileException
public void insertAfter(java.lang.String src) throws CannotCompileException
insertAfter
in class CtBehavior
src
- the source code representing the inserted bytecode.
It must be a single statement or block.
CannotCompileException
public void insertAfter(java.lang.String src, boolean asFinally) throws CannotCompileException
insertAfter
in class CtBehavior
src
- the source code representing the inserted bytecode.
It must be a single statement or block.asFinally
- true if the inserted bytecode is executed
not only when the transfer normally returns
but also when an exception is thrown.
CannotCompileException
public void addCatch(java.lang.String src, CompileTimeClass exceptionType) throws CannotCompileException
addCatch
in class CtBehavior
src
- the source code representing the catch clause.
It must be a single statement or block.exceptionType
- the type of the exception handled by the
catch clause.
CannotCompileException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |