| java.lang.Object javassist.CtMember javassist.CtBehavior javassist.CtMethod
CtMethod | final public class CtMethod extends CtBehavior (Code) | | An instance of CtMethod represents a method.
See the super class CtBehavior since
a number of useful methods are in CtBehavior .
A number of useful factory methods are in CtNewMethod .
See Also: CtClass.getDeclaredMethods See Also: CtNewMethod |
Inner Class :public static class ConstParameter | |
Inner Class :static class IntConstParameter extends ConstParameter | |
Inner Class :static class LongConstParameter extends ConstParameter | |
Inner Class :static class StringConstParameter extends ConstParameter | |
Constructor Summary | |
| CtMethod(MethodInfo minfo, CtClass declaring) | public | CtMethod(CtClass returnType, String mname, CtClass[] parameters, CtClass declaring) Creates a public abstract method. | public | CtMethod(CtMethod src, CtClass declaring, ClassMap map) Creates a copy of a 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 at() is as
follows:
public X at(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 at(int i) {
return (String)super.elementAt(i);
}
By default, all the occurrences of the names of the class
declaring at() 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. |
Method Summary | |
public boolean | equals(Object obj) Indicates whether obj has the same name and the
same signature as this method. | public String | getName() Obtains the name of this method. | public CtClass | getReturnType() Obtains the type of the returned value. | final String | getStringRep() | public int | hashCode() Returns a hash code value for the method. | public boolean | isEmpty() Returns true if the method body is empty, that is, {} . | public static CtMethod | make(String src, CtClass declaring) Compiles the given source code and creates a method.
This method simply delegates to make() in
CtNewMethod . | public void | setBody(CtMethod src, ClassMap map) Copies a method body from another method. | public void | setName(String newname) Changes the name of this method. | public void | setWrappedBody(CtMethod mbody, ConstParameter constParam) Replace a method body with a new method body wrapping the
given method. |
CtMethod | public CtMethod(CtClass returnType, String mname, CtClass[] parameters, CtClass declaring)(Code) | | Creates a public abstract method. The created method must be
added to a class with CtClass.addMethod() .
Parameters: declaring - the class to which the created method is added. Parameters: returnType - the type of the returned value Parameters: mname - the method name Parameters: parameters - a list of the parameter types See Also: CtClass.addMethod(CtMethod) |
CtMethod | public CtMethod(CtMethod src, CtClass declaring, ClassMap map) throws CannotCompileException(Code) | | Creates a copy of a 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 at() is as
follows:
public X at(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 at(int i) {
return (String)super.elementAt(i);
}
By default, all the occurrences of the names of the class
declaring at() 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.
Parameters: src - the source method. Parameters: declaring - the class to which the created method is added. Parameters: map - the hashtable associating original class nameswith substituted names.It can be null . See Also: CtClass.addMethod(CtMethod) See Also: ClassMap.fix(String) |
equals | public boolean equals(Object obj)(Code) | | Indicates whether obj has the same name and the
same signature as this method.
|
getName | public String getName()(Code) | | Obtains the name of this method.
|
hashCode | public int hashCode()(Code) | | Returns a hash code value for the method.
If two methods have the same name and signature, then
the hash codes for the two methods are equal.
|
isEmpty | public boolean isEmpty()(Code) | | Returns true if the method body is empty, that is, {} .
It also returns true if the method is an abstract method.
|
make | public static CtMethod make(String src, CtClass declaring) throws CannotCompileException(Code) | | Compiles the given source code and creates a method.
This method simply delegates to make() in
CtNewMethod . See it for more details.
CtNewMethod has a number of useful factory methods.
Parameters: src - the source text. Parameters: declaring - the class to which the created method is added. See Also: CtNewMethod.make(StringCtClass) |
setBody | public void setBody(CtMethod src, ClassMap map) throws CannotCompileException(Code) | | Copies a method body from another method.
If this method is abstract, the abstract modifier is removed
after the method body is copied.
All occurrences of the class names in the copied method body
are replaced with the names specified by
map if map is not null .
Parameters: src - the method that the body is copied from. Parameters: map - the hashtable associating original class nameswith substituted names.It can be null . |
setName | public void setName(String newname)(Code) | | Changes the name of this method.
|
Methods inherited from javassist.CtBehavior | public void addCatch(String src, CtClass exceptionType) throws CannotCompileException(Code)(Java Doc) public void addCatch(String src, CtClass exceptionType, String exceptionName) throws CannotCompileException(Code)(Java Doc) public void addLocalVariable(String name, CtClass type) throws CannotCompileException(Code)(Java Doc) void copy(CtBehavior src, boolean isCons, ClassMap map) throws CannotCompileException(Code)(Java Doc) protected void extendToString(StringBuffer buffer)(Code)(Java Doc) public Object[] getAnnotations() throws ClassNotFoundException(Code)(Java Doc) public byte[] getAttribute(String name)(Code)(Java Doc) public Object[] getAvailableAnnotations()(Code)(Java Doc) public Object[][] getAvailableParameterAnnotations()(Code)(Java Doc) public CtClass[] getExceptionTypes() throws NotFoundException(Code)(Java Doc) public MethodInfo getMethodInfo()(Code)(Java Doc) public MethodInfo getMethodInfo2()(Code)(Java Doc) public int getModifiers()(Code)(Java Doc) public Object[][] getParameterAnnotations() throws ClassNotFoundException(Code)(Java Doc) Object[][] getParameterAnnotations(boolean ignoreNotFound) throws ClassNotFoundException(Code)(Java Doc) public CtClass[] getParameterTypes() throws NotFoundException(Code)(Java Doc) CtClass getReturnType0() throws NotFoundException(Code)(Java Doc) public String getSignature()(Code)(Java Doc) int getStartPosOfBody(CodeAttribute ca) throws CannotCompileException(Code)(Java Doc) public void insertAfter(String src) throws CannotCompileException(Code)(Java Doc) public void insertAfter(String src, boolean asFinally) throws CannotCompileException(Code)(Java Doc) public int insertAt(int lineNum, String src) throws CannotCompileException(Code)(Java Doc) public int insertAt(int lineNum, boolean modify, String src) throws CannotCompileException(Code)(Java Doc) public void insertBefore(String src) throws CannotCompileException(Code)(Java Doc) public void instrument(CodeConverter converter) throws CannotCompileException(Code)(Java Doc) public void instrument(ExprEditor editor) throws CannotCompileException(Code)(Java Doc) abstract public boolean isEmpty()(Code)(Java Doc) public void setAttribute(String name, byte[] data)(Code)(Java Doc) public void setBody(String src) throws CannotCompileException(Code)(Java Doc) public void setBody(String src, String delegateObj, String delegateMethod) throws CannotCompileException(Code)(Java Doc) static void setBody0(CtClass srcClass, MethodInfo srcInfo, CtClass destClass, MethodInfo destInfo, ClassMap map) throws CannotCompileException(Code)(Java Doc) public void setExceptionTypes(CtClass[] types) throws NotFoundException(Code)(Java Doc) public void setModifiers(int mod)(Code)(Java Doc) public void useCflow(String name) throws CannotCompileException(Code)(Java Doc)
|
|
|