public abstract class CtBehavior extends CtMember
| Modifier and Type | Field and Description |
|---|---|
protected MethodInfo |
methodInfo |
declaringClass| Modifier | Constructor and Description |
|---|---|
protected |
CtBehavior(CtClass clazz,
MethodInfo minfo) |
| Modifier and Type | Method and Description |
|---|---|
void |
addLocalVariable(String name,
CtClass type)
Declares a new local variable.
|
void |
addParameter(CtClass type)
Appends a new parameter, which becomes the last parameter.
|
protected void |
extendToString(StringBuffer buffer)
Invoked by
CtMember.toString() to add to the buffer and provide the
complete value. |
Object |
getAnnotation(Class<?> clz)
Returns the annotation if the class has the specified annotation class.
|
Object[] |
getAnnotations()
Returns the annotations associated with this method or constructor.
|
byte[] |
getAttribute(String name)
Obtains an attribute with the given name.
|
Object[] |
getAvailableAnnotations()
Returns the annotations associated with this method or constructor.
|
Object[][] |
getAvailableParameterAnnotations()
Returns the parameter annotations associated with this method or constructor.
|
CtClass[] |
getExceptionTypes()
Obtains exceptions that this method/constructor may throw.
|
abstract String |
getLongName()
Returns the method or constructor name followed by parameter types
such as
javassist.CtBehavior.stBody(String). |
MethodInfo |
getMethodInfo()
Returns the MethodInfo representing this method/constructor in the
class file.
|
MethodInfo |
getMethodInfo2()
Returns the MethodInfo representing the method/constructor in the
class file (read only).
|
int |
getModifiers()
Obtains the modifiers of the method/constructor.
|
Object[][] |
getParameterAnnotations()
Returns the parameter annotations associated with this method or constructor.
|
CtClass[] |
getParameterTypes()
Obtains parameter types of this method/constructor.
|
String |
getSignature()
Returns the method signature (the parameter types
and the return type).
|
boolean |
hasAnnotation(Class<?> clz)
Returns true if the class has the specified annotation class.
|
void |
insertParameter(CtClass type)
Inserts a new parameter, which becomes the first parameter.
|
abstract boolean |
isEmpty()
Returns true if the body is empty.
|
void |
setAttribute(String name,
byte[] data)
Adds an attribute.
|
void |
setExceptionTypes(CtClass[] types)
Sets exceptions that this method/constructor may throw.
|
void |
setModifiers(int mod)
Sets the encoded modifiers of the method/constructor.
|
getDeclaringClass, getName, toString, visibleFromprotected MethodInfo methodInfo
protected CtBehavior(CtClass clazz, MethodInfo minfo)
protected void extendToString(StringBuffer buffer)
CtMemberCtMember.toString() to add to the buffer and provide the
complete value. Subclasses should invoke this method, adding a
space before each token. The modifiers for the member are
provided first; subclasses should provide additional data such
as return type, field or method name, etc.extendToString in class CtMemberpublic abstract String getLongName()
javassist.CtBehavior.stBody(String).public MethodInfo getMethodInfo()
public MethodInfo getMethodInfo2()
getMethodInfo().
The MethodInfo object obtained by this method
is read only. Changes to this object might not be reflected
on a class file generated by toBytecode(),
toClass(), etc in CtClass.
This method is available even if the CtClass
containing this method is frozen. However, if the class is
frozen, the MethodInfo might be also pruned.
getMethodInfo(),
CtClass.isFrozen(),
CtClass.prune()public int getModifiers()
getModifiers in class CtMemberjavassist.Modifier.Modifierpublic 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 CtMemberModifierpublic boolean hasAnnotation(Class<?> clz)
hasAnnotation in class CtMemberclz - the annotation class.true if the annotation is found,
otherwise false.public Object getAnnotation(Class<?> clz) throws ClassNotFoundException
@Author is associated
with this method/constructor, an Author object is returned.
The member values can be obtained by calling methods on
the Author object.getAnnotation in class CtMemberclz - the annotation class.null.ClassNotFoundExceptionpublic Object[] getAnnotations() throws ClassNotFoundException
getAnnotations in class CtMemberClassNotFoundExceptiongetAvailableAnnotations()public Object[] getAvailableAnnotations()
getAvailableAnnotations in class CtMembergetAnnotations()public Object[][] getParameterAnnotations() throws ClassNotFoundException
ClassNotFoundExceptiongetAvailableParameterAnnotations(),
getAnnotations()public Object[][] getAvailableParameterAnnotations()
getParameterAnnotations(),
getAvailableAnnotations()public CtClass[] getParameterTypes() throws NotFoundException
NotFoundExceptionpublic String getSignature()
getSignature() returns the
same string (the return type of constructors is void).
Note that the returned string is not the type signature
contained in the SignatureAttirbute. It is
a descriptor. To obtain a type signature, call the following
methods:
getMethodInfo().getAttribute(SignatureAttribute.tag)
getSignature in class CtMemberjavassist.bytecode.Descriptor,
javassist.bytecode.SignatureAttributepublic CtClass[] getExceptionTypes() throws NotFoundException
NotFoundExceptionpublic void setExceptionTypes(CtClass[] types) throws NotFoundException
NotFoundExceptionpublic abstract boolean isEmpty()
public byte[] getAttribute(String name)
Note that an attribute is a data block specified by
the class file format. It is not an annotation.
See javassist.bytecode.AttributeInfo.
getAttribute in class CtMembername - attribute namepublic void setAttribute(String name, byte[] data)
Note that an attribute is a data block specified by
the class file format. It is not an annotation.
See javassist.bytecode.AttributeInfo.
setAttribute in class CtMembername - attribute namedata - attribute valuepublic void addLocalVariable(String name, CtClass type) throws CannotCompileException
insertBefore(), insertAfter(), etc.
If the second parameter asFinally to
insertAfter() is true, the declared local variable
is not visible from the code inserted by insertAfter().
name - the name of the variabletype - the type of the variableCannotCompileException#insertBefore(String),
#insertAfter(String)public void insertParameter(CtClass type) throws CannotCompileException
CannotCompileExceptionpublic void addParameter(CtClass type) throws CannotCompileException
CannotCompileExceptionCopyright © December 07, 2012–2015 The Internet Party. All rights reserved.