Package org.codehaus.groovy.classgen
Class InnerClassVisitorHelper
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.classgen.InnerClassVisitorHelper
- All Implemented Interfaces:
GroovyClassVisitor,GroovyCodeVisitor,ErrorCollecting
- Direct Known Subclasses:
InnerClassCompletionVisitor,InnerClassVisitor
Abstract base class providing helper methods for inner class visitors.
This class contains utility methods for generating dispatcher code that
allows inner classes to access members of their enclosing classes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidaddFieldInit(Parameter p, FieldNode fn, BlockStatement block) Adds a statement to initialize a field from a constructor parameter.protected static ClassNodegetClassNode(ClassNode cn, boolean isStatic) Returns the class node to expose when wiring dispatch methods for an inner class.protected static intCalculates the inheritance distance from the supplied type toObject.protected static booleanDetermines whether the supplied inner class behaves as a static nested class.protected static voidsetMethodDispatcherCode(BlockStatement block, Expression target, Parameter[] parameters) Generates method dispatcher code for dynamic method invocation.protected static voidsetPropertyGetterDispatcher(BlockStatement block, Expression target, Parameter[] parameters) Generates property getter dispatcher code for dynamic property access.protected static voidsetPropertySetterDispatcher(BlockStatement block, Expression target, Parameter[] parameters) Generates property setter dispatcher code for dynamic property access.protected static booleanDetermines whether synthetic outer-instance handling should be applied to the inner class.Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport
addError, getSourceUnit, visitAnnotation, visitAnnotations, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitStatementAnnotations, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoopMethods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpressionMethods 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
-
Constructor Details
-
InnerClassVisitorHelper
public InnerClassVisitorHelper()
-
-
Method Details
-
addFieldInit
Adds a statement to initialize a field from a constructor parameter.- Parameters:
p- the parameter to read fromfn- the field to initializeblock- the block statement to add the initialization to
-
setPropertyGetterDispatcher
protected static void setPropertyGetterDispatcher(BlockStatement block, Expression target, Parameter[] parameters) Generates property getter dispatcher code for dynamic property access.- Parameters:
block- the block to add the dispatcher code totarget- the target object to get the property fromparameters- the dispatcher method parameters (property name)
-
setPropertySetterDispatcher
protected static void setPropertySetterDispatcher(BlockStatement block, Expression target, Parameter[] parameters) Generates property setter dispatcher code for dynamic property access.- Parameters:
block- the block to add the dispatcher code totarget- the target object to set the property onparameters- the dispatcher method parameters (property name, value)
-
setMethodDispatcherCode
protected static void setMethodDispatcherCode(BlockStatement block, Expression target, Parameter[] parameters) Generates method dispatcher code for dynamic method invocation. Handles both single arguments and spread arguments.- Parameters:
block- the block to add the dispatcher code totarget- the target object to invoke methods onparameters- the dispatcher method parameters (method name, arguments)
-
getClassNode
Returns the class node to expose when wiring dispatch methods for an inner class.- Parameters:
cn- the enclosing class nodeisStatic- whether the generated access is static- Returns:
- the effective dispatch receiver type
-
getObjectDistance
Calculates the inheritance distance from the supplied type toObject.- Parameters:
cn- the class node to measure- Returns:
- the number of superclass hops to
Object
-
isStatic
Determines whether the supplied inner class behaves as a static nested class.- Parameters:
cn- the inner class node to test- Returns:
trueif no outer-instance field is required
-
shouldHandleImplicitThisForInnerClass
Determines whether synthetic outer-instance handling should be applied to the inner class.- Parameters:
cn- the class node to test- Returns:
trueif implicitthis$0handling is required
-