Package org.codehaus.groovy.ast
Class ClassCodeVisitorSupport
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
- All Implemented Interfaces:
GroovyClassVisitor,GroovyCodeVisitor,ErrorCollecting
- Direct Known Subclasses:
AbstractInterruptibleASTTransformation,AnnotationConstantsVisitor,AssertStatementCreationUtility.AddAssertionCallStatementToReturnStatementVisitor,AssertStatementCreationUtility.AddResultReturnStatementVisitor,AssertStatementCreationUtility.ReturnStatementVisitor,ASTTransformationCollectorCodeVisitor,ASTTransformationVisitor,BaseVisitor,ClassCodeExpressionTransformer,ClassCompletionVerifier,ClassGenerator,ContextualClassCodeVisitor,DependencyTracker,EnumCompletionVisitor,EnumVisitor,ExtendedVerifier,FinalVariableAnalyzer,GenericsVisitor,GrabAnnotationTransformation,GroovydocVisitor,InnerClassVisitorHelper,InstanceOfVerifier,LabelVerifier,PlaceholderVisitor,SharedVariableCollector,StaticTypeCheckingVisitor,StaticTypeCheckingVisitor.VariableExpressionTypeMemoizer,StaticVerifier,VariableScopeVisitor
public abstract class ClassCodeVisitorSupport
extends CodeVisitorSupport
implements ErrorCollecting, GroovyClassVisitor
Abstract base class for visitors that process class nodes and their members, extending the
default visitor traversal with class-specific and annotation processing.
This visitor combines CodeVisitorSupport with GroovyClassVisitor to provide
comprehensive traversal of class structures including:
- Class-level annotations and package/import declarations
- Class contents (fields, methods, properties) with member-level annotations
- Method parameters and their annotations
- Object initializer statements
Subclasses typically override specific visit methods to perform custom processing while inheriting default traversal behavior. Common extension points include:
visitStatement(Statement)- hook for statement-level processingvisitStatementAnnotations(Statement)- hook for statement annotations in loopsvisitAnnotation(AnnotationNode)- override to process annotations
Implementations must provide getSourceUnit() to support error reporting.
The ErrorCollecting interface enables error accumulation during traversal.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an error message associated with an AST node to the source unit.protected abstract SourceUnitProvides access to theSourceUnitfor error reporting during visitation.protected voidVisits an individualAnnotationNode, traversing all member expression values.protected final voidvisitAnnotations(Iterable<AnnotationNode> nodes) Visits a collection ofAnnotationNodes by processing each annotation individually.voidVisits annotations on anAnnotatedNode, delegating tovisitAnnotation(AnnotationNode).voidvisitAssertStatement(AssertStatement statement) Visits anAssertStatement, invoking the statement hook before parent traversal.voidvisitBlockStatement(BlockStatement statement) Visits aBlockStatement, invoking the statement hook before parent traversal.voidvisitBreakStatement(BreakStatement statement) Visits aBreakStatement, invoking the statement hook before parent traversal.voidvisitCaseStatement(CaseStatement statement) Visits aCaseStatement, invoking the statement hook before parent traversal.voidvisitCatchStatement(CatchStatement statement) Visits aCatchStatement, processing variable annotations and invoking the statement hook.voidvisitClass(ClassNode node) Visits aClassNode, processing its annotations, package, imports, contents, and object initializers.protected voidVisits a code statement container, traversing it if present.voidvisitClosureExpression(ClosureExpression expression) Visits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.voidVisits aConstructorNode, processing its annotations, parameter annotations, and code block.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 node) Visits aFieldNode, processing its annotations and initial value expression if present.voidvisitForLoop(ForStatement statement) Visits aForStatement, invoking statement hooks and processing loop variable annotations.voidvisitIfElse(IfStatement statement) Visits anIfStatement, invoking the statement hook before parent traversal.voidvisitImports(ModuleNode node) Visits all import declarations from aModuleNode, including regular imports, star imports, static imports, and static star imports, processing their annotations.voidvisitMethod(MethodNode node) Visits aMethodNode, processing its annotations, parameter annotations, and code block.protected voidVisits all object initializer statements in a class, typically static or instance initialization blocks.voidvisitPackage(PackageNode node) Visits aPackageNodeif present, processing its annotations.voidvisitProperty(PropertyNode node) Visits aPropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.voidvisitReturnStatement(ReturnStatement statement) Visits aReturnStatement, invoking the statement hook before parent traversal.protected voidvisitStatement(Statement statement) Hook method called when visiting anyStatement.protected voidvisitStatementAnnotations(Statement statement) Called for each loop statement (for,while,do-while) that carries statement-level annotations.voidvisitSwitch(SwitchStatement statement) Visits aSwitchStatement, invoking the statement hook before parent traversal.voidvisitSynchronizedStatement(SynchronizedStatement statement) Visits aSynchronizedStatement, invoking the statement hook before parent traversal.voidvisitThrowStatement(ThrowStatement statement) Visits aThrowStatement, invoking the statement hook before parent traversal.voidvisitTryCatchFinally(TryCatchStatement statement) Visits aTryCatchStatement, invoking the statement hook before parent traversal.voidvisitWhileLoop(WhileStatement statement) Visits aWhileStatement, invoking statement hooks before parent traversal.Methods 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
-
ClassCodeVisitorSupport
public ClassCodeVisitorSupport()
-
-
Method Details
-
visitClass
Visits aClassNode, processing its annotations, package, imports, contents, and object initializers.- Specified by:
visitClassin interfaceGroovyClassVisitor- Parameters:
node- the class node to visit
-
visitAnnotations
Visits annotations on anAnnotatedNode, delegating tovisitAnnotation(AnnotationNode).- Parameters:
node- the annotated node containing annotations to visit
-
visitAnnotations
Visits a collection ofAnnotationNodes by processing each annotation individually.- Parameters:
nodes- iterable collection of annotation nodes to visit
-
visitAnnotation
Visits an individualAnnotationNode, traversing all member expression values. Subclasses may override to perform custom annotation processing.- Parameters:
node- the annotation node to visit
-
visitPackage
Visits aPackageNodeif present, processing its annotations.- Parameters:
node- the package node, may be null
-
visitImports
Visits all import declarations from aModuleNode, including regular imports, star imports, static imports, and static star imports, processing their annotations.- Parameters:
node- the module node containing imports, may be null
-
visitConstructor
Visits aConstructorNode, processing its annotations, parameter annotations, and code block.- Specified by:
visitConstructorin interfaceGroovyClassVisitor- Parameters:
node- the constructor node to visit
-
visitMethod
Visits aMethodNode, processing its annotations, parameter annotations, and code block.- Specified by:
visitMethodin interfaceGroovyClassVisitor- Parameters:
node- the method 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.- Parameters:
node- the method or constructor nodeisConstructor- true if node is a constructor, false if it is a method
-
visitField
Visits aFieldNode, processing its annotations and initial value expression if present.- Specified by:
visitFieldin interfaceGroovyClassVisitor- Parameters:
node- the field node to visit
-
visitProperty
Visits aPropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.- Specified by:
visitPropertyin interfaceGroovyClassVisitor- Parameters:
node- the property node to visit
-
visitClassCodeContainer
Visits a code statement container, traversing it if present.- Parameters:
code- the statement to visit, may be null
-
visitObjectInitializerStatements
Visits all object initializer statements in a class, typically static or instance initialization blocks.- Parameters:
node- the class node containing initializer statements
-
visitClosureExpression
Visits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.- Specified by:
visitClosureExpressionin interfaceGroovyCodeVisitor- Overrides:
visitClosureExpressionin classCodeVisitorSupport- Parameters:
expression- the closure expression to visit
-
visitDeclarationExpression
Visits aDeclarationExpressionwith annotation processing, traversing expression annotations before delegating to parent traversal.- Specified by:
visitDeclarationExpressionin interfaceGroovyCodeVisitor- Overrides:
visitDeclarationExpressionin classCodeVisitorSupport- Parameters:
expression- the declaration expression to visit
-
visitAssertStatement
Visits anAssertStatement, invoking the statement hook before parent traversal.- Specified by:
visitAssertStatementin interfaceGroovyCodeVisitor- Overrides:
visitAssertStatementin classCodeVisitorSupport- Parameters:
statement- the assert statement to visit
-
visitBlockStatement
Visits aBlockStatement, invoking the statement hook before parent traversal.- Specified by:
visitBlockStatementin interfaceGroovyCodeVisitor- Overrides:
visitBlockStatementin classCodeVisitorSupport- Parameters:
statement- the block statement to visit- See Also:
-
visitBreakStatement
Visits aBreakStatement, invoking the statement hook before parent traversal.- Specified by:
visitBreakStatementin interfaceGroovyCodeVisitor- Overrides:
visitBreakStatementin classCodeVisitorSupport- Parameters:
statement- the break statement to visit
-
visitCaseStatement
Visits aCaseStatement, invoking the statement hook before parent traversal.- Specified by:
visitCaseStatementin interfaceGroovyCodeVisitor- Overrides:
visitCaseStatementin classCodeVisitorSupport- Parameters:
statement- the case statement to visit
-
visitCatchStatement
Visits aCatchStatement, processing variable annotations and invoking the statement hook.- Specified by:
visitCatchStatementin interfaceGroovyCodeVisitor- Overrides:
visitCatchStatementin classCodeVisitorSupport- Parameters:
statement- the catch statement to visit
-
visitContinueStatement
Visits aContinueStatement, invoking the statement hook before parent traversal.- Specified by:
visitContinueStatementin interfaceGroovyCodeVisitor- Overrides:
visitContinueStatementin classCodeVisitorSupport- Parameters:
statement- the continue statement to visit
-
visitDoWhileLoop
Visits aDoWhileStatement, invoking statement hooks before parent traversal.- Specified by:
visitDoWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitDoWhileLoopin classCodeVisitorSupport- Parameters:
statement- the do-while statement to visit
-
visitExpressionStatement
Visits anExpressionStatement, invoking the statement hook before parent traversal.- Specified by:
visitExpressionStatementin interfaceGroovyCodeVisitor- Overrides:
visitExpressionStatementin classCodeVisitorSupport- Parameters:
statement- the expression statement to visit
-
visitForLoop
Visits aForStatement, invoking statement hooks and processing loop variable annotations.- Specified by:
visitForLoopin interfaceGroovyCodeVisitor- Overrides:
visitForLoopin classCodeVisitorSupport- Parameters:
statement- the for statement to visit
-
visitIfElse
Visits anIfStatement, invoking the statement hook before parent traversal.- Specified by:
visitIfElsein interfaceGroovyCodeVisitor- Overrides:
visitIfElsein classCodeVisitorSupport- Parameters:
statement- the if statement to visit
-
visitReturnStatement
Visits aReturnStatement, invoking the statement hook before parent traversal.- Specified by:
visitReturnStatementin interfaceGroovyCodeVisitor- Overrides:
visitReturnStatementin classCodeVisitorSupport- Parameters:
statement- the return statement to visit
-
visitSwitch
Visits aSwitchStatement, invoking the statement hook before parent traversal.- Specified by:
visitSwitchin interfaceGroovyCodeVisitor- Overrides:
visitSwitchin classCodeVisitorSupport- Parameters:
statement- the switch statement to visit
-
visitSynchronizedStatement
Visits aSynchronizedStatement, invoking the statement hook before parent traversal.- Specified by:
visitSynchronizedStatementin interfaceGroovyCodeVisitor- Overrides:
visitSynchronizedStatementin classCodeVisitorSupport- Parameters:
statement- the synchronized statement to visit
-
visitThrowStatement
Visits aThrowStatement, invoking the statement hook before parent traversal.- Specified by:
visitThrowStatementin interfaceGroovyCodeVisitor- Overrides:
visitThrowStatementin classCodeVisitorSupport- Parameters:
statement- the throw statement to visit
-
visitTryCatchFinally
Visits aTryCatchStatement, invoking the statement hook before parent traversal.- Specified by:
visitTryCatchFinallyin interfaceGroovyCodeVisitor- Overrides:
visitTryCatchFinallyin classCodeVisitorSupport- Parameters:
statement- the try-catch statement to visit
-
visitWhileLoop
Visits aWhileStatement, invoking statement hooks before parent traversal.- Specified by:
visitWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitWhileLoopin classCodeVisitorSupport- Parameters:
statement- the while statement to visit
-
visitStatement
Hook method called when visiting anyStatement. Subclasses may override to perform common processing on all statements.- Parameters:
statement- the statement being visited
-
visitStatementAnnotations
Called for each loop statement (for,while,do-while) that carries statement-level annotations. Subclasses may override to process those annotations.- Parameters:
statement- the loop statement that may have statement-level annotations- Since:
- 6.0.0
-
getSourceUnit
Provides access to theSourceUnitfor error reporting during visitation. Implementations must override this method.- Returns:
- the source unit for this visitor
-
addError
Adds an error message associated with an AST node to the source unit. Errors are accumulated and reported after visitation completes.- Specified by:
addErrorin interfaceErrorCollecting- Parameters:
error- the error message to reportnode- the AST node associated with the error location- See Also:
-