classUtils.javassist
Class CtBehavior

java.lang.Object
  extended by classUtils.javassist.CtMember
      extended by classUtils.javassist.CtBehavior
Direct Known Subclasses:
CtConstructor, CtMethod

public abstract class CtBehavior
extends CtMember

CtBehavior is the abstract super class of CtMethod and CtConstructor.


Method Summary
 void addCatch(java.lang.String src, CompileTimeClass exceptionType)
          Adds a catch clause that handles an exception thrown in the body.
 void addCatch(java.lang.String src, CompileTimeClass exceptionType, java.lang.String exceptionName)
          Adds a catch clause that handles an exception thrown in the body.
 byte[] getAttribute(java.lang.String name)
          Obtains an attribute with the given name.
 CompileTimeClass[] getExceptionTypes()
          Obtains exceptions that this member may throw.
 MethodInfo getMethodInfo()
          Returns the MethodInfo representing this member in the class file.
 MethodInfo getMethodInfo2()
          Undocumented method.
 int getModifiers()
          Obtains the modifiers of the member.
abstract  java.lang.String getName()
          Obtains the name of this member.
 CompileTimeClass[] getParameterTypes()
          Obtains parameter types of this member.
 java.lang.String getSignature()
          Returns the character string representing the parameter types and the return type.
 void insertAfter(java.lang.String src)
          Inserts bytecode affineTransform the end of the body.
 void insertAfter(java.lang.String src, boolean asFinally)
          Inserts bytecode affineTransform the end of the body.
 void insertBefore(java.lang.String src)
          Inserts bytecode affineTransform the beginning of the body.
 void instrument(CodeConverter converter)
          Modifies the member body.
 void instrument(ExprEditor editor)
          Modifies the member body.
abstract  boolean isEmpty()
          Returns true if the body is empty.
 void setAttribute(java.lang.String name, byte[] data)
          Adds an attribute.
 void setBody(java.lang.String src)
          Sets a member body.
 void setExceptionTypes(CompileTimeClass[] types)
          Sets exceptions that this member may throw.
 void setModifiers(int mod)
          Sets the encoded modifiers of the member.
 void useCflow(java.lang.String name)
          Declares to use $cflow for this member; 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).
 
Methods inherited from class classUtils.javassist.CtMember
getDeclaringClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMethodInfo

public MethodInfo getMethodInfo()
Returns the MethodInfo representing this member in the class file.


getMethodInfo2

public MethodInfo getMethodInfo2()
Undocumented method. Do not use; internal-use only.


getModifiers

public int getModifiers()
Obtains the modifiers of the member.

Specified by:
getModifiers in class CtMember
Returns:
modifiers encoded with javassist.Modifier.
See Also:
Modifier

setModifiers

public void setModifiers(int mod)
Sets the encoded modifiers of the member.

Specified by:
setModifiers in class CtMember
See Also:
Modifier

getName

public abstract java.lang.String getName()
Obtains the name of this member.

Specified by:
getName in class CtMember
See Also:
CtConstructor.getName()

getParameterTypes

public CompileTimeClass[] getParameterTypes()
                                     throws NotFoundException
Obtains parameter types of this member.

Throws:
NotFoundException

getSignature

public java.lang.String getSignature()
Returns the character string representing the parameter types and the return type. If two members have the same parameter types and the return type, getSignature() returns the same string.


getExceptionTypes

public CompileTimeClass[] getExceptionTypes()
                                     throws NotFoundException
Obtains exceptions that this member may throw.

Throws:
NotFoundException

setExceptionTypes

public void setExceptionTypes(CompileTimeClass[] types)
                       throws NotFoundException
Sets exceptions that this member may throw.

Throws:
NotFoundException

isEmpty

public abstract boolean isEmpty()
Returns true if the body is empty.


setBody

public void setBody(java.lang.String src)
             throws CannotCompileException
Sets a member body.

Parameters:
src - the source code representing the member body. It must be a single statement or block. If it is null, the substituted member body does nothing except returning zero or null.
Throws:
CannotCompileException

getAttribute

public byte[] getAttribute(java.lang.String name)
Obtains an attribute with the given name. If that attribute is not found in the class file, this method returns null.

Specified by:
getAttribute in class CtMember
Parameters:
name - attribute name

setAttribute

public void setAttribute(java.lang.String name,
                         byte[] data)
Adds an attribute. The attribute is saved in the class file.

Specified by:
setAttribute in class CtMember
Parameters:
name - attribute name
data - attribute value

useCflow

public void useCflow(java.lang.String name)
              throws CannotCompileException
Declares to use $cflow for this member; 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).

Parameters:
name - $cflow name. It can include alphabets, numbers, _, $, and . (dot).
Throws:
CannotCompileException
See Also:
Cflow

instrument

public void instrument(CodeConverter converter)
                throws CannotCompileException
Modifies the member body.

Parameters:
converter - specifies how to modify.
Throws:
CannotCompileException

instrument

public void instrument(ExprEditor editor)
                throws CannotCompileException
Modifies the member body.

Parameters:
editor - specifies how to modify.
Throws:
CannotCompileException

insertBefore

public void insertBefore(java.lang.String src)
                  throws CannotCompileException
Inserts bytecode affineTransform the beginning of the body.

Parameters:
src - the source code representing the inserted bytecode. It must be a single statement or block.
Throws:
CannotCompileException

insertAfter

public void insertAfter(java.lang.String src)
                 throws CannotCompileException
Inserts bytecode affineTransform the end of the body. The bytecode is inserted just before every return insturction. It is not executed when an exception is thrown.

Parameters:
src - the source code representing the inserted bytecode. It must be a single statement or block.
Throws:
CannotCompileException

insertAfter

public void insertAfter(java.lang.String src,
                        boolean asFinally)
                 throws CannotCompileException
Inserts bytecode affineTransform the end of the body. The bytecode is inserted just before every return insturction.

Parameters:
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 control normally returns but also when an exception is thrown.
Throws:
CannotCompileException

addCatch

public void addCatch(java.lang.String src,
                     CompileTimeClass exceptionType)
              throws CannotCompileException
Adds a catch clause that handles an exception thrown in the body. The catch clause must end with a return or throw statement.

Parameters:
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.
Throws:
CannotCompileException

addCatch

public void addCatch(java.lang.String src,
                     CompileTimeClass exceptionType,
                     java.lang.String exceptionName)
              throws CannotCompileException
Adds a catch clause that handles an exception thrown in the body. The catch clause must end with a return or throw statement.

Parameters:
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.
exceptionName - the name of the variable containing the caught exception, for example, $e.
Throws:
CannotCompileException