org.codehaus.aspectwerkz.transform
Class AsmHelper

java.lang.Object
  extended byorg.codehaus.aspectwerkz.transform.AsmHelper
All Implemented Interfaces:
org.objectweb.asm.Constants, TransformationConstants

public class AsmHelper
extends Object
implements org.objectweb.asm.Constants, TransformationConstants

Helper class with utility methods for the ASM library.

Author:
Jonas BonŽr , Alexandre Vasseur

Field Summary
static boolean IS_JAVA_5
          A boolean to check if we have a J2SE 5 support
static int JAVA_VERSION
           
 
Fields inherited from interface org.objectweb.asm.Constants
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5
 
Fields inherited from interface org.codehaus.aspectwerkz.transform.TransformationConstants
ASPECT_MANAGER_CLASS, ASPECT_MANAGER_FIELD, ASPECTWERKZ_PREFIX, BOOLEAN_CLASS_INIT_METHOD_SIGNATURE, BOOLEAN_CLASS_NAME, BOOLEAN_VALUE_METHOD_NAME, BOOLEAN_VALUE_METHOD_SIGNATURE, BYTE_CLASS_INIT_METHOD_SIGNATURE, BYTE_CLASS_NAME, BYTE_VALUE_METHOD_NAME, BYTE_VALUE_METHOD_SIGNATURE, CHAR_VALUE_METHOD_NAME, CHAR_VALUE_METHOD_SIGNATURE, CHARACTER_CLASS_INIT_METHOD_SIGNATURE, CHARACTER_CLASS_NAME, CLASS_CLASS, CLASS_CLASS_SIGNATURE, CLASS_LOADER_REFLECT_CLASS_NAME, CLASS_LOOKUP_METHOD, CLINIT_METHOD_NAME, CROSS_CUTTING_INFO_CLASS, CROSS_CUTTING_INFO_CLASS_FIELD, DEFINE_CLASS_METHOD_NAME, DELIMITER, DOUBLE_CLASS_INIT_METHOD_SIGNATURE, DOUBLE_CLASS_NAME, DOUBLE_VALUE_METHOD_NAME, DOUBLE_VALUE_METHOD_SIGNATURE, EMPTY_WRAPPER_ATTRIBUTE, EMPTY_WRAPPER_ATTRIBUTE_VALUE_EMPTY, EMPTY_WRAPPER_ATTRIBUTE_VALUE_NOTEMPTY, EMTPTY_ARRAY_LIST, FLOAT_CLASS_INIT_METHOD_SIGNATURE, FLOAT_CLASS_NAME, FLOAT_VALUE_METHOD_NAME, FLOAT_VALUE_METHOD_SIGNATURE, FOR_NAME_METHOD_NAME, FOR_NAME_METHOD_SIGNATURE, GET_ASPECT_MANAGER_METHOD, GET_JOIN_POINT_MANAGER, GET_JOIN_POINTS_EXECUTION_METHOD, GET_MIXIN_METHOD, GET_SYSTEM_METHOD, GETFIELD_WRAPPER_METHOD_PREFIX, HANDLER_JOIN_POINT_EXECUTION_METHOD, I, INIT_JOIN_POINTS_METHOD_NAME, INIT_METHOD_NAME, INLINED_JOIN_POINT_MANAGER_CLASS_NAME, INT_VALUE_METHOD_NAME, INT_VALUE_METHOD_SIGNATURE, INTEGER_CLASS_INIT_METHOD_SIGNATURE, INTEGER_CLASS_NAME, INVOKE_METHOD_NAME, INVOKE_MIXIN_METHOD, INVOKE_WRAPPER_METHOD_PREFIX, JOIN_POINT_BASE_CLASS_SUFFIX, JOIN_POINT_CLASS_SUFFIX, JOIN_POINT_INDEX_ATTRIBUTE, JOIN_POINT_MANAGER_CLASS, JOIN_POINT_MANAGER_FIELD, JOIN_POINT_PREFIX, JOIN_POINT_TYPE_CONSTRUCTOR_CALL, JOIN_POINT_TYPE_CONSTRUCTOR_EXECUTION, JOIN_POINT_TYPE_FIELD_GET, JOIN_POINT_TYPE_FIELD_SET, JOIN_POINT_TYPE_HANDLER, JOIN_POINT_TYPE_METHOD_CALL, JOIN_POINT_TYPE_METHOD_EXECUTION, JOIN_POINT_TYPE_STATIC_INITALIZATION, JOIN_POINTS_INIT_METHOD, L, LOAD_JOIN_POINT_METHOD_NAME, LOAD_JOIN_POINT_METHOD_SIGNATURE, LONG_CLASS_INIT_METHOD_SIGNATURE, LONG_CLASS_NAME, LONG_VALUE_METHOD_NAME, LONG_VALUE_METHOD_SIGNATURE, MIXIN_CLASS, NO_PARAMS_RETURN_VOID_METHOD_SIGNATURE, OBJECT_CLASS_NAME, OBJECT_CLASS_SIGNATURE, ORIGINAL_METHOD_PREFIX, PROCEED_WITH_CALL_JOIN_POINT_METHOD, PROCEED_WITH_EXECUTION_JOIN_POINT_METHOD, PROCEED_WITH_GET_JOIN_POINT_METHOD, PROCEED_WITH_HANDLER_JOIN_POINT_METHOD, PROCEED_WITH_SET_JOIN_POINT_METHOD, PUTFIELD_WRAPPER_METHOD_PREFIX, SEMICOLON, SERIAL_VERSION_UID_FIELD, SHORT_CLASS_INIT_METHOD_SIGNATURE, SHORT_CLASS_NAME, SHORT_VALUE_METHOD_NAME, SHORT_VALUE_METHOD_SIGNATURE, STATIC_CLASS_FIELD, SYSTEM_CLASS, SYSTEM_LOADER_CLASS, TARGET_CLASS_FIELD_NAME, THREAD_LOCAL_CLASS, THROWABLE_CLASS_NAME, UUID_EXECUTION_METHOD, WEAK_REFERENCE_CLASS, WRAPPER_METHOD_PREFIX
 
