org.codehaus.aspectwerkz.transform.delegation
Class JavassistHelper

java.lang.Object
  extended byorg.codehaus.aspectwerkz.transform.delegation.JavassistHelper

public class JavassistHelper
extends Object

Helper class with utility methods for Javassist.

Author:
Alexandre Vasseur , Jonas Bonér

Constructor Summary
JavassistHelper()
           
 
Method Summary
static void addAspectManagerField(javassist.CtClass ctClass, SystemDefinition definition, Context context)
          Adds a new AspectManager field to the advised class.
static void addJoinPointManagerField(javassist.CtClass ctClass, SystemDefinition definition, Context context)
          Adds a new JoinPointManager field to the advised class.
static void addStaticClassField(javassist.CtClass ctClass, Context context)
          Creates a new static class field.
static int calculateHash(javassist.CtClass ctClass)
          Calculate the hash for a class.
static int calculateHash(javassist.CtConstructor constructor)
          Calculate the hash for a javassist constructor.
static int calculateHash(javassist.CtField field)
          Calculate the hash for a javassist field.
static int calculateHash(javassist.CtMethod method)
          Calculate the hash for a javassist method.
static long calculateSerialVerUid(javassist.CtClass clazz)
          Copy pasted from Javassist since it is a private method
static String convertJavassistTypeSignatureToReflectTypeSignature(String typeName)
          Converts a Javassist type signature to a reflect type signature.
static void copyCustomAttributes(javassist.CtBehavior copyTo, javassist.CtBehavior copyFrom)
          Copies the custom attributes from one class to another.
static javassist.CtMethod createEmptyWrapperMethod(javassist.CtClass ctClass, javassist.CtMethod originalMethod, int methodSequence)
          Creates an empty wrapper method to allow HotSwap without schema change

TODO refactor PrepareTransformer CAUTION: does not check the wrapped method already exists while PrepareTransformer version does

static List createSortedMethodList(javassist.CtClass klass)
          Creates a sorted method list of all the public methods in the class and super classes.
static String getDefaultPrimitiveValue(javassist.CtClass type)
          Gets the default value for primitive types
static int getJoinPointIndex(javassist.CtClass klass)
          Returrns the join point index for the class.
static boolean hasConstructor(javassist.CtClass klass, javassist.CtClass[] args)
          Checks if the given Class as already a ctor with given signature
static boolean hasField(javassist.CtClass klass, String fieldName)
          Checks if the given Class as already a method methodName Does not take into account the signature
static boolean hasMethod(javassist.CtClass klass, String methodName)
          Checks if the given Class as already a method methodName Does not take into account the signature
static boolean hasMethod(javassist.CtClass klass, String methodName, javassist.CtClass[] args)
          Checks if the given Class as already a method methodName.
static boolean isAnnotatedEmpty(javassist.CtMethod method)
          Checks if a method is marked as an empty wrapper (runtime weaving)
static boolean isAnnotatedNotEmpty(javassist.CtMethod method)
          Checks if a method is marked as a non empty wrapper (runtime unweaving)
static boolean isSerialVerUidNeeded(javassist.CtClass clazz)
           
static javassist.CtMethod makeStatic(javassist.CtClass returnType, String name, javassist.CtClass[] parameters, javassist.CtClass[] exceptions, String body, javassist.CtClass declaring)
          Helper method for bogus CtMethod.make in Javassist for static methods
static void setAnnotatedEmpty(javassist.CtMethod method)
          Sets a method as beeing an empty wrapper
static void setAnnotatedNotEmpty(javassist.CtMethod method)
          Sets a method as beeing a non empty wrapper
static void setJoinPointIndex(javassist.CtClass klass, int index)
          Sets the join point index for the class.
static void setSerialVersionUID(javassist.CtClass clazz, long serialVerUid)
           
static void swapBodies(javassist.CtMethod methodA, javassist.CtMethod methodB)
          Swapp bodies of the two given methods of the same declaring class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavassistHelper

public JavassistHelper()
Method Detail

makeStatic

public static javassist.CtMethod makeStatic(javassist.CtClass returnType,
                                            String name,
                                            javassist.CtClass[] parameters,
                                            javassist.CtClass[] exceptions,
                                            String body,
                                            javassist.CtClass declaring)
                                     throws javassist.CannotCompileException
Helper method for bogus CtMethod.make in Javassist for static methods

Parameters:
returnType -
name -
parameters -
exceptions -
body -
declaring -
Returns:
new method
Throws:
javassist.CannotCompileException

getDefaultPrimitiveValue

public static String getDefaultPrimitiveValue(javassist.CtClass type)
Gets the default value for primitive types

Parameters:
type -
Returns:

hasMethod

public static boolean hasMethod(javassist.CtClass klass,
                                String methodName)
Checks if the given Class as already a method methodName Does not take into account the signature

Parameters:
klass -
methodName -
Returns:
true if klass has methodName

hasConstructor

public static boolean hasConstructor(javassist.CtClass klass,
                                     javassist.CtClass[] args)
Checks if the given Class as already a ctor with given signature

Parameters:
klass -
args -
Returns:
true if klass has ctor

hasField

public static boolean hasField(javassist.CtClass klass,
                               String fieldName)
Checks if the given Class as already a method methodName Does not take into account the signature

Parameters:
klass -
fieldName -
Returns:
true if klass has methodName

hasMethod

public static boolean hasMethod(javassist.CtClass klass,
                                String methodName,
                                javassist.CtClass[] args)
Checks if the given Class as already a method methodName.

Parameters:
klass -
methodName -
Returns:
true if klass has methodName

swapBodies

