public class AsmClassGenerator
extends ClassGenerator
Generates Java class versions of Groovy classes using ASM.
| Modifiers | Name | Description |
|---|---|---|
static boolean |
ASM_DEBUG |
Add marker in the bytecode to show source-bytecode relationship. |
static boolean |
CREATE_DEBUG_INFO |
Enables emission of local-variable and source debug metadata. |
static boolean |
CREATE_LINE_NUMBER_INFO |
Enables emission of line number tables. |
static String |
ELIDE_EXPRESSION_VALUE |
Metadata key used to mark expressions whose value should be discarded. |
static String |
MINIMUM_BYTECODE_VERSION |
Metadata key used to request a minimum emitted bytecode level. |
static MethodCallerMultiAdapter |
getField |
Runtime helper used for dynamic field reads. |
static MethodCallerMultiAdapter |
getGroovyObjectField |
Runtime helper used for dynamic field reads against GroovyObject receivers. |
static MethodCallerMultiAdapter |
setField |
Runtime helper used for dynamic field writes. |
static MethodCallerMultiAdapter |
setGroovyObjectField |
Runtime helper used for dynamic field writes against GroovyObject receivers. |
static MethodCallerMultiAdapter |
setProperty |
Runtime helper used for dynamic property writes. |
| Fields inherited from class | Fields |
|---|---|
class ClassGenerator |
innerClasses |
| Constructor and description |
|---|
AsmClassGenerator(SourceUnit source, GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, String sourceFile)Creates a bytecode generator for a single class. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public boolean |
addInnerClass(ClassNode innerClass)Registers a generated inner class with the enclosing module. |
|
public static int |
argumentSize(Expression arguments)Calculates the argument count represented by an argument expression. |
|
public static boolean |
containsSpreadExpression(Expression expression)Determines whether the supplied argument or collection expression contains a spread element. |
|
protected void |
createInterfaceSyntheticStaticFields()Creates helper class literal fields for interface bytecode generation. |
|
protected void |
createSyntheticStaticFields()Creates synthetic class-literal helper fields and accessors on the current class. |
|
public void |
despreadList(List<Expression> expressions, boolean wrap)Expands spread arguments into the runtime list representation expected by call sites. |
|
public WriterController |
getController()Returns the writer controller coordinating bytecode emission. |
|
public static FieldNode |
getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper(ClassNode accessingNode, ClassNode current, String fieldName, boolean skipCurrent)Resolves a field declared on the current class or an accessible superclass. |
|
public SourceUnit |
getSourceUnit()* * Provides access to the SourceUnit for error reporting during visitation. * Implementations must override this method. * *
|
|
public static boolean |
isFieldDirectlyAccessible(FieldNode field, ClassNode accessingClass)Determines if the given field can be directly accessed by the given class (via GETFIELD, GETSTATIC, etc. bytecode instructions). |
|
public static boolean |
isMemberDirectlyAccessible(int modifiers, ClassNode declaringClass, ClassNode accessingClass)Determines whether a member with the supplied modifiers is directly accessible to a class. |
|
public void |
loadInstanceField(FieldExpression expression)RHS instance field. should move most of the code in the BytecodeHelper |
|
public void |
loadStaticField(FieldExpression expression)Loads a static field value onto the operand stack. |
|
public void |
loadWrapper(Expression expression)Wraps the top-of-stack value for reflective invocation helper paths. |
|
public void |
onLineNumber(ASTNode node, String message)Emits line number information for the supplied node when appropriate. |
|
public void |
throwException(String message)Throws a parser exception associated with the current AST node. |
|
public void |
visitAnnotationAttributes(AnnotationNode an, AnnotationVisitor av)Generates the annotation attributes. |
|
public void |
visitAnnotations(AnnotatedNode node)* Visits annotations on an AnnotatedNode, delegating to visitAnnotation(AnnotationNode). * *
|
|
public void |
visitArgumentlistExpression(ArgumentListExpression ale)* Visits an ArgumentListExpression, treating it as a tuple expression. * *
|
|
public void |
visitArrayExpression(ArrayExpression expression)* Visits an ArrayExpression, traversing element expressions and size expressions. * *
|
|
public void |
visitAssertStatement(AssertStatement statement)* Visits an AssertStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitAttributeExpression(AttributeExpression expression)* Visits an AttributeExpression, traversing the object and attribute name expressions. * *
|
|
public void |
visitBinaryExpression(BinaryExpression expression)* Visits a BinaryExpression, traversing left and right operand expressions. * *
|
|
public void |
visitBitwiseNegationExpression(BitwiseNegationExpression expression)* Visits a BitwiseNegationExpression, traversing the operand expression. * *
|
|
public void |
visitBlockStatement(BlockStatement statement)* Visits a BlockStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitBooleanExpression(BooleanExpression expression)* Visits a BooleanExpression, traversing the contained expression. * *
|
|
public void |
visitBreakStatement(BreakStatement statement)* Visits a BreakStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitBytecodeExpression(BytecodeExpression expression)* Visits a BytecodeExpression. No traversal is performed as bytecode expressions are terminal. * *
|
|
public void |
visitBytecodeSequence(BytecodeSequence bytecodeSequence)* Visits a bytecode sequence during AST traversal. Subclasses should override * this method to handle custom bytecode generation. * *
|
|
public void |
visitCaseStatement(CaseStatement statement)* Visits a CaseStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitCastExpression(CastExpression castExpression)* Visits a CastExpression, traversing the operand expression. * *
|
|
public void |
visitCatchStatement(CatchStatement statement)* Visits a CatchStatement, processing variable annotations and invoking the statement hook. * *
|
|
public void |
visitClass(ClassNode classNode)* Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers. * *
|
|
public void |
visitClassExpression(ClassExpression expression)* Visits a ClassExpression. No traversal is performed as class expressions contain no child expressions. * *
|
|
public void |
visitClosureExpression(ClosureExpression expression)* Visits a ClosureExpression with annotation processing, traversing parameter annotations * before delegating to parent traversal. * *
|
|
public void |
visitClosureListExpression(ClosureListExpression expression)* Visits a ClosureListExpression, traversing all contained expressions. * *
|
|
public void |
visitConstantExpression(ConstantExpression expression)Generates byte code for constants. |
|
public void |
visitConstructor(ConstructorNode node)* Visits a ConstructorNode, processing its annotations, parameter annotations, and code block. * *
|
|
public void |
visitConstructorCallExpression(ConstructorCallExpression call)* Visits a ConstructorCallExpression, traversing its argument list. * *
|
|
protected void |
visitConstructorOrMethod(MethodNode node, boolean isConstructor)* Visits a constructor or method node (implementation detail for both visit methods). * Processes the node's annotations, all parameter annotations, and code block. * *
|
|
public void |
visitContinueStatement(ContinueStatement statement)* Visits a ContinueStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitDeclarationExpression(DeclarationExpression expression)* Visits a DeclarationExpression with annotation processing, traversing expression annotations * before delegating to parent traversal. * *
|
|
public void |
visitDoWhileLoop(DoWhileStatement statement)* Visits a DoWhileStatement, invoking statement hooks before parent traversal. * *
|
|
public void |
visitExpressionStatement(ExpressionStatement statement)* Visits an ExpressionStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitField(FieldNode fieldNode)* Visits a FieldNode, processing its annotations and initial value expression if present. * *
|
|
public void |
visitFieldExpression(FieldExpression expression)* Visits a FieldExpression. No traversal is performed as field expressions contain no child expressions. * *
|
|
public void |
visitForLoop(ForStatement statement)* Visits a ForStatement, invoking statement hooks and processing loop variable annotations. * *
|
|
public void |
visitGStringExpression(GStringExpression expression)* Visits a GStringExpression, traversing string parts and interpolated value expressions. * *
|
|
public void |
visitIfElse(IfStatement statement)* Visits an IfStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitLambdaExpression(LambdaExpression expression)* Visits a LambdaExpression, treating it as a closure expression. * *
|
|
public void |
visitListExpression(ListExpression expression)* Visits a ListExpression, traversing all contained expressions. * *
|
|
public void |
visitMapEntryExpression(MapEntryExpression expression)* Visits a MapEntryExpression, traversing key and value expressions. * *
|
|
public void |
visitMapExpression(MapExpression expression)* Visits a MapExpression, traversing all map entry expressions. * *
|
|
public void |
visitMethod(MethodNode node)* Visits a MethodNode, processing its annotations, parameter annotations, and code block. * *
|
|
public void |
visitMethodCallExpression(MethodCallExpression call)* Visits a MethodCallExpression, traversing the object expression, * method expression, and argument list. * *
|
|
public void |
visitMethodPointerExpression(MethodPointerExpression expression)* Visits a MethodPointerExpression, traversing the object and method name expressions. * *
|
|
public void |
visitMethodReferenceExpression(MethodReferenceExpression expression)* Visits a MethodReferenceExpression, treating it as a method pointer. * *
|
|
public void |
visitNotExpression(NotExpression expression)* Visits a NotExpression, traversing the operand expression. * *
|
|
public void |
visitPostfixExpression(PostfixExpression expression)* Visits a PostfixExpression, traversing the operand expression. * *
|
|
public void |
visitPrefixExpression(PrefixExpression expression)* Visits a PrefixExpression, traversing the operand expression. * *
|
|
public void |
visitProperty(PropertyNode statement)* Visits a PropertyNode, processing its annotations, initial value expression, * and getter/setter blocks if present. * *
|
|
public void |
visitPropertyExpression(PropertyExpression expression)* Visits a PropertyExpression, traversing the object and property name expressions. * *
|
|
public void |
visitRangeExpression(RangeExpression expression)* Visits a RangeExpression, traversing from and to boundary expressions. * *
|
|
public void |
visitReturnStatement(ReturnStatement statement)* Visits a ReturnStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitSpreadExpression(SpreadExpression expression)* Visits a SpreadExpression, traversing the operand expression. * *
|
|
public void |
visitSpreadMapExpression(SpreadMapExpression expression)* Visits a SpreadMapExpression, traversing the operand expression. * *
|
|
protected void |
visitStatement(Statement statement)* Hook method called when visiting any Statement. Subclasses may override * to perform common processing on all statements. * *
|
|
public void |
visitStaticMethodCallExpression(StaticMethodCallExpression call)* Visits a StaticMethodCallExpression, traversing its argument list. * *
|
|
public void |
visitSwitch(SwitchStatement statement)* Visits a SwitchStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitSynchronizedStatement(SynchronizedStatement statement)* Visits a SynchronizedStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitTernaryExpression(TernaryExpression expression)* Visits a TernaryExpression, traversing the condition, true-branch, and false-branch expressions. * *
|
|
public void |
visitThrowStatement(ThrowStatement statement)* Visits a ThrowStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitTryCatchFinally(TryCatchStatement statement)* Visits a TryCatchStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitTupleExpression(TupleExpression expression)* Visits a TupleExpression, traversing all contained expressions. * *
|
|
public void |
visitUnaryMinusExpression(UnaryMinusExpression expression)* Visits a UnaryMinusExpression, traversing the operand expression. * *
|
|
public void |
visitUnaryPlusExpression(UnaryPlusExpression expression)* Visits a UnaryPlusExpression, traversing the operand expression. * *
|
|
public void |
visitVariableExpression(VariableExpression expression)* Visits a VariableExpression. No traversal is performed as variable expressions contain no child expressions. * *
|
|
public void |
visitWhileLoop(WhileStatement statement)* Visits a WhileStatement, invoking statement hooks before parent traversal. * *
|
Add marker in the bytecode to show source-bytecode relationship.
Enables emission of local-variable and source debug metadata.
Enables emission of line number tables.
Metadata key used to mark expressions whose value should be discarded.
Metadata key used to request a minimum emitted bytecode level.
Runtime helper used for dynamic field reads.
Runtime helper used for dynamic field reads against GroovyObject receivers.
Runtime helper used for dynamic field writes.
Runtime helper used for dynamic field writes against GroovyObject receivers.
Runtime helper used for dynamic property writes.
Creates a bytecode generator for a single class.
source - the source unit being compiledcontext - shared generation state for the enclosing compile unitclassVisitor - the ASM visitor receiving the emitted classsourceFile - the source file name recorded in the generated classRegisters a generated inner class with the enclosing module.
innerClass - the inner class to registertrue if the inner class was queued for later emissionCalculates the argument count represented by an argument expression.
arguments - the argument expression to inspectDetermines whether the supplied argument or collection expression contains a spread element.
expression - the expression to inspecttrue if any spread element is presentCreates helper class literal fields for interface bytecode generation.
Creates synthetic class-literal helper fields and accessors on the current class.
Expands spread arguments into the runtime list representation expected by call sites.
expressions - the argument expressions to expandwrap - whether certain arguments should be wrapped for constructor dispatchReturns the writer controller coordinating bytecode emission.
Resolves a field declared on the current class or an accessible superclass.
accessingNode - the class performing the accesscurrent - the class whose hierarchy is being searchedfieldName - the field name to resolveskipCurrent - whether to skip the current class and start with its superclassnull if none is directly accessible* * Provides access to the SourceUnit for error reporting during visitation. * Implementations must override this method. * *
Determines if the given field can be directly accessed by the given class
(via GETFIELD, GETSTATIC, etc. bytecode instructions).
Determines whether a member with the supplied modifiers is directly accessible to a class.
modifiers - the member modifiersdeclaringClass - the class declaring the memberaccessingClass - the class attempting accesstrue if direct bytecode access is legalRHS instance field. should move most of the code in the BytecodeHelper
Loads a static field value onto the operand stack.
expression - the field expression to loadWraps the top-of-stack value for reflective invocation helper paths.
expression - the expression whose runtime value should be wrappedEmits line number information for the supplied node when appropriate.
node - the current source nodemessage - a debug message retained for compatibility with existing callersThrows a parser exception associated with the current AST node.
message - the exception messageGenerates the annotation attributes.
an - the node with an annotationav - the visitor to use* Visits annotations on an AnnotatedNode, delegating to visitAnnotation(AnnotationNode). * *
node - the annotated node containing annotations to visit* Visits an ArgumentListExpression, treating it as a tuple expression. * *
expression - the argument list expression* Visits an ArrayExpression, traversing element expressions and size expressions. * *
expression - the array expression* Visits an AssertStatement, invoking the statement hook before parent traversal. * *
statement - the assert statement to visit* Visits an AttributeExpression, traversing the object and attribute name expressions. * *
expression - the attribute expression* Visits a BinaryExpression, traversing left and right operand expressions. * *
expression - the binary expression* Visits a BitwiseNegationExpression, traversing the operand expression. * *
expression - the bitwise negation expression* Visits a BlockStatement, invoking the statement hook before parent traversal. * *
statement - the block statement to visit* Visits a BooleanExpression, traversing the contained expression. * *
expression - the boolean expression* Visits a BreakStatement, invoking the statement hook before parent traversal. * *
statement - the break statement to visit* Visits a BytecodeExpression. No traversal is performed as bytecode expressions are terminal. * *
expression - the bytecode expression* Visits a bytecode sequence during AST traversal. Subclasses should override * this method to handle custom bytecode generation. * *
bytecodeSequence - the bytecode sequence to visit* Visits a CaseStatement, invoking the statement hook before parent traversal. * *
statement - the case statement to visit* Visits a CastExpression, traversing the operand expression. * *
expression - the cast expression* Visits a CatchStatement, processing variable annotations and invoking the statement hook. * *
statement - the catch statement to visit* Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers. * *
node - the class node to visit* Visits a ClassExpression. No traversal is performed as class expressions contain no child expressions. * *
expression - the class expression* Visits a ClosureExpression with annotation processing, traversing parameter annotations * before delegating to parent traversal. * *
expression - the closure expression to visit* Visits a ClosureListExpression, traversing all contained expressions. * *
expression - the closure list expressionGenerates byte code for constants.
* Visits a ConstructorNode, processing its annotations, parameter annotations, and code block. * *
node - the constructor node to visit* Visits a ConstructorCallExpression, traversing its argument list. * *
call - the constructor call expression* Visits a constructor or method node (implementation detail for both visit methods). * Processes the node's annotations, all parameter annotations, and code block. * *
node - the method or constructor node
*isConstructor - true if node is a constructor, false if it is a method* Visits a ContinueStatement, invoking the statement hook before parent traversal. * *
statement - the continue statement to visit* Visits a DeclarationExpression with annotation processing, traversing expression annotations * before delegating to parent traversal. * *
expression - the declaration expression to visit* Visits a DoWhileStatement, invoking statement hooks before parent traversal. * *
statement - the do-while statement to visit* Visits an ExpressionStatement, invoking the statement hook before parent traversal. * *
statement - the expression statement to visit* Visits a FieldNode, processing its annotations and initial value expression if present. * *
node - the field node to visit* Visits a FieldExpression. No traversal is performed as field expressions contain no child expressions. * *
expression - the field expression* Visits a ForStatement, invoking statement hooks and processing loop variable annotations. * *
statement - the for statement to visit* Visits a GStringExpression, traversing string parts and interpolated value expressions. * *
expression - the GString expression* Visits an IfStatement, invoking the statement hook before parent traversal. * *
statement - the if statement to visit* Visits a LambdaExpression, treating it as a closure expression. * *
expression - the lambda expression* Visits a ListExpression, traversing all contained expressions. * *
expression - the list expression* Visits a MapEntryExpression, traversing key and value expressions. * *
expression - the map entry expression* Visits a MapExpression, traversing all map entry expressions. * *
expression - the map expression* Visits a MethodNode, processing its annotations, parameter annotations, and code block. * *
node - the method node to visit* Visits a MethodCallExpression, traversing the object expression, * method expression, and argument list. * *
call - the method call expression* Visits a MethodPointerExpression, traversing the object and method name expressions. * *
expression - the method pointer expression* Visits a MethodReferenceExpression, treating it as a method pointer. * *
expression - the method reference expression* Visits a NotExpression, traversing the operand expression. * *
expression - the not expression* Visits a PostfixExpression, traversing the operand expression. * *
expression - the postfix expression* Visits a PrefixExpression, traversing the operand expression. * *
expression - the prefix expression* Visits a PropertyNode, processing its annotations, initial value expression, * and getter/setter blocks if present. * *
node - the property node to visit* Visits a PropertyExpression, traversing the object and property name expressions. * *
expression - the property expression* Visits a RangeExpression, traversing from and to boundary expressions. * *
expression - the range expression* Visits a ReturnStatement, invoking the statement hook before parent traversal. * *
statement - the return statement to visit* Visits a SpreadExpression, traversing the operand expression. * *
expression - the spread expression* Visits a SpreadMapExpression, traversing the operand expression. * *
expression - the spread map expression* Hook method called when visiting any Statement. Subclasses may override * to perform common processing on all statements. * *
statement - the statement being visited* Visits a StaticMethodCallExpression, traversing its argument list. * *
call - the static method call expression* Visits a SwitchStatement, invoking the statement hook before parent traversal. * *
statement - the switch statement to visit* Visits a SynchronizedStatement, invoking the statement hook before parent traversal. * *
statement - the synchronized statement to visit* Visits a TernaryExpression, traversing the condition, true-branch, and false-branch expressions. * *
expression - the ternary expression* Visits a ThrowStatement, invoking the statement hook before parent traversal. * *
statement - the throw statement to visit* Visits a TryCatchStatement, invoking the statement hook before parent traversal. * *
statement - the try-catch statement to visit* Visits a TupleExpression, traversing all contained expressions. * *
expression - the tuple expression* Visits a UnaryMinusExpression, traversing the operand expression. * *
expression - the unary minus expression* Visits a UnaryPlusExpression, traversing the operand expression. * *
expression - the unary plus expression* Visits a VariableExpression. No traversal is performed as variable expressions contain no child expressions. * *
expression - the variable expression* Visits a WhileStatement, invoking statement hooks before parent traversal. * *
statement - the while statement to visitCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.