Constructor Summary
AsmHelper()
           
 
Method Summary
static int calculateClassHash(String declaringType)
          Calculates the class hash.
static int calculateConstructorHash(String desc)
          Calculates the constructor hash.
static int calculateFieldHash(String name, String desc)
          Calculates the field hash.
static int calculateMethodHash(String name, String desc)
          Calculates the method hash.
static String convertReflectDescToTypeDesc(String desc)
          Converts a java reflect type desc to ASM type desc.
static String convertTypeDescToReflectDesc(String typeDesc)
          Converts an ASM type descriptor" (I, [I, [Ljava/lang/String;, Ljava/lang/String;) to a Java.reflect one (int, [I, [Ljava.lang.String;, java.lang.String)
static org.objectweb.asm.Type[] getArgumentTypes(Constructor constructor)
          Gets the argument types for a constructor.
static String getConstructorDescriptor(Constructor constructor)
          Creates a constructor descriptor.
static String getMethodDescriptor(Method method)
          Creates a method descriptor.
static Class loadClass(ClassLoader loader, byte[] bytes, String name)
          Adds a class to a class loader and loads it.
static Class loadClass(ClassLoader loader, String name)
          Tries to load a class if unsuccessful returns null.
static void loadIntegerConstant(org.objectweb.asm.CodeVisitor cv, int index)
          Creates and adds the correct parameter index for integer types.
static org.objectweb.asm.ClassWriter newClassWriter(boolean computeMax)
          Factory method for ASM ClassWriter and J2SE 5 support See http://www.objectweb.org/wws/arc/asm/2004-08/msg00005.html
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_JAVA_5

public static final boolean IS_JAVA_5
A boolean to check if we have a J2SE 5 support


JAVA_VERSION

public static int JAVA_VERSION
Constructor Detail

AsmHelper

public AsmHelper()
Method Detail

newClassWriter

public static org.objectweb.asm.ClassWriter newClassWriter(boolean computeMax)
Factory method for ASM ClassWriter and J2SE 5 support See http://www.objectweb.org/wws/arc/asm/2004-08/msg00005.html

Parameters:
computeMax -
Returns:

getConstructorDescriptor

public static String getConstructorDescriptor(Constructor constructor)
Creates a constructor descriptor.

Parts of code in this method is taken from the ASM codebase.

Parameters:
constructor -
Returns:
the descriptor

getMethodDescriptor

public static String getMethodDescriptor(Method method)
Creates a method descriptor.

Parts of code in this method is taken from the ASM codebase.

Parameters:
method -
Returns:
the descriptor

getArgumentTypes

public static org.objectweb.asm.Type[] getArgumentTypes(Constructor constructor)
Gets the argument types for a constructor.

Parts of code in this method is taken from the ASM codebase.

Parameters:
constructor -
Returns:
the ASM argument types for the constructor

loadClass

public static Class loadClass(ClassLoader loader,
                              byte[] bytes,
                              String name)
Adds a class to a class loader and loads it.

Parameters:
loader - the class loader (if null the context class loader will be used)
bytes - the bytes for the class
name - the name of the class
Returns:
the class

loadClass

public static Class loadClass(ClassLoader loader,
                              String name)
Tries to load a class if unsuccessful returns null.

Parameters:
loader - the class loader
name - the name of the class
Returns:
the class

calculateMethodHash

public static int calculateMethodHash(String name,
                                      String desc)
Calculates the method hash. The computation MUST be the same as in ReflectHelper, thus we switch back the names to Java style. Note that for array type, Java.reflect is using "[Lpack.foo;" style unless primitive.

Parameters:
name -
desc -
Returns:

calculateConstructorHash

public static int calculateConstructorHash(String desc)
Calculates the constructor hash.

Parameters:
desc -
Returns:

calculateFieldHash

public static int calculateFieldHash(String name,
                                     String desc)
Calculates the field hash.

Parameters:
name -
desc -
Returns:

calculateClassHash

public static int calculateClassHash(String declaringType)
Calculates the class hash.

Parameters:
declaringType -
Returns:

convertTypeDescToReflectDesc

public static String convertTypeDescToReflectDesc(String typeDesc)
Converts an ASM type descriptor" (I, [I, [Ljava/lang/String;, Ljava/lang/String;) to a Java.reflect one (int, [I, [Ljava.lang.String;, java.lang.String)

Parameters:
typeDesc -
Returns:
the Java.reflect string representation

convertReflectDescToTypeDesc

public static String convertReflectDescToTypeDesc(String desc)
Converts a java reflect type desc to ASM type desc.

Parameters:
desc -
Returns:

loadIntegerConstant

public static void loadIntegerConstant(org.objectweb.asm.CodeVisitor cv,
                                       int index)
Creates and adds the correct parameter index for integer types.

Parameters:
cv -
index -


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