Overview | Package | Class | Deprecated | Index | Help
| Groovy 1.7.6
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.classgen
[Java] Class AsmClassGenerator

    java.lang.Object
      org.codehaus.groovy.ast.CodeVisitorSupport
          org.codehaus.groovy.ast.ClassCodeVisitorSupport
              org.codehaus.groovy.classgen.ClassGenerator
                  org.codehaus.groovy.classgen.AsmClassGenerator

    public class AsmClassGenerator
    extends ClassGenerator

Generates Java class versions of Groovy classes using ASM.

Authors:
  James Strachan
  Bing Ran
  Jochen Theodorou
  Alex Popescu
  Alex Tkachman

Version:
  \$Revision: 21147 \$

Field Summary
`static boolean` | `ASM_DEBUG`
`static boolean` | `CREATE_DEBUG_INFO`
`static boolean` | `CREATE_LINE_NUMBER_INFO`

Fields inherited from class ClassGenerator
asmJDKVersion, classLoader, innerClasses

Method Summary
`def` | `AsmClassGenerator(SourceUnit source, GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, ClassLoader classLoader, String sourceFile)`
`protected boolean` | `addInnerClass(ClassNode innerClass)`
`protected static int` | `argumentSize(Expression arguments)`
`protected boolean` | `argumentsUseStack(Expression arguments)` @return true if the given argument expression requires the stack, in which case the arguments are evaluated first, stored in the variable stack and then reloaded to make a method call
`protected static boolean` | `containsSpreadExpression(Expression arguments)`
`protected ClassNode` | `createClosureClass(ClosureExpression expression)`
`protected void` | `createInterfaceSyntheticStaticFields()`
`protected Expression` | `createReturnLHSExpression(Expression expression)` For assignment expressions, return a safe expression for the LHS we can use to return the value
`protected Expression` | `createReusableExpression(Expression expression)`
`protected void` | `createSyntheticStaticFields()`
`protected void` | `doConvertAndCast(ClassNode type, Expression expression, boolean ignoreAutoboxing, boolean forceCast, boolean coerce)` Casts to the given type unless it can be determined that the cast is unnecessary
`protected void` | `doConvertAndCast(ClassNode type)`
`protected void` | `doConvertAndCast(ClassNode type, boolean coerce)`
`protected boolean` | `emptyArguments(Expression arguments)`
`protected void` | `evaluateBinaryExpression(String method, BinaryExpression expression)`
`protected void` | `evaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression)`
`protected void` | `evaluateCompareTo(BinaryExpression expression)`
`protected void` | `evaluateEqual(BinaryExpression expression, boolean defineVariable)`
`protected void` | `evaluateExpression(Expression expression)` @param expression
`protected void` | `evaluateInstanceof(BinaryExpression expression)`
`protected void` | `evaluateLogicalAndExpression(BinaryExpression expression)`
`protected void` | `evaluateLogicalOrExpression(BinaryExpression expression)`
`protected void` | `evaluatePostfixMethod(String method, Expression expression)`
`protected void` | `evaluatePrefixMethod(String method, Expression expression)`
`protected int` | `getBytecodeVersion()`
`protected Parameter[]` | `getClosureSharedVariables(ClosureExpression ce)`
`protected CompileUnit` | `getCompileUnit()`
`protected ClassNode` | `getExpressionType(Expression expression)` @return if the type of the expression can be determined at compile time then this method returns the type - otherwise null
`protected ClassNode` | `getLHSType(Expression leftExpression)` Deduces the type name required for some casting
`static String` | `getMopMethodName(MethodNode method, boolean useThis)` creates a MOP method name from a method
`protected ClassNode` | `getOutermostClass()`
`protected SourceUnit` | `getSourceUnit()`
`protected boolean` | `isComparisonExpression(Expression expression)`
`protected boolean` | `isFieldOrVariable(String name)` @return true if the given name is a local variable or a field
`protected boolean` | `isGroovyObject(Expression objectExpression)`
`protected boolean` | `isInClosure()`
`protected boolean` | `isInClosureConstructor()`
`protected boolean` | `isInScriptBody()` @return true if we are in a script body, where all variables declared are no longer local variables but are properties
`static boolean` | `isMopMethod(String methodName)` method to determine if a method is a MOP method.
`protected boolean` | `isNotExplicitThisInClosure(boolean implicitThis)`
`protected boolean` | `isPopRequired(Expression expression)` @return true if this expression will have left a value on the stack that must be popped
`protected boolean` | `isStaticMethod()`
`protected boolean` | `isValidTypeForCast(ClassNode type)`
`void` | `loadInstanceField(FieldExpression fldExp)` RHS instance field. should move most of the code in the BytecodeHelper
`void` | `loadStaticField(FieldExpression fldExp)` @param fldExp
`protected void` | `loadThisOrOwner()` Loads either this object or if we're inside a closure then load the top level owner
`protected void` | `onLineNumber(ASTNode statement, String message)`
`protected void` | `processClassVariable(String name)`
`protected void` | `processFieldAccess(String name, FieldNode field, int steps)`
`protected void` | `processStackVariable(Variable variable, boolean useReferenceDirectly)`
`void` | `storeStaticField(FieldExpression expression)`
`void` | `storeThisInstanceField(FieldExpression expression)`
`static boolean` | `usesSuper(MethodCallExpression call)`
`static boolean` | `usesSuper(PropertyExpression pe)`
`protected void` | `visitAndAutoboxBoolean(Expression expression)`
`void` | `visitAnnotations(AnnotatedNode node)` Note: ignore it.
`void` | `visitArgumentlistExpression(ArgumentListExpression ale)`
`void` | `visitArrayExpression(ArrayExpression expression)`
`void` | `visitAssertStatement(AssertStatement statement)`
`void` | `visitAttributeExpression(AttributeExpression expression)`
`void` | `visitBinaryExpression(BinaryExpression expression)`
`void` | `visitBitwiseNegationExpression(BitwiseNegationExpression expression)`
`void` | `visitBlockStatement(BlockStatement block)`
`void` | `visitBooleanExpression(BooleanExpression expression)` return a primitive boolean value of the BooleanExpresion.
`void` | `visitBreakStatement(BreakStatement statement)`
`void` | `visitBytecodeExpression(BytecodeExpression cle)`
`void` | `visitBytecodeSequence(BytecodeSequence bytecodeSequence)`
`void` | `visitCaseStatement(CaseStatement statement)`
`void` | `visitCaseStatement(CaseStatement statement, int switchVariableIndex, org.objectweb.asm.Label thisLabel, org.objectweb.asm.Label nextLabel)`
`void` | `visitCastExpression(CastExpression castExpression)`
`void` | `visitClass(ClassNode classNode)`
`void` | `visitClassExpression(ClassExpression expression)` load class object on stack
`void` | `visitClosureExpression(ClosureExpression expression)`
`void` | `visitClosureListExpression(ClosureListExpression expression)`
`void` | `visitConstantExpression(ConstantExpression expression)` Generate byte code for constants
`void` | `visitConstructor(ConstructorNode node)`
`void` | `visitConstructorCallExpression(ConstructorCallExpression call)`
`protected void` | `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
`void` | `visitContinueStatement(ContinueStatement statement)`
`void` | `visitDeclarationExpression(DeclarationExpression expression)`
`void` | `visitDoWhileLoop(DoWhileStatement loop)`
`void` | `visitExpressionStatement(ExpressionStatement statement)`
`void` | `visitField(FieldNode fieldNode)`
`void` | `visitFieldExpression(FieldExpression expression)`
`void` | `visitForLoop(ForStatement loop)`
`void` | `visitGStringExpression(GStringExpression expression)`
`void` | `visitGenericType(GenericsType genericsType)`
`void` | `visitIfElse(IfStatement ifElse)`
`void` | `visitListExpression(ListExpression expression)`
`void` | `visitMapEntryExpression(MapEntryExpression expression)`
`void` | `visitMapExpression(MapExpression expression)`
`void` | `visitMethod(MethodNode node)`
`void` | `visitMethodCallExpression(MethodCallExpression call)`
`void` | `visitMethodPointerExpression(MethodPointerExpression expression)`
`void` | `visitNotExpression(NotExpression expression)`
`protected void` | `visitOuterFieldExpression(FieldExpression expression, ClassNode outerClassNode, int steps, boolean first)`
`void` | `visitPostfixExpression(PostfixExpression expression)`
`void` | `visitPrefixExpression(PrefixExpression expression)`
`void` | `visitProperty(PropertyNode statement)`
`void` | `visitPropertyExpression(PropertyExpression expression)`
`void` | `visitRangeExpression(RangeExpression expression)`
`void` | `visitRegexExpression(RegexExpression expression)`
`void` | `visitReturnStatement(ReturnStatement statement)`
`void` | `visitSpreadExpression(SpreadExpression expression)`
`void` | `visitSpreadMapExpression(SpreadMapExpression expression)`
`protected void` | `visitStatement(Statement statement)`
`void` | `visitStaticMethodCallExpression(StaticMethodCallExpression call)`
`void` | `visitSwitch(SwitchStatement statement)`
`void` | `visitSynchronizedStatement(SynchronizedStatement statement)`
`void` | `visitTernaryExpression(TernaryExpression expression)`
`void` | `visitThrowStatement(ThrowStatement statement)`
`void` | `visitTryCatchFinally(TryCatchStatement statement)`
`void` | `visitTupleExpression(TupleExpression expression)`
`void` | `visitUnaryMinusExpression(UnaryMinusExpression expression)`
`void` | `visitUnaryPlusExpression(UnaryPlusExpression expression)`
`void` | `visitVariableExpression(VariableExpression expression)` Visits a bare (unqualified) variable expression.
`void` | `visitWhileLoop(WhileStatement loop)`

Methods inherited from class ClassGenerator
getClassLoader, getInnerClasses, getSourceUnit, visitBytecodeSequence

Methods inherited from class ClassCodeVisitorSupport
addError, getSourceUnit, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitVariableExpression, visitWhileLoop

Methods inherited from class CodeVisitorSupport
visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitListExpression, visitListOfExpressions, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitRegexExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop

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

Field Detail

### ASM_DEBUG

    public static final boolean ASM_DEBUG

### CREATE_DEBUG_INFO

    public static final boolean CREATE_DEBUG_INFO

### CREATE_LINE_NUMBER_INFO

    public static final boolean CREATE_LINE_NUMBER_INFO

Method Detail

### AsmClassGenerator

    public def AsmClassGenerator(SourceUnit source, GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, ClassLoader classLoader, String sourceFile)

### addInnerClass

    protected boolean addInnerClass(ClassNode innerClass)

### argumentSize

    protected static int argumentSize(Expression arguments)

### argumentsUseStack

    protected boolean argumentsUseStack(Expression arguments)

  Returns:
    true if the given argument expression requires the stack, in which case the arguments are evaluated first, stored in the variable stack and then reloaded to make a method call

### containsSpreadExpression

    protected static boolean containsSpreadExpression(Expression arguments)

### createClosureClass

    protected ClassNode createClosureClass(ClosureExpression expression)

### createInterfaceSyntheticStaticFields

    protected void createInterfaceSyntheticStaticFields()

### createReturnLHSExpression

    protected Expression createReturnLHSExpression(Expression expression)

  For assignment expressions, return a safe expression for the LHS we can use to return the value

### createReusableExpression

    protected Expression createReusableExpression(Expression expression)

### createSyntheticStaticFields

    protected void createSyntheticStaticFields()

### doConvertAndCast

    protected void doConvertAndCast(ClassNode type, Expression expression, boolean ignoreAutoboxing, boolean forceCast, boolean coerce)

  Casts to the given type unless it can be determined that the cast is unnecessary

### doConvertAndCast

    protected void doConvertAndCast(ClassNode type)

### doConvertAndCast

    protected void doConvertAndCast(ClassNode type, boolean coerce)

### emptyArguments

    protected boolean emptyArguments(Expression arguments)

### evaluateBinaryExpression

    protected void evaluateBinaryExpression(String method, BinaryExpression expression)

### evaluateBinaryExpressionWithAssignment

    protected void evaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression)

### evaluateCompareTo

    protected void evaluateCompareTo(BinaryExpression expression)

### evaluateEqual

    protected void evaluateEqual(BinaryExpression expression, boolean defineVariable)

### evaluateExpression

    protected void evaluateExpression(Expression expression)

  Parameters:
    expression

### evaluateInstanceof

    protected void evaluateInstanceof(BinaryExpression expression)

### evaluateLogicalAndExpression

    protected void evaluateLogicalAndExpression(BinaryExpression expression)

### evaluateLogicalOrExpression

    protected void evaluateLogicalOrExpression(BinaryExpression expression)

### evaluatePostfixMethod

    protected void evaluatePostfixMethod(String method, Expression expression)

### evaluatePrefixMethod

    protected void evaluatePrefixMethod(String method, Expression expression)

### getBytecodeVersion

    protected int getBytecodeVersion()

### getClosureSharedVariables

    protected Parameter[] getClosureSharedVariables(ClosureExpression ce)

### getCompileUnit

    protected CompileUnit getCompileUnit()

### getExpressionType

    protected ClassNode getExpressionType(Expression expression)

  Returns:
    if the type of the expression can be determined at compile time then this method returns the type - otherwise null

### getLHSType

    protected ClassNode getLHSType(Expression leftExpression)

  Deduces the type name required for some casting
  Returns:
    the type of the given (LHS) expression or null if it is java.lang.Object or it cannot be deduced

### getMopMethodName

    public static String getMopMethodName(MethodNode method, boolean useThis)

  creates a MOP method name from a method
  Parameters:
    `method` - the method to be called by the mop method
    `useThis` - if true, then it is a call on "this", "super" else
  Returns:
    the mop method name

### getOutermostClass

    protected ClassNode getOutermostClass()

### getSourceUnit

    protected SourceUnit getSourceUnit()

### isComparisonExpression

    protected boolean isComparisonExpression(Expression expression)

### isFieldOrVariable

    protected boolean isFieldOrVariable(String name)

  Returns:
    true if the given name is a local variable or a field

### isGroovyObject

    protected boolean isGroovyObject(Expression objectExpression)

### isInClosure

    protected boolean isInClosure()

### isInClosureConstructor

    protected boolean isInClosureConstructor()

### isInScriptBody

    protected boolean isInScriptBody()

  Returns:
    true if we are in a script body, where all variables declared are no longer local variables but are properties

### isMopMethod

    public static boolean isMopMethod(String methodName)

  method to determine if a method is a MOP method. This is done by the method name. If the name starts with "this$" or "super$" but does not contain "$dist$", then it is an MOP method
  Parameters:
    `methodName` - name of the method to test
  Returns:
    true if the method is a MOP method

### isNotExplicitThisInClosure

    protected boolean isNotExplicitThisInClosure(boolean implicitThis)

### isPopRequired

    protected boolean isPopRequired(Expression expression)

  Returns:
    true if this expression will have left a value on the stack that must be popped

### isStaticMethod

    protected boolean isStaticMethod()

### isValidTypeForCast

    protected boolean isValidTypeForCast(ClassNode type)

### loadInstanceField

    public void loadInstanceField(FieldExpression fldExp)

  RHS instance field. should move most of the code in the BytecodeHelper
  Parameters:
    fldExp

### loadStaticField

    public void loadStaticField(FieldExpression fldExp)

  Parameters:
    fldExp

### loadThisOrOwner

    protected void loadThisOrOwner()

  Loads either this object or if we're inside a closure then load the top level owner

### onLineNumber

    protected void onLineNumber(ASTNode statement, String message)

### processClassVariable

    protected void processClassVariable(String name)

### processFieldAccess

    protected void processFieldAccess(String name, FieldNode field, int steps)

### processStackVariable

    protected void processStackVariable(Variable variable, boolean useReferenceDirectly)

### storeStaticField

    public void storeStaticField(FieldExpression expression)

### storeThisInstanceField

    public void storeThisInstanceField(FieldExpression expression)

### usesSuper

    public static boolean usesSuper(MethodCallExpression call)

### usesSuper

    public static boolean usesSuper(PropertyExpression pe)

### visitAndAutoboxBoolean

    protected void visitAndAutoboxBoolean(Expression expression)

### visitAnnotations

    public void visitAnnotations(AnnotatedNode node)

  Note: ignore it. Annotation generation needs the current visitor.

### visitArgumentlistExpression

    public void visitArgumentlistExpression(ArgumentListExpression ale)

### visitArrayExpression

    public void visitArrayExpression(ArrayExpression expression)

### visitAssertStatement

    public void visitAssertStatement(AssertStatement statement)

### visitAttributeExpression

    public void visitAttributeExpression(AttributeExpression expression)

### visitBinaryExpression

    public void visitBinaryExpression(BinaryExpression expression)

### visitBitwiseNegationExpression

    public void visitBitwiseNegationExpression(BitwiseNegationExpression expression)

### visitBlockStatement

    public void visitBlockStatement(BlockStatement block)

### visitBooleanExpression

    public void visitBooleanExpression(BooleanExpression expression)

  return a primitive boolean value of the BooleanExpresion.
  Parameters:
    expression

### visitBreakStatement

    public void visitBreakStatement(BreakStatement statement)

### visitBytecodeExpression

    public void visitBytecodeExpression(BytecodeExpression cle)

### visitBytecodeSequence

    public void visitBytecodeSequence(BytecodeSequence bytecodeSequence)

### visitCaseStatement

    public void visitCaseStatement(CaseStatement statement)

### visitCaseStatement

    public void visitCaseStatement(CaseStatement statement, int switchVariableIndex, org.objectweb.asm.Label thisLabel, org.objectweb.asm.Label nextLabel)

### visitCastExpression

    public void visitCastExpression(CastExpression castExpression)

### visitClass

    public void visitClass(ClassNode classNode)

### visitClassExpression

    public void visitClassExpression(ClassExpression expression)

  load class object on stack

### visitClosureExpression

    public void visitClosureExpression(ClosureExpression expression)

### visitClosureListExpression

    public void visitClosureListExpression(ClosureListExpression expression)

### visitConstantExpression

    public void visitConstantExpression(ConstantExpression expression)

  Generate byte code for constants
  See Also:

### visitConstructor

    public void visitConstructor(ConstructorNode node)

### visitConstructorCallExpression

    public void visitConstructorCallExpression(ConstructorCallExpression call)

### visitConstructorOrMethod

    protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)

### visitContinueStatement

    public void visitContinueStatement(ContinueStatement statement)

### visitDeclarationExpression

    public void visitDeclarationExpression(DeclarationExpression expression)

### visitDoWhileLoop

    public void visitDoWhileLoop(DoWhileStatement loop)

### visitExpressionStatement

    public void visitExpressionStatement(ExpressionStatement statement)

### visitField

    public void visitField(FieldNode fieldNode)

### visitFieldExpression

    public void visitFieldExpression(FieldExpression expression)

### visitForLoop

    public void visitForLoop(ForStatement loop)

### visitGStringExpression

    public void visitGStringExpression(GStringExpression expression)

### visitGenericType

    public void visitGenericType(GenericsType genericsType)

### visitIfElse

    public void visitIfElse(IfStatement ifElse)

### visitListExpression

    public void visitListExpression(ListExpression expression)

### visitMapEntryExpression

    public void visitMapEntryExpression(MapEntryExpression expression)

### visitMapExpression

    public void visitMapExpression(MapExpression expression)

### visitMethod

    public void visitMethod(MethodNode node)

### visitMethodCallExpression

    public void visitMethodCallExpression(MethodCallExpression call)

### visitMethodPointerExpression

    public void visitMethodPointerExpression(MethodPointerExpression expression)

### visitNotExpression

    public void visitNotExpression(NotExpression expression)

### visitOuterFieldExpression

    protected void visitOuterFieldExpression(FieldExpression expression, ClassNode outerClassNode, int steps, boolean first)

### visitPostfixExpression

    public void visitPostfixExpression(PostfixExpression expression)

### visitPrefixExpression

    public void visitPrefixExpression(PrefixExpression expression)

### visitProperty

    public void visitProperty(PropertyNode statement)

### visitPropertyExpression

    public void visitPropertyExpression(PropertyExpression expression)

### visitRangeExpression

    public void visitRangeExpression(RangeExpression expression)

### visitRegexExpression

    @Deprecated
    public void visitRegexExpression(RegexExpression expression)

### visitReturnStatement

    public void visitReturnStatement(ReturnStatement statement)

### visitSpreadExpression

    public void visitSpreadExpression(SpreadExpression expression)

### visitSpreadMapExpression

    public void visitSpreadMapExpression(SpreadMapExpression expression)

### visitStatement

    protected void visitStatement(Statement statement)

### visitStaticMethodCallExpression

    public void visitStaticMethodCallExpression(StaticMethodCallExpression call)

### visitSwitch

    public void visitSwitch(SwitchStatement statement)

### visitSynchronizedStatement

    public void visitSynchronizedStatement(SynchronizedStatement statement)

### visitTernaryExpression

    public void visitTernaryExpression(TernaryExpression expression)

### visitThrowStatement

    public void visitThrowStatement(ThrowStatement statement)

### visitTryCatchFinally

    public void visitTryCatchFinally(TryCatchStatement statement)

### visitTupleExpression

    public void visitTupleExpression(TupleExpression expression)

### visitUnaryMinusExpression

    public void visitUnaryMinusExpression(UnaryMinusExpression expression)

### visitUnaryPlusExpression

    public void visitUnaryPlusExpression(UnaryPlusExpression expression)

### visitVariableExpression

    public void visitVariableExpression(VariableExpression expression)

  Visits a bare (unqualified) variable expression.

### visitWhileLoop

    public void visitWhileLoop(WhileStatement loop)

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