## org.codehaus.groovy.classgen
Class BytecodeHelper

A helper class for bytecode generation with AsmClassGenerator.

author:
  James Strachan

author:
  Bing Ran

author:
  Jochen Theodorou

version:
  $Revision: 8045 $

Field Summary
`MethodVisitor` | `mv`

Constructor Summary
`BytecodeHelper(MethodVisitor mv)`

Method Summary
`static void` | `addSubTypes(StringBuffer ret, def types, String start, String end)`
`void` | `box(Class type)` Generates the bytecode to autobox the current value on the stack
`void` | `box(ClassNode type)`
`void` | `boxBoolean()` convert boolean to Boolean
`static ClassNode` | `boxOnPrimitive(ClassNode type)`
`void` | `doCast(Class type)`
`void` | `doCast(ClassNode type)`
`void` | `doReturn(ClassNode returnType)`
`void` | `dup()`
`static String` | `formatNameForClassLoading(String name)` returns a name that Class.forName() can take.
`static String` | `getClassInternalName(ClassNode t)`
`static String` | `getClassInternalName(Class t)`
`static String` | `getClassInternalName(String name)`
`static def` | `getClassInternalNames(def names)`
`static String` | `getClassLoadingTypeDescription(ClassNode c)` array types are special: eg.: String[]: classname: [Ljava.lang.String; Object: classname: java.lang.Object int[] : classname: [I unlike getTypeDescription '.' is not replaced by '/'.
`static String` | `getGenericsBounds(ClassNode type)`
`static String` | `getGenericsMethodSignature(MethodNode node)`
`static String` | `getGenericsSignature(ClassNode node)`
`static void` | `getGenericsTypeSpec(StringBuffer ret, def genericsTypes)`
`static String` | `getMethodDescriptor(ClassNode returnType, def parameters)`
`static String` | `getMethodDescriptor(Class returnType, def paramTypes)`
`MethodVisitor` | `getMethodVisitor()`
`static String` | `getTypeDescription(Class c)`
`static String` | `getTypeDescription(ClassNode c)` array types are special: eg.: String[]: classname: [Ljava/lang/String; int[]: [I
`static String` | `getTypeDescription(ClassNode c, boolean end)` array types are special: eg.: String[]: classname: [Ljava/lang/String; int[]: [I
`static boolean` | `hasGenerics(def param)`
`void` | `load(ClassNode type, int idx)`
`void` | `load(Variable v)`
`void` | `loadConstant(Object value)` load the constant on the operand stack. primitives auto-boxed.
`void` | `loadVar(Variable variable)` load the value of the variable on the operand stack. unbox it if it's a reference
`void` | `mark(String msg)` load a message on the stack and remove it right away.
`void` | `negateBoolean()` negate a boolean on stack. true->false, false->true
`void` | `pushConstant(boolean value)`
`void` | `pushConstant(int value)`
`void` | `putField(FieldNode fld)`
`void` | `putField(FieldNode fld, String ownerName)`
`void` | `quickBoxIfNecessary(ClassNode type)` box the primitive value on the stack
`void` | `quickUnboxIfNecessary(ClassNode type)`
`void` | `store(Variable v, boolean markStart)`
`void` | `store(Variable v)`
`void` | `storeVar(Variable variable)`
`void` | `swapObjectWith(ClassNode type)`
`void` | `swapWithObject(ClassNode type)`
`void` | `unbox(Class type)` Generates the bytecode to unbox the current value on the stack
`void` | `unbox(ClassNode type)`
`static boolean` | `usesGenericsInClassSignature(ClassNode node)`
`static void` | `writeGenericsBoundType(StringBuffer ret, ClassNode printType, boolean writeInterfaceMarker)`
`static void` | `writeGenericsBounds(StringBuffer ret, GenericsType type, boolean writeInterfaceMarker)`

Constructor Detail

### BytecodeHelper

    public BytecodeHelper(MethodVisitor mv)

Method Detail

### addSubTypes

    static void addSubTypes(StringBuffer ret, def types, String start, String end)

### box

    public void box(Class type)

  Generates the bytecode to autobox the current value on the stack

### box

    public void box(ClassNode type)

### boxBoolean

    public void boxBoolean()

  convert boolean to Boolean

### boxOnPrimitive

    public static ClassNode boxOnPrimitive(ClassNode type)

### doCast

    public void doCast(Class type)

### doCast

    public void doCast(ClassNode type)

### doReturn

    public void doReturn(ClassNode returnType)

### dup

    public void dup()

### formatNameForClassLoading

    public static String formatNameForClassLoading(String name)

  returns a name that Class.forName() can take. Notablely for arrays: [I, [Ljava.lang.String; etc Regular object type: java.lang.String
  param:
    name

### getClassInternalName

    public static String getClassInternalName(ClassNode t)

### getClassInternalName

    public static String getClassInternalName(Class t)

### getClassInternalName

    public static String getClassInternalName(String name)

  return:
    the ASM internal name of the type

### getClassInternalNames

    public static def getClassInternalNames(def names)

  return:
    an array of ASM internal names of the type

### getClassLoadingTypeDescription

    public static String getClassLoadingTypeDescription(ClassNode c)

  array 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 '/'
  return:
    the ASM type description for class loading

### getGenericsBounds

    public static String getGenericsBounds(ClassNode type)

### getGenericsMethodSignature

    public static String getGenericsMethodSignature(MethodNode node)

### getGenericsSignature

    public static String getGenericsSignature(ClassNode node)

### getGenericsTypeSpec

    static void getGenericsTypeSpec(StringBuffer ret, def genericsTypes)

### getMethodDescriptor

    public static String getMethodDescriptor(ClassNode returnType, def parameters)

  return:
    the ASM method type descriptor

### getMethodDescriptor

    public static String getMethodDescriptor(Class returnType, def paramTypes)

  return:
    the ASM method type descriptor

### getMethodVisitor

    public MethodVisitor getMethodVisitor()

### getTypeDescription

    public static String getTypeDescription(Class c)

### getTypeDescription

    public static String getTypeDescription(ClassNode c)

  array types are special: eg.: String[]: classname: [Ljava/lang/String; int[]: [I
  return:
    the ASM type description

### getTypeDescription

    static String getTypeDescription(ClassNode c, boolean end)

  array types are special: eg.: String[]: classname: [Ljava/lang/String; int[]: [I
  return:
    the ASM type description

### hasGenerics

    static boolean hasGenerics(def param)

### load

    public void load(ClassNode type, int idx)

### load

    public void load(Variable v)

### loadConstant

    public void loadConstant(Object value)

  load the constant on the operand stack. primitives auto-boxed.

### loadVar

    public void loadVar(Variable variable)

  load the value of the variable on the operand stack. unbox it if it's a reference
  param:
    variable

### mark

    public void mark(String msg)

  load a message on the stack and remove it right away. Good for put a mark in the generated bytecode for debugging purpose.
  param:
    msg

### negateBoolean

    public void negateBoolean()

  negate a boolean on stack. true->false, false->true

### pushConstant

    void pushConstant(boolean value)

### pushConstant

    public void pushConstant(int value)

### putField

    public void putField(FieldNode fld)

### putField

    public void putField(FieldNode fld, String ownerName)

### quickBoxIfNecessary

    public void quickBoxIfNecessary(ClassNode type)

  box the primitive value on the stack
  param:
    type

### quickUnboxIfNecessary

    public void quickUnboxIfNecessary(ClassNode type)

### store

    public void store(Variable v, boolean markStart)

### store

    public void store(Variable v)

### storeVar

    public void storeVar(Variable variable)

### swapObjectWith

    public void swapObjectWith(ClassNode type)

### swapWithObject

    public void swapWithObject(ClassNode type)

### unbox

    public void unbox(Class type)

  Generates the bytecode to unbox the current value on the stack

### unbox

    public void unbox(ClassNode type)

### usesGenericsInClassSignature

    static boolean usesGenericsInClassSignature(ClassNode node)

### writeGenericsBoundType

    static void writeGenericsBoundType(StringBuffer ret, ClassNode printType, boolean writeInterfaceMarker)

### writeGenericsBounds

    static void writeGenericsBounds(StringBuffer ret, GenericsType type, boolean writeInterfaceMarker)