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
Generates Java class versions of Groovy classes using ASM.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanAdd marker in the bytecode to show source-bytecode relationship.static final booleanEnables emission of local-variable and source debug metadata.static final booleanEnables emission of line number tables.static final StringMetadata key used to mark expressions whose value should be discarded.static final MethodCallerMultiAdapterRuntime helper used for dynamic field reads.static final MethodCallerMultiAdapterRuntime helper used for dynamic field reads againstGroovyObjectreceivers.static final StringMetadata key used to request a minimum emitted bytecode level.static final MethodCallerMultiAdapterRuntime helper used for dynamic field writes.static final MethodCallerMultiAdapterRuntime helper used for dynamic field writes againstGroovyObjectreceivers.static final MethodCallerMultiAdapterRuntime helper used for dynamic property writes.Fields inherited from class org.codehaus.groovy.classgen.ClassGenerator
innerClasses -
Constructor Summary
ConstructorsConstructorDescriptionAsmClassGenerator(SourceUnit source, GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, String sourceFile) Creates a bytecode generator for a single class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddInnerClass(ClassNode innerClass) Registers a generated inner class with the enclosing module.static intargumentSize(Expression arguments) Calculates the argument count represented by an argument expression.static booleancontainsSpreadExpression(Expression expression) Determines whether the supplied argument or collection expression contains a spread element.protected voidCreates helper class literal fields for interface bytecode generation.protected voidCreates synthetic class-literal helper fields and accessors on the current class.voiddespreadList(List<Expression> expressions, boolean wrap) Expands spread arguments into the runtime list representation expected by call sites.Returns the writer controller coordinating bytecode emission.static FieldNodegetDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper(ClassNode accessingNode, ClassNode current, String fieldName, boolean skipCurrent) Resolves a field declared on the current class or an accessible superclass.Provides access to theSourceUnitfor error reporting during visitation.static booleanisFieldDirectlyAccessible(FieldNode field, ClassNode accessingClass) Determines if the given field can be directly accessed by the given class (viaGETFIELD,GETSTATIC, etc.static booleanisMemberDirectlyAccessible(int modifiers, ClassNode declaringClass, ClassNode accessingClass) Determines whether a member with the supplied modifiers is directly accessible to a class.voidloadInstanceField(FieldExpression expression) RHS instance field.voidloadStaticField(FieldExpression expression) Loads a static field value onto the operand stack.voidloadWrapper(Expression expression) Wraps the top-of-stack value for reflective invocation helper paths.voidonLineNumber(ASTNode node, String message) Emits line number information for the supplied node when appropriate.voidthrowException(String message) Throws a parser exception associated with the current AST node.voidvisitAnnotationAttributes(AnnotationNode an, org.objectweb.asm.AnnotationVisitor av) Generates the annotation attributes.voidVisits annotations on anAnnotatedNode, delegating toClassCodeVisitorSupport.visitAnnotation(AnnotationNode).voidVisits anArgumentListExpression, treating it as a tuple expression.voidvisitArrayExpression(ArrayExpression expression) Visits anArrayExpression, traversing element expressions and size expressions.voidvisitAssertStatement(AssertStatement statement) Visits anAssertStatement, invoking the statement hook before parent traversal.voidvisitAttributeExpression(AttributeExpression expression) Visits anAttributeExpression, traversing the object and attribute name expressions.voidvisitBinaryExpression(BinaryExpression expression) Visits aBinaryExpression, traversing left and right operand expressions.voidVisits aBitwiseNegationExpression, traversing the operand expression.voidvisitBlockStatement(BlockStatement statement) Visits aBlockStatement, invoking the statement hook before parent traversal.voidvisitBooleanExpression(BooleanExpression expression) Visits aBooleanExpression, traversing the contained expression.voidvisitBreakStatement(BreakStatement statement) Visits aBreakStatement, invoking the statement hook before parent traversal.voidvisitBytecodeExpression(BytecodeExpression expression) Visits aBytecodeExpression.voidvisitBytecodeSequence(BytecodeSequence bytecodeSequence) Visits a bytecode sequence during AST traversal.voidvisitCaseStatement(CaseStatement statement) Visits aCaseStatement, invoking the statement hook before parent traversal.voidvisitCastExpression(CastExpression castExpression) Visits aCastExpression, traversing the operand expression.voidvisitCatchStatement(CatchStatement statement) Visits aCatchStatement, processing variable annotations and invoking the statement hook.voidvisitClass(ClassNode classNode) Visits aClassNode, processing its annotations, package, imports, contents, and object initializers.voidvisitClassExpression(ClassExpression expression) Visits aClassExpression.voidvisitClosureExpression(ClosureExpression expression) Visits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.voidvisitClosureListExpression(ClosureListExpression expression) Visits aClosureListExpression, traversing all contained expressions.voidvisitConstantExpression(ConstantExpression expression) Generates byte code for constants.voidVisits aConstructorNode, processing its annotations, parameter annotations, and code block.voidVisits aConstructorCallExpression, traversing its argument list.protected voidvisitConstructorOrMethod(MethodNode node, boolean isConstructor) Visits a constructor or method node (implementation detail for both visit methods).voidvisitContinueStatement(ContinueStatement statement) Visits aContinueStatement, invoking the statement hook before parent traversal.voidvisitDeclarationExpression(DeclarationExpression expression) Visits aDeclarationExpressionwith annotation processing, traversing expression annotations before delegating to parent traversal.voidvisitDoWhileLoop(DoWhileStatement statement) Visits aDoWhileStatement, invoking statement hooks before parent traversal.voidvisitExpressionStatement(ExpressionStatement statement) Visits anExpressionStatement, invoking the statement hook before parent traversal.voidvisitField(FieldNode fieldNode) Visits aFieldNode, processing its annotations and initial value expression if present.voidvisitFieldExpression(FieldExpression expression) Visits aFieldExpression.voidvisitForLoop(ForStatement statement) Visits aForStatement, invoking statement hooks and processing loop variable annotations.voidvisitGStringExpression(GStringExpression expression) Visits aGStringExpression, traversing string parts and interpolated value expressions.voidvisitIfElse(IfStatement statement) Visits anIfStatement, invoking the statement hook before parent traversal.voidvisitLambdaExpression(LambdaExpression expression) Visits aLambdaExpression, treating it as a closure expression.voidvisitListExpression(ListExpression expression) Visits aListExpression, traversing all contained expressions.voidvisitMapEntryExpression(MapEntryExpression expression) Visits aMapEntryExpression, traversing key and value expressions.voidvisitMapExpression(MapExpression expression) Visits aMapExpression, traversing all map entry expressions.voidvisitMethod(MethodNode node) Visits aMethodNode, processing its annotations, parameter annotations, and code block.voidVisits aMethodCallExpression, traversing the object expression, method expression, and argument list.voidvisitMethodPointerExpression(MethodPointerExpression expression) Visits aMethodPointerExpression, traversing the object and method name expressions.voidVisits aMethodReferenceExpression, treating it as a method pointer.voidvisitNotExpression(NotExpression expression) Visits aNotExpression, traversing the operand expression.voidvisitPostfixExpression(PostfixExpression expression) Visits aPostfixExpression, traversing the operand expression.voidvisitPrefixExpression(PrefixExpression expression) Visits aPrefixExpression, traversing the operand expression.voidvisitProperty(PropertyNode statement) Visits aPropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.voidvisitPropertyExpression(PropertyExpression expression) Visits aPropertyExpression, traversing the object and property name expressions.voidvisitRangeExpression(RangeExpression expression) Visits aRangeExpression, traversing from and to boundary expressions.voidvisitReturnStatement(ReturnStatement statement) Visits aReturnStatement, invoking the statement hook before parent traversal.voidvisitSpreadExpression(SpreadExpression expression) Visits aSpreadExpression, traversing the operand expression.voidvisitSpreadMapExpression(SpreadMapExpression expression) Visits aSpreadMapExpression, traversing the operand expression.protected voidvisitStatement(Statement statement) Hook method called when visiting anyStatement.voidVisits aStaticMethodCallExpression, traversing its argument list.voidvisitSwitch(SwitchStatement statement) Visits aSwitchStatement, invoking the statement hook before parent traversal.voidvisitSynchronizedStatement(SynchronizedStatement statement) Visits aSynchronizedStatement, invoking the statement hook before parent traversal.voidvisitTernaryExpression(TernaryExpression expression) Visits aTernaryExpression, traversing the condition, true-branch, and false-branch expressions.voidvisitThrowStatement(ThrowStatement statement) Visits aThrowStatement, invoking the statement hook before parent traversal.voidvisitTryCatchFinally(TryCatchStatement statement) Visits aTryCatchStatement, invoking the statement hook before parent traversal.voidvisitTupleExpression(TupleExpression expression) Visits aTupleExpression, traversing all contained expressions.voidvisitUnaryMinusExpression(UnaryMinusExpression expression) Visits aUnaryMinusExpression, traversing the operand expression.voidvisitUnaryPlusExpression(UnaryPlusExpression expression) Visits aUnaryPlusExpression, traversing the operand expression.voidvisitVariableExpression(VariableExpression expression) Visits aVariableExpression.voidvisitWhileLoop(WhileStatement statement) Visits aWhileStatement, invoking statement hooks before parent traversal.Methods inherited from class org.codehaus.groovy.classgen.ClassGenerator
getInnerClassesMethods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport
addError, visitAnnotation, visitAnnotations, visitClassCodeContainer, visitImports, visitObjectInitializerStatements, visitPackage, visitStatementAnnotationsMethods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitEmptyStatement, visitShortTernaryExpressionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor
visit, visit, visitEmptyExpression, visitListOfExpressions
-
Field Details
-
setField
Runtime helper used for dynamic field writes. -
getField
Runtime helper used for dynamic field reads. -
setGroovyObjectField
Runtime helper used for dynamic field writes againstGroovyObjectreceivers. -
getGroovyObjectField
Runtime helper used for dynamic field reads againstGroovyObjectreceivers. -
setProperty
Runtime helper used for dynamic property writes. -
ASM_DEBUG
public static final boolean ASM_DEBUGAdd marker in the bytecode to show source-bytecode relationship.- See Also:
-
CREATE_DEBUG_INFO
public static final boolean CREATE_DEBUG_INFOEnables emission of local-variable and source debug metadata.- See Also:
-
CREATE_LINE_NUMBER_INFO
public static final boolean CREATE_LINE_NUMBER_INFOEnables emission of line number tables.- See Also:
-
ELIDE_EXPRESSION_VALUE
Metadata key used to mark expressions whose value should be discarded.- See Also:
-
MINIMUM_BYTECODE_VERSION
Metadata key used to request a minimum emitted bytecode level.- See Also:
-
-
Constructor Details
-
AsmClassGenerator
public AsmClassGenerator(SourceUnit source, GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, String sourceFile) Creates a bytecode generator for a single class.- Parameters:
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 class
-
-
Method Details
-
getSourceUnit
Provides access to theSourceUnitfor error reporting during visitation. Implementations must override this method.- Overrides:
getSourceUnitin classClassGenerator- Returns:
- the source unit for this visitor
-
getController
Returns the writer controller coordinating bytecode emission.- Returns:
- the active writer controller
-
visitClass
Visits aClassNode, processing its annotations, package, imports, contents, and object initializers.- Specified by:
visitClassin interfaceGroovyClassVisitor- Overrides:
visitClassin classClassCodeVisitorSupport- Parameters:
classNode- the class node to visit
-
visitConstructorOrMethod
Visits a constructor or method node (implementation detail for both visit methods). Processes the node's annotations, all parameter annotations, and code block.- Overrides:
visitConstructorOrMethodin classClassCodeVisitorSupport- Parameters:
node- the method or constructor nodeisConstructor- true if node is a constructor, false if it is a method
-
visitConstructor
Visits aConstructorNode, processing its annotations, parameter annotations, and code block.- Specified by:
visitConstructorin interfaceGroovyClassVisitor- Overrides:
visitConstructorin classClassCodeVisitorSupport- Parameters:
node- the constructor node to visit
-
visitMethod
Visits aMethodNode, processing its annotations, parameter annotations, and code block.- Specified by:
visitMethodin interfaceGroovyClassVisitor- Overrides:
visitMethodin classClassCodeVisitorSupport- Parameters:
node- the method node to visit
-
visitField
Visits aFieldNode, processing its annotations and initial value expression if present.- Specified by:
visitFieldin interfaceGroovyClassVisitor- Overrides:
visitFieldin classClassCodeVisitorSupport- Parameters:
fieldNode- the field node to visit
-
visitProperty
Visits aPropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.- Specified by:
visitPropertyin interfaceGroovyClassVisitor- Overrides:
visitPropertyin classClassCodeVisitorSupport- Parameters:
statement- the property node to visit
-
visitStatement
Hook method called when visiting anyStatement. Subclasses may override to perform common processing on all statements.- Overrides:
visitStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement being visited
-
visitBlockStatement
Visits aBlockStatement, invoking the statement hook before parent traversal.- Specified by:
visitBlockStatementin interfaceGroovyCodeVisitor- Overrides:
visitBlockStatementin classClassCodeVisitorSupport- Parameters:
statement- the block statement to visit- See Also:
-
visitForLoop
Visits aForStatement, invoking statement hooks and processing loop variable annotations.- Specified by:
visitForLoopin interfaceGroovyCodeVisitor- Overrides:
visitForLoopin classClassCodeVisitorSupport- Parameters:
statement- the for statement to visit
-
visitWhileLoop
Visits aWhileStatement, invoking statement hooks before parent traversal.- Specified by:
visitWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitWhileLoopin classClassCodeVisitorSupport- Parameters:
statement- the while statement to visit
-
visitDoWhileLoop
Visits aDoWhileStatement, invoking statement hooks before parent traversal.- Specified by:
visitDoWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitDoWhileLoopin classClassCodeVisitorSupport- Parameters:
statement- the do-while statement to visit
-
visitIfElse
Visits anIfStatement, invoking the statement hook before parent traversal.- Specified by:
visitIfElsein interfaceGroovyCodeVisitor- Overrides:
visitIfElsein classClassCodeVisitorSupport- Parameters:
statement- the if statement to visit
-
visitAssertStatement
Visits anAssertStatement, invoking the statement hook before parent traversal.- Specified by:
visitAssertStatementin interfaceGroovyCodeVisitor- Overrides:
visitAssertStatementin classClassCodeVisitorSupport- Parameters:
statement- the assert statement to visit
-
visitTryCatchFinally
Visits aTryCatchStatement, invoking the statement hook before parent traversal.- Specified by:
visitTryCatchFinallyin interfaceGroovyCodeVisitor- Overrides:
visitTryCatchFinallyin classClassCodeVisitorSupport- Parameters:
statement- the try-catch statement to visit
-
visitCatchStatement
Visits aCatchStatement, processing variable annotations and invoking the statement hook.- Specified by:
visitCatchStatementin interfaceGroovyCodeVisitor- Overrides:
visitCatchStatementin classClassCodeVisitorSupport- Parameters:
statement- the catch statement to visit
-
visitSwitch
Visits aSwitchStatement, invoking the statement hook before parent traversal.- Specified by:
visitSwitchin interfaceGroovyCodeVisitor- Overrides:
visitSwitchin classClassCodeVisitorSupport- Parameters:
statement- the switch statement to visit
-
visitCaseStatement
Visits aCaseStatement, invoking the statement hook before parent traversal.- Specified by:
visitCaseStatementin interfaceGroovyCodeVisitor- Overrides:
visitCaseStatementin classClassCodeVisitorSupport- Parameters:
statement- the case statement to visit
-
visitBreakStatement
Visits aBreakStatement, invoking the statement hook before parent traversal.- Specified by:
visitBreakStatementin interfaceGroovyCodeVisitor- Overrides:
visitBreakStatementin classClassCodeVisitorSupport- Parameters:
statement- the break statement to visit
-
visitContinueStatement
Visits aContinueStatement, invoking the statement hook before parent traversal.- Specified by:
visitContinueStatementin interfaceGroovyCodeVisitor- Overrides:
visitContinueStatementin classClassCodeVisitorSupport- Parameters:
statement- the continue statement to visit
-
visitSynchronizedStatement
Visits aSynchronizedStatement, invoking the statement hook before parent traversal.- Specified by:
visitSynchronizedStatementin interfaceGroovyCodeVisitor- Overrides:
visitSynchronizedStatementin classClassCodeVisitorSupport- Parameters:
statement- the synchronized statement to visit
-
visitThrowStatement
Visits aThrowStatement, invoking the statement hook before parent traversal.- Specified by:
visitThrowStatementin interfaceGroovyCodeVisitor- Overrides:
visitThrowStatementin classClassCodeVisitorSupport- Parameters:
statement- the throw statement to visit
-
visitReturnStatement
Visits aReturnStatement, invoking the statement hook before parent traversal.- Specified by:
visitReturnStatementin interfaceGroovyCodeVisitor- Overrides:
visitReturnStatementin classClassCodeVisitorSupport- Parameters:
statement- the return statement to visit
-
visitExpressionStatement
Visits anExpressionStatement, invoking the statement hook before parent traversal.- Specified by:
visitExpressionStatementin interfaceGroovyCodeVisitor- Overrides:
visitExpressionStatementin classClassCodeVisitorSupport- Parameters:
statement- the expression statement to visit
-
visitTernaryExpression
Visits aTernaryExpression, traversing the condition, true-branch, and false-branch expressions.- Specified by:
visitTernaryExpressionin interfaceGroovyCodeVisitor- Overrides:
visitTernaryExpressionin classCodeVisitorSupport- Parameters:
expression- the ternary expression
-
visitDeclarationExpression
Visits aDeclarationExpressionwith annotation processing, traversing expression annotations before delegating to parent traversal.- Specified by:
visitDeclarationExpressionin interfaceGroovyCodeVisitor- Overrides:
visitDeclarationExpressionin classClassCodeVisitorSupport- Parameters:
expression- the declaration expression to visit
-
visitBinaryExpression
Visits aBinaryExpression, traversing left and right operand expressions.- Specified by:
visitBinaryExpressionin interfaceGroovyCodeVisitor- Overrides:
visitBinaryExpressionin classCodeVisitorSupport- Parameters:
expression- the binary expression
-
visitPostfixExpression
Visits aPostfixExpression, traversing the operand expression.- Specified by:
visitPostfixExpressionin interfaceGroovyCodeVisitor- Overrides:
visitPostfixExpressionin classCodeVisitorSupport- Parameters:
expression- the postfix expression
-
visitPrefixExpression
Visits aPrefixExpression, traversing the operand expression.- Specified by:
visitPrefixExpressionin interfaceGroovyCodeVisitor- Overrides:
visitPrefixExpressionin classCodeVisitorSupport- Parameters:
expression- the prefix expression
-
visitClosureExpression
Visits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.- Specified by:
visitClosureExpressionin interfaceGroovyCodeVisitor- Overrides:
visitClosureExpressionin classClassCodeVisitorSupport- Parameters:
expression- the closure expression to visit
-
visitLambdaExpression
Visits aLambdaExpression, treating it as a closure expression.- Specified by:
visitLambdaExpressionin interfaceGroovyCodeVisitor- Overrides:
visitLambdaExpressionin classCodeVisitorSupport- Parameters:
expression- the lambda expression
-
visitConstantExpression
Generates byte code for constants.- Specified by:
visitConstantExpressionin interfaceGroovyCodeVisitor- Overrides:
visitConstantExpressionin classCodeVisitorSupport- Parameters:
expression- the constant expression- See Also:
-
visitSpreadExpression
Visits aSpreadExpression, traversing the operand expression.- Specified by:
visitSpreadExpressionin interfaceGroovyCodeVisitor- Overrides:
visitSpreadExpressionin classCodeVisitorSupport- Parameters:
expression- the spread expression
-
visitSpreadMapExpression
Visits aSpreadMapExpression, traversing the operand expression.- Specified by:
visitSpreadMapExpressionin interfaceGroovyCodeVisitor- Overrides:
visitSpreadMapExpressionin classCodeVisitorSupport- Parameters:
expression- the spread map expression
-
visitMethodPointerExpression
Visits aMethodPointerExpression, traversing the object and method name expressions.- Specified by:
visitMethodPointerExpressionin interfaceGroovyCodeVisitor- Overrides:
visitMethodPointerExpressionin classCodeVisitorSupport- Parameters:
expression- the method pointer expression
-
visitMethodReferenceExpression
Visits aMethodReferenceExpression, treating it as a method pointer.- Specified by:
visitMethodReferenceExpressionin interfaceGroovyCodeVisitor- Overrides:
visitMethodReferenceExpressionin classCodeVisitorSupport- Parameters:
expression- the method reference expression
-
visitUnaryMinusExpression
Visits aUnaryMinusExpression, traversing the operand expression.- Specified by:
visitUnaryMinusExpressionin interfaceGroovyCodeVisitor- Overrides:
visitUnaryMinusExpressionin classCodeVisitorSupport- Parameters:
expression- the unary minus expression
-
visitUnaryPlusExpression
Visits aUnaryPlusExpression, traversing the operand expression.- Specified by:
visitUnaryPlusExpressionin interfaceGroovyCodeVisitor- Overrides:
visitUnaryPlusExpressionin classCodeVisitorSupport- Parameters:
expression- the unary plus expression
-
visitBitwiseNegationExpression
Visits aBitwiseNegationExpression, traversing the operand expression.- Specified by:
visitBitwiseNegationExpressionin interfaceGroovyCodeVisitor- Overrides:
visitBitwiseNegationExpressionin classCodeVisitorSupport- Parameters:
expression- the bitwise negation expression
-
visitCastExpression
Visits aCastExpression, traversing the operand expression.- Specified by:
visitCastExpressionin interfaceGroovyCodeVisitor- Overrides:
visitCastExpressionin classCodeVisitorSupport- Parameters:
castExpression- the cast expression
-
visitNotExpression
Visits aNotExpression, traversing the operand expression.- Specified by:
visitNotExpressionin interfaceGroovyCodeVisitor- Overrides:
visitNotExpressionin classCodeVisitorSupport- Parameters:
expression- the not expression
-
visitBooleanExpression
Visits aBooleanExpression, traversing the contained expression.- Specified by:
visitBooleanExpressionin interfaceGroovyCodeVisitor- Overrides:
visitBooleanExpressionin classCodeVisitorSupport- Parameters:
expression- the boolean expression
-
visitMethodCallExpression
Visits aMethodCallExpression, traversing the object expression, method expression, and argument list.- Specified by:
visitMethodCallExpressionin interfaceGroovyCodeVisitor- Overrides:
visitMethodCallExpressionin classCodeVisitorSupport- Parameters:
call- the method call expression
-
visitStaticMethodCallExpression
Visits aStaticMethodCallExpression, traversing its argument list.- Specified by:
visitStaticMethodCallExpressionin interfaceGroovyCodeVisitor- Overrides:
visitStaticMethodCallExpressionin classCodeVisitorSupport- Parameters:
call- the static method call expression
-
visitConstructorCallExpression
Visits aConstructorCallExpression, traversing its argument list.- Specified by:
visitConstructorCallExpressionin interfaceGroovyCodeVisitor- Overrides:
visitConstructorCallExpressionin classCodeVisitorSupport- Parameters:
call- the constructor call expression
-
isFieldDirectlyAccessible
Determines if the given field can be directly accessed by the given class (viaGETFIELD,GETSTATIC, etc. bytecode instructions). -
isMemberDirectlyAccessible
public static boolean isMemberDirectlyAccessible(int modifiers, ClassNode declaringClass, ClassNode accessingClass) Determines whether a member with the supplied modifiers is directly accessible to a class.- Parameters:
modifiers- the member modifiersdeclaringClass- the class declaring the memberaccessingClass- the class attempting access- Returns:
trueif direct bytecode access is legal
-
getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper
public static FieldNode getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper(ClassNode accessingNode, ClassNode current, String fieldName, boolean skipCurrent) Resolves a field declared on the current class or an accessible superclass.- Parameters:
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 superclass- Returns:
- the resolved field, or
nullif none is directly accessible
-
visitPropertyExpression
Visits aPropertyExpression, traversing the object and property name expressions.- Specified by:
visitPropertyExpressionin interfaceGroovyCodeVisitor- Overrides:
visitPropertyExpressionin classCodeVisitorSupport- Parameters:
expression- the property expression
-
visitAttributeExpression
Visits anAttributeExpression, traversing the object and attribute name expressions.- Specified by:
visitAttributeExpressionin interfaceGroovyCodeVisitor- Overrides:
visitAttributeExpressionin classCodeVisitorSupport- Parameters:
expression- the attribute expression
-
visitFieldExpression
Visits aFieldExpression. No traversal is performed as field expressions contain no child expressions.- Specified by:
visitFieldExpressionin interfaceGroovyCodeVisitor- Overrides:
visitFieldExpressionin classCodeVisitorSupport- Parameters:
expression- the field expression
-
loadStaticField
Loads a static field value onto the operand stack.- Parameters:
expression- the field expression to load
-
loadInstanceField
RHS instance field. should move most of the code in the BytecodeHelper -
visitVariableExpression
Visits aVariableExpression. No traversal is performed as variable expressions contain no child expressions.- Specified by:
visitVariableExpressionin interfaceGroovyCodeVisitor- Overrides:
visitVariableExpressionin classCodeVisitorSupport- Parameters:
expression- the variable expression
-
createInterfaceSyntheticStaticFields
protected void createInterfaceSyntheticStaticFields()Creates helper class literal fields for interface bytecode generation. -
createSyntheticStaticFields
protected void createSyntheticStaticFields()Creates synthetic class-literal helper fields and accessors on the current class. -
visitClassExpression
Visits aClassExpression. No traversal is performed as class expressions contain no child expressions.- Specified by:
visitClassExpressionin interfaceGroovyCodeVisitor- Overrides:
visitClassExpressionin classCodeVisitorSupport- Parameters:
expression- the class expression
-
visitRangeExpression
Visits aRangeExpression, traversing from and to boundary expressions.- Specified by:
visitRangeExpressionin interfaceGroovyCodeVisitor- Overrides:
visitRangeExpressionin classCodeVisitorSupport- Parameters:
expression- the range expression
-
visitMapEntryExpression
Visits aMapEntryExpression, traversing key and value expressions.- Specified by:
visitMapEntryExpressionin interfaceGroovyCodeVisitor- Overrides:
visitMapEntryExpressionin classCodeVisitorSupport- Parameters:
expression- the map entry expression
-
visitMapExpression
Visits aMapExpression, traversing all map entry expressions.- Specified by:
visitMapExpressionin interfaceGroovyCodeVisitor- Overrides:
visitMapExpressionin classCodeVisitorSupport- Parameters:
expression- the map expression
-
visitArgumentlistExpression
Visits anArgumentListExpression, treating it as a tuple expression.- Specified by:
visitArgumentlistExpressionin interfaceGroovyCodeVisitor- Overrides:
visitArgumentlistExpressionin classCodeVisitorSupport- Parameters:
ale- the argument list expression
-
visitTupleExpression
Visits aTupleExpression, traversing all contained expressions.- Specified by:
visitTupleExpressionin interfaceGroovyCodeVisitor- Overrides:
visitTupleExpressionin classCodeVisitorSupport- Parameters:
expression- the tuple expression
-
visitArrayExpression
Visits anArrayExpression, traversing element expressions and size expressions.- Specified by:
visitArrayExpressionin interfaceGroovyCodeVisitor- Overrides:
visitArrayExpressionin classCodeVisitorSupport- Parameters:
expression- the array expression
-
visitClosureListExpression
Visits aClosureListExpression, traversing all contained expressions.- Specified by:
visitClosureListExpressionin interfaceGroovyCodeVisitor- Overrides:
visitClosureListExpressionin classCodeVisitorSupport- Parameters:
expression- the closure list expression
-
visitBytecodeExpression
Visits aBytecodeExpression. No traversal is performed as bytecode expressions are terminal.- Specified by:
visitBytecodeExpressionin interfaceGroovyCodeVisitor- Overrides:
visitBytecodeExpressionin classCodeVisitorSupport- Parameters:
expression- the bytecode expression
-
visitBytecodeSequence
Visits a bytecode sequence during AST traversal. Subclasses should override this method to handle custom bytecode generation.- Overrides:
visitBytecodeSequencein classClassGenerator- Parameters:
bytecodeSequence- the bytecode sequence to visit
-
visitListExpression
Visits aListExpression, traversing all contained expressions.- Specified by:
visitListExpressionin interfaceGroovyCodeVisitor- Overrides:
visitListExpressionin classCodeVisitorSupport- Parameters:
expression- the list expression
-
visitGStringExpression
Visits aGStringExpression, traversing string parts and interpolated value expressions.- Specified by:
visitGStringExpressionin interfaceGroovyCodeVisitor- Overrides:
visitGStringExpressionin classCodeVisitorSupport- Parameters:
expression- the GString expression
-
visitAnnotations
Visits annotations on anAnnotatedNode, delegating toClassCodeVisitorSupport.visitAnnotation(AnnotationNode).- Overrides:
visitAnnotationsin classClassCodeVisitorSupport- Parameters:
node- the annotated node containing annotations to visit
-
visitAnnotationAttributes
Generates the annotation attributes.- Parameters:
an- the node with an annotationav- the visitor to use
-
addInnerClass
Registers a generated inner class with the enclosing module.- Parameters:
innerClass- the inner class to register- Returns:
trueif the inner class was queued for later emission
-
argumentSize
Calculates the argument count represented by an argument expression.- Parameters:
arguments- the argument expression to inspect- Returns:
- the represented argument count
-
containsSpreadExpression
Determines whether the supplied argument or collection expression contains a spread element.- Parameters:
expression- the expression to inspect- Returns:
trueif any spread element is present
-
despreadList
Expands spread arguments into the runtime list representation expected by call sites.- Parameters:
expressions- the argument expressions to expandwrap- whether certain arguments should be wrapped for constructor dispatch
-
loadWrapper
Wraps the top-of-stack value for reflective invocation helper paths.- Parameters:
expression- the expression whose runtime value should be wrapped
-
onLineNumber
Emits line number information for the supplied node when appropriate.- Parameters:
node- the current source nodemessage- a debug message retained for compatibility with existing callers
-
throwException
Throws a parser exception associated with the current AST node.- Parameters:
message- the exception message
-