Package org.codehaus.groovy.classgen.asm
Class BytecodeHelper
java.lang.Object
org.codehaus.groovy.classgen.asm.BytecodeHelper
A helper class for bytecode generation with AsmClassGenerator.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanDeprecated.static booleanDeprecated.static voidconvertPrimitiveToBoolean(org.objectweb.asm.MethodVisitor mv, ClassNode type) Converts a primitive type to boolean.static voidstatic voidstatic voiddoCastToPrimitive(org.objectweb.asm.MethodVisitor mv, ClassNode sourceType, ClassNode targetType) Given a wrapped number type (Byte, Integer, Short, ...), generates bytecode to convert it to a primitive number (int, long, double) using calls to wrapped.[targetType]Value()static voiddoCastToWrappedType(org.objectweb.asm.MethodVisitor mv, ClassNode sourceType, ClassNode targetType) Given a primitive number type (byte, integer, short, ...), generates bytecode to convert it to a wrapped number (Integer, Long, Double) using calls to [WrappedType].valueOfstatic voidstatic Stringreturns a name that Class.forName() can take.static Stringstatic StringgetClassInternalName(String name) static Stringstatic String[]getClassInternalNames(ClassNode[] names) static Stringarray types are special: eg.: String[]: classname: [Ljava.lang.String; Object: classname: java.lang.Object int[] : classname: [I unlike getTypeDescription '.' is not replaced by '/'.static StringgetGenericsBounds(ClassNode type) static Stringstatic Stringstatic StringgetMethodDescriptor(Class returnType, Class[] paramTypes) static StringgetMethodDescriptor(ClassNode returnType, ClassNode[] parameterTypes) static StringgetMethodDescriptor(ClassNode returnType, Parameter[] parameters) static StringgetMethodDescriptor(MethodNode methodNode) Returns a method descriptor for the givenMethodNode.static Stringstatic Stringarray types are special: eg.: String[]: classname: [Ljava/lang/String; int[]: [Istatic Stringstatic intComputes a hash code for a string.static booleanisClassLiteralPossible(ClassNode classNode) Tells if a class node is candidate for class literal bytecode optimization.static booleanReturns true if the two classes share the same compilation unit.static voidstatic voidnegateBoolean(org.objectweb.asm.MethodVisitor mv) Negate a boolean on stack.static voidpushConstant(org.objectweb.asm.MethodVisitor mv, int value) static voidstatic voidGenerates the bytecode to unbox the current value on the stack.static voidGenerates the bytecode to unbox the current value on the stack.static voidvisitClassLiteral(org.objectweb.asm.MethodVisitor mv, ClassNode classNode) Visits a class literal.
- 
Constructor Details- 
BytecodeHelperpublic BytecodeHelper()
 
- 
- 
Method Details- 
getClassInternalName- Returns:
- the ASM internal name of the type
 
- 
getClassInternalName- Returns:
- the ASM internal name of the type
 
- 
getClassInternalName- Returns:
- the ASM internal name of the type
 
- 
getMethodDescriptorReturns a method descriptor for the givenMethodNode.- Parameters:
- methodNode- the method node for which to create the descriptor
- Returns:
- a method descriptor as defined in section JVMS section 4.3.3
 
- 
getMethodDescriptor- Returns:
- the ASM method type descriptor
 
- 
getMethodDescriptor- Returns:
- the ASM method type descriptor
 
- 
getMethodDescriptor- Returns:
- the ASM method type descriptor
 
- 
getClassLoadingTypeDescriptionarray types are special: eg.: String[]: classname: [Ljava.lang.String; Object: classname: java.lang.Object int[] : classname: [I unlike getTypeDescription '.' is not replaced by '/'. it seems that makes problems for the class loading if '.' is replaced by '/'- Returns:
- the ASM type description for class loading
 
- 
getTypeDescription
- 
getTypeDescriptionarray types are special: eg.: String[]: classname: [Ljava/lang/String; int[]: [I- Returns:
- the ASM type description
 
- 
getClassInternalNames- Returns:
- an array of ASM internal names of the type
 
- 
pushConstantpublic static void pushConstant(org.objectweb.asm.MethodVisitor mv, int value) 
- 
negateBooleanpublic static void negateBoolean(org.objectweb.asm.MethodVisitor mv) Negate a boolean on stack.
- 
formatNameForClassLoadingreturns a name that Class.forName() can take. Notably for arrays: [I, [Ljava.lang.String; etc Regular object type: java.lang.String
- 
getGenericsMethodSignature
- 
getTypeGenericsSignature
- 
getGenericsSignature
- 
getGenericsBounds
- 
doCast
- 
doCastToPrimitivepublic static void doCastToPrimitive(org.objectweb.asm.MethodVisitor mv, ClassNode sourceType, ClassNode targetType) Given a wrapped number type (Byte, Integer, Short, ...), generates bytecode to convert it to a primitive number (int, long, double) using calls to wrapped.[targetType]Value()- Parameters:
- mv- method visitor
- sourceType- the wrapped number type
- targetType- the primitive target type
 
- 
doCastToWrappedTypepublic static void doCastToWrappedType(org.objectweb.asm.MethodVisitor mv, ClassNode sourceType, ClassNode targetType) Given a primitive number type (byte, integer, short, ...), generates bytecode to convert it to a wrapped number (Integer, Long, Double) using calls to [WrappedType].valueOf- Parameters:
- mv- method visitor
- sourceType- the primitive number type
- targetType- the wrapped target type
 
- 
doCast
- 
boxDeprecated.Generates the bytecode to autobox the current value on the stack.
- 
boxDeprecated.Generates the bytecode to autobox the current value on the stack.
- 
unboxGenerates the bytecode to unbox the current value on the stack.
- 
unboxGenerates the bytecode to unbox the current value on the stack.
- 
visitClassLiteralVisits a class literal. If the type of the classnode is a primitive type, the generated bytecode will be a GETSTATIC Integer.TYPE. If the classnode is not a primitive type, we will generate a LDC instruction.
- 
isClassLiteralPossibleTells if a class node is candidate for class literal bytecode optimization. If so, bytecode may use LDC instructions instead of static constant Class fields to retrieve class literals.- Parameters:
- classNode- the classnode for which we want to know if bytecode optimization is possible
- Returns:
- true if the bytecode can be optimized
 
- 
isSameCompilationUnitReturns true if the two classes share the same compilation unit.- Parameters:
- a- class a
- b- class b
- Returns:
- true if both classes share the same compilation unit
 
- 
hashCodeComputes a hash code for a string. The purpose of this hashcode is to be constant independently of the JDK being used.- Parameters:
- str- the string for which to compute the hashcode
- Returns:
- hashcode of the string
 
- 
convertPrimitiveToBooleanConverts a primitive type to boolean.- Parameters:
- mv- method visitor
- type- primitive type to convert
 
- 
doReturn
- 
load
- 
store
 
-