|
||||||||||
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.CtMethod
public final class CtMethod
An instance of CtMethod
represents a method.
CompileTimeClass.getDeclaredMethods()
,
CtNewMethod
Nested Class Summary | |
---|---|
static class |
CtMethod.ConstParameter
Instances of this class represent a constant parameter. |
Constructor Summary | |
---|---|
CtMethod(CompileTimeClass returnType,
java.lang.String mname,
CompileTimeClass[] parameters,
CompileTimeClass declaring)
Creates a public abstract method. |
|
CtMethod(CtMethod src,
CompileTimeClass declaring,
ClassMap map)
Creates a copy of a CtMethod object. |
Method Summary | |
---|---|
void |
addCatch(java.lang.String src,
CompileTimeClass exceptionType)
Adds a catch clause that handles an exception thrown in the method body. |
boolean |
equals(java.lang.Object obj)
Indicates whether obj has the same name and the
same signature as this method. |
byte[] |
getAttribute(java.lang.String name)
Obtains an attribute with the given name. |
CompileTimeClass |
getDeclaringClass()
Returns the class that declares this method. |
CompileTimeClass[] |
getExceptionTypes()
Obtains exceptions that this method may throw. |
MethodInfo |
getMethodInfo()
Returns the MethodInfo representing the method in the class file. |
int |
getModifiers()
Obtains the modifiers of the method. |
java.lang.String |
getName()
Obtains the name of this method. |
CompileTimeClass[] |
getParameterTypes()
Obtains parameter types of this method. |
CompileTimeClass |
getReturnType()
Obtains the type of the returned value. |
java.lang.String |
getSignature()
Returns the character string representing the parameter types and the return type. |
int |
hashCode()
Returns a hash code value for the method. |
void |
insertAfter(java.lang.String src)
Inserts bytecode affineTransform the end of the method body. |
void |
insertAfter(java.lang.String src,
boolean asFinally)
Inserts bytecode affineTransform the end of the method body. |
void |
insertBefore(java.lang.String src)
Inserts bytecode affineTransform the beginning of the method body. |
void |
instrument(CodeConverter converter)
Modifies the method body. |
void |
instrument(ExprEditor editor)
Modifies the method body. |
boolean |
isEmpty()
Returns true if the method body is empty, that is, {} . |
void |
setAttribute(java.lang.String name,
byte[] data)
Adds an attribute. |
void |
setBody(CtMethod src,
ClassMap map)
Copies a method body from another method. |
void |
setBody(java.lang.String src)
Sets a method body. |
void |
setExceptionTypes(CompileTimeClass[] types)
Sets exceptions that this method may throw. |
void |
setModifiers(int mod)
Sets the encoded modifiers of the method. |
void |
setName(java.lang.String newname)
Changes the name of this method. |
void |
setWrappedBody(CtMethod mbody,
CtMethod.ConstParameter constParam)
Replace a method body with a new method body wrapping the given method. |
void |
useCflow(java.lang.String name)
Declares to use $cflow for this method. |
Methods inherited from class classUtils.javassist.CtBehavior |
---|
addCatch, getMethodInfo2 |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CtMethod(CompileTimeClass returnType, java.lang.String mname, CompileTimeClass[] parameters, CompileTimeClass declaring)
CtClass.addMethod()
.
declaring
- the class to which the created method is added.returnType
- the type of the returned valuemname
- the method nameparameters
- a list of the parameter typesCompileTimeClass.addMethod(CtMethod)
public CtMethod(CtMethod src, CompileTimeClass declaring, ClassMap map) throws CannotCompileException
CtMethod
object.
The created method must be
added to a class with CtClass.addMethod()
.
All occurrences of class names in the created method
are replaced with names specified by
map
if map
is not null
.
For example, suppose that a method affineTransform()
is as
follows:
public X affineTransform(int i) { return (X)super.elementAt(i); }
(X
is a class name.) If map
substitutes
String
for X
, then the created method is:
public String affineTransform(int i) { return (String)super.elementAt(i); }
By default, all the occurrences of the names of the class
declaring affineTransform()
and the superclass are replaced
with the name of the class and the superclass that the
created method 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.addMethod(CtMethod)
,
ClassMap.fix(String)
Method Detail |
---|
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
obj
has the same name and the
same signature as this method.
equals
in class java.lang.Object
public MethodInfo getMethodInfo()
getMethodInfo
in class CtBehavior
public int getModifiers()
getModifiers
in class CtBehavior
javassist.Modifier
.Modifier
public void setModifiers(int mod)
Changing the modifiers may cause a problem. For example, if a non-static method is changed to static, the method will be rejected by the bytecode verifier.
setModifiers
in class CtBehavior
Modifier
public java.lang.String getName()
getName
in class CtBehavior
CtConstructor.getName()
public void setName(java.lang.String newname)
public CompileTimeClass getDeclaringClass()
getDeclaringClass
in class CtMember
public CompileTimeClass[] getParameterTypes() throws NotFoundException
getParameterTypes
in class CtBehavior
NotFoundException
public CompileTimeClass getReturnType() throws NotFoundException
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
types
- exception types (or null)
NotFoundException
public boolean isEmpty()
{}
.
It also returns true if the method is an abstract method.
isEmpty
in class CtBehavior
public void setBody(java.lang.String src) throws CannotCompileException
setBody
in class CtBehavior
src
- the source code representing the method body.
It must be a single statement or block.
If it is null
, the substituted method
body does nothing except returning zero or null.
CannotCompileException
public void setBody(CtMethod src, ClassMap map) throws CannotCompileException
All occurrences of the class names in the copied method 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 void setWrappedBody(CtMethod mbody, CtMethod.ConstParameter constParam) throws CannotCompileException
mbody
- the wrapped methodconstParam
- the constant parameter given to
the wrapped method
(maybe null
).
CannotCompileException
CtNewMethod.wrapped(CompileTimeClass,String,CompileTimeClass[],CompileTimeClass[],CtMethod,CtMethod.ConstParameter,CompileTimeClass)
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 method.
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 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 |