Package org.codehaus.groovy.classgen
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
-
- All Implemented Interfaces:
GroovyClassVisitor
,GroovyCodeVisitor
,ErrorCollecting
,org.objectweb.asm.Opcodes
public class AsmClassGenerator extends ClassGenerator
Generates Java class versions of Groovy classes using ASM.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
ASM_DEBUG
static boolean
CREATE_DEBUG_INFO
static boolean
CREATE_LINE_NUMBER_INFO
static MethodCallerMultiAdapter
getField
static MethodCallerMultiAdapter
getGroovyObjectField
static String
MINIMUM_BYTECODE_VERSION
static MethodCallerMultiAdapter
setField
static MethodCallerMultiAdapter
setGroovyObjectField
static MethodCallerMultiAdapter
setProperty
-
Fields inherited from class org.codehaus.groovy.classgen.ClassGenerator
innerClasses
-
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_RECORD, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM4, ASM5, ASM6, ASM7, ASM8, ASM9_EXPERIMENTAL, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, 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, INTEGER, INVOKEDYNAMIC, 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, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SOURCE_DEPRECATED, SOURCE_MASK, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V13, V14, V15, V9
-
-
Constructor Summary
Constructors Constructor Description AsmClassGenerator(SourceUnit source, GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, String sourceFile)
-
Method Summary
-
Methods inherited from class org.codehaus.groovy.classgen.ClassGenerator
getInnerClasses
-
Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport
addError, visitClassCodeContainer, visitImports, visitObjectInitializerStatements, visitPackage
-
Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
visitEmptyStatement, visitListOfExpressions, visitShortTernaryExpression
-
-
-
-
Field Detail
-
setField
public static final MethodCallerMultiAdapter setField
-
getField
public static final MethodCallerMultiAdapter getField
-
setGroovyObjectField
public static final MethodCallerMultiAdapter setGroovyObjectField
-
getGroovyObjectField
public static final MethodCallerMultiAdapter getGroovyObjectField
-
setProperty
public static final MethodCallerMultiAdapter setProperty
-
CREATE_DEBUG_INFO
public static final boolean CREATE_DEBUG_INFO
- See Also:
- Constant Field Values
-
CREATE_LINE_NUMBER_INFO
public static final boolean CREATE_LINE_NUMBER_INFO
- See Also:
- Constant Field Values
-
ASM_DEBUG
public static final boolean ASM_DEBUG
- See Also:
- Constant Field Values
-
MINIMUM_BYTECODE_VERSION
public static final String MINIMUM_BYTECODE_VERSION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AsmClassGenerator
public AsmClassGenerator(SourceUnit source, GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, String sourceFile)
-
-
Method Detail
-
getSourceUnit
public SourceUnit getSourceUnit()
- Overrides:
getSourceUnit
in classClassGenerator
-
getController
public WriterController getController()
-
visitClass
public void visitClass(ClassNode classNode)
Description copied from interface:GroovyClassVisitor
Visit a ClassNode.- Specified by:
visitClass
in interfaceGroovyClassVisitor
- Overrides:
visitClass
in classClassCodeVisitorSupport
-
visitGenericType
public void visitGenericType(GenericsType genericsType)
-
visitConstructorOrMethod
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)
- Overrides:
visitConstructorOrMethod
in classClassCodeVisitorSupport
-
visitConstructor
public void visitConstructor(ConstructorNode node)
Description copied from interface:GroovyClassVisitor
Visit a ConstructorNode.- Specified by:
visitConstructor
in interfaceGroovyClassVisitor
- Overrides:
visitConstructor
in classClassCodeVisitorSupport
-
visitMethod
public void visitMethod(MethodNode node)
Description copied from interface:GroovyClassVisitor
Visit a MethodNode.- Specified by:
visitMethod
in interfaceGroovyClassVisitor
- Overrides:
visitMethod
in classClassCodeVisitorSupport
-
visitField
public void visitField(FieldNode fieldNode)
Description copied from interface:GroovyClassVisitor
Visit a FieldNode.- Specified by:
visitField
in interfaceGroovyClassVisitor
- Overrides:
visitField
in classClassCodeVisitorSupport
-
visitProperty
public void visitProperty(PropertyNode statement)
Description copied from interface:GroovyClassVisitor
Visit a PropertyNode.- Specified by:
visitProperty
in interfaceGroovyClassVisitor
- Overrides:
visitProperty
in classClassCodeVisitorSupport
-
visitStatement
protected void visitStatement(Statement statement)
- Overrides:
visitStatement
in classClassCodeVisitorSupport
-
visitCatchStatement
public void visitCatchStatement(CatchStatement statement)
- Specified by:
visitCatchStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitCatchStatement
in classClassCodeVisitorSupport
-
visitBlockStatement
public void visitBlockStatement(BlockStatement block)
- Specified by:
visitBlockStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitBlockStatement
in classClassCodeVisitorSupport
-
visitForLoop
public void visitForLoop(ForStatement loop)
- Specified by:
visitForLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitForLoop
in classClassCodeVisitorSupport
-
visitWhileLoop
public void visitWhileLoop(WhileStatement loop)
- Specified by:
visitWhileLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitWhileLoop
in classClassCodeVisitorSupport
-
visitDoWhileLoop
public void visitDoWhileLoop(DoWhileStatement loop)
- Specified by:
visitDoWhileLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitDoWhileLoop
in classClassCodeVisitorSupport
-
visitIfElse
public void visitIfElse(IfStatement ifElse)
- Specified by:
visitIfElse
in interfaceGroovyCodeVisitor
- Overrides:
visitIfElse
in classClassCodeVisitorSupport
-
visitAssertStatement
public void visitAssertStatement(AssertStatement statement)
- Specified by:
visitAssertStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitAssertStatement
in classClassCodeVisitorSupport
-
visitTryCatchFinally
public void visitTryCatchFinally(TryCatchStatement statement)
- Specified by:
visitTryCatchFinally
in interfaceGroovyCodeVisitor
- Overrides:
visitTryCatchFinally
in classClassCodeVisitorSupport
-
visitSwitch
public void visitSwitch(SwitchStatement statement)
- Specified by:
visitSwitch
in interfaceGroovyCodeVisitor
- Overrides:
visitSwitch
in classClassCodeVisitorSupport
-
visitCaseStatement
public void visitCaseStatement(CaseStatement statement)
- Specified by:
visitCaseStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitCaseStatement
in classClassCodeVisitorSupport
-
visitBreakStatement
public void visitBreakStatement(BreakStatement statement)
- Specified by:
visitBreakStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitBreakStatement
in classClassCodeVisitorSupport
-
visitContinueStatement
public void visitContinueStatement(ContinueStatement statement)
- Specified by:
visitContinueStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitContinueStatement
in classClassCodeVisitorSupport
-
visitSynchronizedStatement
public void visitSynchronizedStatement(SynchronizedStatement statement)
- Specified by:
visitSynchronizedStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitSynchronizedStatement
in classClassCodeVisitorSupport
-
visitThrowStatement
public void visitThrowStatement(ThrowStatement statement)
- Specified by:
visitThrowStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitThrowStatement
in classClassCodeVisitorSupport
-
visitReturnStatement
public void visitReturnStatement(ReturnStatement statement)
- Specified by:
visitReturnStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitReturnStatement
in classClassCodeVisitorSupport
-
visitExpressionStatement
public void visitExpressionStatement(ExpressionStatement statement)
- Specified by:
visitExpressionStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitExpressionStatement
in classClassCodeVisitorSupport
-
visitTernaryExpression
public void visitTernaryExpression(TernaryExpression expression)
- Specified by:
visitTernaryExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitTernaryExpression
in classCodeVisitorSupport
-
visitDeclarationExpression
public void visitDeclarationExpression(DeclarationExpression expression)
- Specified by:
visitDeclarationExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitDeclarationExpression
in classClassCodeVisitorSupport
-
visitBinaryExpression
public void visitBinaryExpression(BinaryExpression expression)
- Specified by:
visitBinaryExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitBinaryExpression
in classCodeVisitorSupport
-
visitPostfixExpression
public void visitPostfixExpression(PostfixExpression expression)
- Specified by:
visitPostfixExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitPostfixExpression
in classCodeVisitorSupport
-
throwException
public void throwException(String s)
-
visitPrefixExpression
public void visitPrefixExpression(PrefixExpression expression)
- Specified by:
visitPrefixExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitPrefixExpression
in classCodeVisitorSupport
-
visitClosureExpression
public void visitClosureExpression(ClosureExpression expression)
- Specified by:
visitClosureExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitClosureExpression
in classCodeVisitorSupport
-
loadThisOrOwner
protected void loadThisOrOwner()
Loads either this object or if we're inside a closure then load the top level owner
-
visitConstantExpression
public void visitConstantExpression(ConstantExpression expression)
Generate byte code for constants- Specified by:
visitConstantExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitConstantExpression
in classCodeVisitorSupport
- See Also:
- Class field types
-
visitSpreadExpression
public void visitSpreadExpression(SpreadExpression expression)
- Specified by:
visitSpreadExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitSpreadExpression
in classCodeVisitorSupport
-
visitSpreadMapExpression
public void visitSpreadMapExpression(SpreadMapExpression expression)
- Specified by:
visitSpreadMapExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitSpreadMapExpression
in classCodeVisitorSupport
-
visitMethodPointerExpression
public void visitMethodPointerExpression(MethodPointerExpression expression)
- Specified by:
visitMethodPointerExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitMethodPointerExpression
in classCodeVisitorSupport
-
visitUnaryMinusExpression
public void visitUnaryMinusExpression(UnaryMinusExpression expression)
- Specified by:
visitUnaryMinusExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitUnaryMinusExpression
in classCodeVisitorSupport
-
visitUnaryPlusExpression
public void visitUnaryPlusExpression(UnaryPlusExpression expression)
- Specified by:
visitUnaryPlusExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitUnaryPlusExpression
in classCodeVisitorSupport
-
visitBitwiseNegationExpression
public void visitBitwiseNegationExpression(BitwiseNegationExpression expression)
- Specified by:
visitBitwiseNegationExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitBitwiseNegationExpression
in classCodeVisitorSupport
-
visitCastExpression
public void visitCastExpression(CastExpression castExpression)
- Specified by:
visitCastExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitCastExpression
in classCodeVisitorSupport
-
visitNotExpression
public void visitNotExpression(NotExpression expression)
- Specified by:
visitNotExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitNotExpression
in classCodeVisitorSupport
-
visitBooleanExpression
public void visitBooleanExpression(BooleanExpression expression)
- Specified by:
visitBooleanExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitBooleanExpression
in classCodeVisitorSupport
-
visitMethodCallExpression
public void visitMethodCallExpression(MethodCallExpression call)
- Specified by:
visitMethodCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitMethodCallExpression
in classCodeVisitorSupport
-
emptyArguments
protected boolean emptyArguments(Expression arguments)
-
containsSpreadExpression
public static boolean containsSpreadExpression(Expression arguments)
-
argumentSize
public static int argumentSize(Expression arguments)
-
visitStaticMethodCallExpression
public void visitStaticMethodCallExpression(StaticMethodCallExpression call)
- Specified by:
visitStaticMethodCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitStaticMethodCallExpression
in classCodeVisitorSupport
-
isNullConstant
@Deprecated public static boolean isNullConstant(Expression expr)
Deprecated.
-
visitConstructorCallExpression
public void visitConstructorCallExpression(ConstructorCallExpression call)
- Specified by:
visitConstructorCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitConstructorCallExpression
in classCodeVisitorSupport
-
isFieldDirectlyAccessible
public static boolean isFieldDirectlyAccessible(FieldNode field, ClassNode clazz)
Determines if the given class can directly access the given field (viaGETFIELD
,GETSTATIC
, etc. bytecode instructions).
-
getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper
public static FieldNode getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper(ClassNode accessingNode, ClassNode current, String fieldName, boolean skipCurrent)
-
visitPropertyExpression
public void visitPropertyExpression(PropertyExpression expression)
- Specified by:
visitPropertyExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitPropertyExpression
in classCodeVisitorSupport
-
visitAttributeExpression
public void visitAttributeExpression(AttributeExpression expression)
- Specified by:
visitAttributeExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitAttributeExpression
in classCodeVisitorSupport
-
visitFieldExpression
public void visitFieldExpression(FieldExpression expression)
- Specified by:
visitFieldExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitFieldExpression
in classCodeVisitorSupport
-
loadStaticField
public void loadStaticField(FieldExpression fldExp)
- Parameters:
fldExp
-
-
loadInstanceField
public void loadInstanceField(FieldExpression fldExp)
RHS instance field. should move most of the code in the BytecodeHelper- Parameters:
fldExp
-
-
visitVariableExpression
public void visitVariableExpression(VariableExpression expression)
Visits a bare (unqualified) variable expression.- Specified by:
visitVariableExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitVariableExpression
in classCodeVisitorSupport
-
createInterfaceSyntheticStaticFields
protected void createInterfaceSyntheticStaticFields()
-
createSyntheticStaticFields
protected void createSyntheticStaticFields()
-
visitClassExpression
public void visitClassExpression(ClassExpression expression)
load class object on stack- Specified by:
visitClassExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitClassExpression
in classCodeVisitorSupport
-
visitRangeExpression
public void visitRangeExpression(RangeExpression expression)
- Specified by:
visitRangeExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitRangeExpression
in classCodeVisitorSupport
-
visitMapEntryExpression
public void visitMapEntryExpression(MapEntryExpression expression)
- Specified by:
visitMapEntryExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitMapEntryExpression
in classCodeVisitorSupport
-
visitMapExpression
public void visitMapExpression(MapExpression expression)
- Specified by:
visitMapExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitMapExpression
in classCodeVisitorSupport
-
visitArgumentlistExpression
public void visitArgumentlistExpression(ArgumentListExpression ale)
- Specified by:
visitArgumentlistExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitArgumentlistExpression
in classCodeVisitorSupport
-
despreadList
public void despreadList(List expressions, boolean wrap)
-
visitTupleExpression
public void visitTupleExpression(TupleExpression expression)
- Specified by:
visitTupleExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitTupleExpression
in classCodeVisitorSupport
-
loadWrapper
public void loadWrapper(Expression argument)
-
visitArrayExpression
public void visitArrayExpression(ArrayExpression expression)
- Specified by:
visitArrayExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitArrayExpression
in classCodeVisitorSupport
-
visitClosureListExpression
public void visitClosureListExpression(ClosureListExpression expression)
- Specified by:
visitClosureListExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitClosureListExpression
in classCodeVisitorSupport
-
visitBytecodeSequence
public void visitBytecodeSequence(BytecodeSequence bytecodeSequence)
- Overrides:
visitBytecodeSequence
in classClassGenerator
-
visitListExpression
public void visitListExpression(ListExpression expression)
- Specified by:
visitListExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitListExpression
in classCodeVisitorSupport
-
visitGStringExpression
public void visitGStringExpression(GStringExpression expression)
- Specified by:
visitGStringExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitGStringExpression
in classCodeVisitorSupport
-
visitAnnotations
public void visitAnnotations(AnnotatedNode node)
Note: ignore it. Annotation generation needs the current visitor.- Overrides:
visitAnnotations
in classClassCodeVisitorSupport
-
visitBytecodeExpression
public void visitBytecodeExpression(BytecodeExpression cle)
- Specified by:
visitBytecodeExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitBytecodeExpression
in classCodeVisitorSupport
-
isThisExpression
@Deprecated public static boolean isThisExpression(Expression expression)
Deprecated.
-
getCompileUnit
protected CompileUnit getCompileUnit()
-
addInnerClass
public boolean addInnerClass(ClassNode innerClass)
-
-