public static void swapBodies(javassist.CtMethod methodA,
                              javassist.CtMethod methodB)
Swapp bodies of the two given methods of the same declaring class

Parameters:
methodA -
methodB -

convertJavassistTypeSignatureToReflectTypeSignature

public static String convertJavassistTypeSignatureToReflectTypeSignature(String typeName)
Converts a Javassist type signature to a reflect type signature.

Since sucky Javassist does not use the standard.

Parameters:
typeName -
Returns:
@TODO does not support multi dimensional arrays, needs to be fixed

isAnnotatedEmpty

public static boolean isAnnotatedEmpty(javassist.CtMethod method)
Checks if a method is marked as an empty wrapper (runtime weaving)

Parameters:
method -
Returns:
true if empty wrapper

isAnnotatedNotEmpty

public static boolean isAnnotatedNotEmpty(javassist.CtMethod method)
Checks if a method is marked as a non empty wrapper (runtime unweaving)

Parameters:
method -
Returns:
true if non empty wrapper

setAnnotatedEmpty

public static void setAnnotatedEmpty(javassist.CtMethod method)
Sets a method as beeing an empty wrapper

Parameters:
method -

setAnnotatedNotEmpty

public static void setAnnotatedNotEmpty(javassist.CtMethod method)
Sets a method as beeing a non empty wrapper

Parameters:
method -

createEmptyWrapperMethod

public static javassist.CtMethod createEmptyWrapperMethod(javassist.CtClass ctClass,
                                                          javassist.CtMethod originalMethod,
                                                          int methodSequence)
                                                   throws javassist.NotFoundException,
                                                          javassist.CannotCompileException
Creates an empty wrapper method to allow HotSwap without schema change

TODO refactor PrepareTransformer CAUTION: does not check the wrapped method already exists while PrepareTransformer version does

Parameters:
ctClass - the ClassGen
originalMethod - the current method
methodSequence - the method hash
Returns:
the wrapper method
Throws:
javassist.NotFoundException
javassist.CannotCompileException

calculateSerialVerUid

public static long calculateSerialVerUid(javassist.CtClass clazz)
                                  throws javassist.CannotCompileException
Copy pasted from Javassist since it is a private method

Parameters:
clazz -
Returns:
@throws CannotCompileException
Throws:
javassist.CannotCompileException

setSerialVersionUID

public static void setSerialVersionUID(javassist.CtClass clazz,
                                       long serialVerUid)
                                throws javassist.CannotCompileException
Throws:
javassist.CannotCompileException

isSerialVerUidNeeded

public static boolean isSerialVerUidNeeded(javassist.CtClass clazz)
                                    throws javassist.NotFoundException
Throws:
javassist.NotFoundException

addAspectManagerField

public static void addAspectManagerField(javassist.CtClass ctClass,
                                         SystemDefinition definition,
                                         Context context)
                                  throws javassist.NotFoundException,
                                         javassist.CannotCompileException
Adds a new AspectManager field to the advised class.

Parameters:
ctClass -
definition -
Throws:
javassist.NotFoundException
javassist.CannotCompileException

addStaticClassField

public static void addStaticClassField(javassist.CtClass ctClass,
                                       Context context)
                                throws javassist.NotFoundException,
                                       javassist.CannotCompileException
Creates a new static class field.

Parameters:
ctClass - the class
Throws:
javassist.NotFoundException
javassist.CannotCompileException

addJoinPointManagerField

public static void addJoinPointManagerField(javassist.CtClass ctClass,
                                            SystemDefinition definition,
                                            Context context)
                                     throws javassist.NotFoundException,
                                            javassist.CannotCompileException
Adds a new JoinPointManager field to the advised class.

Parameters:
ctClass -
definition -
Throws:
javassist.NotFoundException
javassist.CannotCompileException

copyCustomAttributes

public static void copyCustomAttributes(javassist.CtBehavior copyTo,
                                        javassist.CtBehavior copyFrom)
Copies the custom attributes from one class to another.

Parameters:
copyTo -
copyFrom -

calculateHash

public static int calculateHash(javassist.CtField field)
                         throws javassist.NotFoundException
Calculate the hash for a javassist field.

Parameters:
field - the field
Returns:
the hash
Throws:
javassist.NotFoundException

calculateHash

public static int calculateHash(javassist.CtConstructor constructor)
                         throws javassist.NotFoundException
Calculate the hash for a javassist constructor.

Parameters:
constructor - the constructor
Returns:
the hash
Throws:
javassist.NotFoundException

calculateHash

public static int calculateHash(javassist.CtMethod method)
                         throws javassist.NotFoundException
Calculate the hash for a javassist method.

Parameters:
method - the method
Returns:
the hash
Throws:
javassist.NotFoundException

calculateHash

public static int calculateHash(javassist.CtClass ctClass)
                         throws javassist.NotFoundException
Calculate the hash for a class.

Parameters:
ctClass - the class
Returns:
the hash
Throws:
javassist.NotFoundException

createSortedMethodList

public static List createSortedMethodList(javassist.CtClass klass)
Creates a sorted method list of all the public methods in the class and super classes.

Parameters:
klass - the class with the methods
Returns:
the sorted method list

getJoinPointIndex

public static int getJoinPointIndex(javassist.CtClass klass)
Returrns the join point index for the class.

Parameters:
klass -
Returns:
the index

setJoinPointIndex

public static void setJoinPointIndex(javassist.CtClass klass,
                                     int index)
Sets the join point index for the class.

Parameters:
klass -
index -


Copyright © 2002-2004 Jonas Bonér, Alexandre Vasseur. All Rights Reserved.