Groovy 1.7.9

org.codehaus.groovy.classgen
[Java] Class BytecodeHelper

java.lang.Object
  org.codehaus.groovy.classgen.BytecodeHelper
All Implemented Interfaces:
org.objectweb.asm.Opcodes

public class BytecodeHelper
extends Object

A helper class for bytecode generation with AsmClassGenerator.

Authors:
James Strachan
Bing Ran
Jochen Theodorou
Version:
\$Revision: 21030 \$


Constructor Summary
BytecodeHelper(org.objectweb.asm.MethodVisitor mv)

 
Method Summary
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)

@return the ASM internal name of the type

static String[] getClassInternalNames(ClassNode[] names)

@return an array of ASM internal names of the type

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 String getMethodDescriptor(ClassNode returnType, Parameter[] parameters)

@return the ASM method type descriptor

static String getMethodDescriptor(Class returnType, Class[] paramTypes)

@return the ASM method type descriptor

org.objectweb.asm.MethodVisitor getMethodVisitor()

static String getTypeDescription(Class c)

static String getTypeDescription(ClassNode c)

array types are special: eg.: String[]: classname: [Ljava/lang/String; int[]: [I

void load(ClassNode type, int idx)

void load(Variable v)

void loadVar(Variable variable)

todo it would be more efficient to generate class constants

void loadVar(Variable variable, boolean useReferenceDirectly)

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

protected 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)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

BytecodeHelper

public BytecodeHelper(org.objectweb.asm.MethodVisitor mv)


 
Method Detail

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
Parameters:
name


getClassInternalName

public static String getClassInternalName(ClassNode t)


getClassInternalName

public static String getClassInternalName(Class t)


getClassInternalName

public static String getClassInternalName(String name)
Returns:
the ASM internal name of the type


getClassInternalNames

public static String[] getClassInternalNames(ClassNode[] names)
Returns:
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 '/'
Returns:
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)


getMethodDescriptor

public static String getMethodDescriptor(ClassNode returnType, Parameter[] parameters)
Returns:
the ASM method type descriptor


getMethodDescriptor

public static String getMethodDescriptor(Class returnType, Class[] paramTypes)
Returns:
the ASM method type descriptor


getMethodVisitor

public org.objectweb.asm.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
Returns:
the ASM type description


load

public void load(ClassNode type, int idx)


load

public void load(Variable v)


loadVar

public void loadVar(Variable variable)
todo it would be more efficient to generate class constants


loadVar

public void loadVar(Variable variable, boolean useReferenceDirectly)
load the value of the variable on the operand stack. unbox it if it's a reference
Parameters:
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.
Parameters:
msg


negateBoolean

public void negateBoolean()
negate a boolean on stack. true->false, false->true


pushConstant

protected 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
Parameters:
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)


 

Copyright © 2003-2010 The Codehaus. All rights reserved.