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:
Subclasses typically override specific visit methods to perform custom processing while inheriting default traversal behavior. Common extension points include:
Implementations must provide getSourceUnit() to support error reporting. The ErrorCollecting interface enables error accumulation during traversal.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addError(String error, ASTNode node)Adds an error message associated with an AST node to the source unit. |
|
protected abstract SourceUnit |
getSourceUnit()Provides access to the SourceUnit for error reporting during visitation. |
|
protected void |
visitAnnotation(AnnotationNode node)Visits an individual AnnotationNode, traversing all member expression values. |
|
public void |
visitAnnotations(AnnotatedNode node)Visits annotations on an AnnotatedNode, delegating to visitAnnotation(AnnotationNode). |
|
protected final void |
visitAnnotations(Iterable<AnnotationNode> nodes)Visits a collection of AnnotationNodes by processing each annotation individually. |
|
public void |
visitAssertStatement(AssertStatement statement)Visits an AssertStatement, invoking the statement hook before parent traversal. |
|
public void |
visitBlockStatement(BlockStatement statement)Visits a BlockStatement, invoking the statement hook before parent traversal. |
|
public void |
visitBreakStatement(BreakStatement statement)Visits a BreakStatement, invoking the statement hook before parent traversal. |
|
public void |
visitCaseStatement(CaseStatement statement)Visits a CaseStatement, invoking the statement hook before parent traversal. |
|
public void |
visitCatchStatement(CatchStatement statement)Visits a CatchStatement, processing variable annotations and invoking the statement hook. |
|
public void |
visitClass(ClassNode node)Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers. |
|
protected void |
visitClassCodeContainer(Statement code)Visits a code statement container, traversing it if present. |
|
public void |
visitClosureExpression(ClosureExpression expression)Visits a ClosureExpression with annotation processing, traversing parameter annotations before delegating to parent traversal. |
|
public void |
visitConstructor(ConstructorNode node)Visits a ConstructorNode, processing its annotations, parameter annotations, and code block. |
|
protected void |
visitConstructorOrMethod(MethodNode node, boolean isConstructor)Visits a constructor or method node (implementation detail for both visit methods). |
|
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 node)Visits a FieldNode, processing its annotations and initial value expression if present. |
|
public void |
visitForLoop(ForStatement statement)Visits a ForStatement, invoking statement hooks and processing loop variable annotations. |
|
public void |
visitIfElse(IfStatement statement)Visits an IfStatement, invoking the statement hook before parent traversal. |
|
public void |
visitImports(ModuleNode node)Visits all import declarations from a ModuleNode, including regular imports, star imports, static imports, and static star imports, processing their annotations. |
|
public void |
visitMethod(MethodNode node)Visits a MethodNode, processing its annotations, parameter annotations, and code block. |
|
protected void |
visitObjectInitializerStatements(ClassNode node)Visits all object initializer statements in a class, typically static or instance initialization blocks. |
|
public void |
visitPackage(PackageNode node)Visits a PackageNode if present, processing its annotations. |
|
public void |
visitProperty(PropertyNode node)Visits a PropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present. |
|
public void |
visitReturnStatement(ReturnStatement statement)Visits a ReturnStatement, invoking the statement hook before parent traversal. |
|
protected void |
visitStatement(Statement statement)Hook method called when visiting any Statement. |
|
protected void |
visitStatementAnnotations(Statement statement)Called for each loop statement ( for, while, do-while) that
carries statement-level annotations. |
|
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 |
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 |
visitWhileLoop(WhileStatement statement)Visits a WhileStatement, invoking statement hooks before parent traversal. |
Adds an error message associated with an AST node to the source unit. Errors are accumulated and reported after visitation completes.
error - the error message to reportnode - the AST node associated with the error locationProvides access to the SourceUnit for error reporting during visitation. Implementations must override this method.
Visits an individual AnnotationNode, traversing all member expression values. Subclasses may override to perform custom annotation processing.
node - the annotation node to visitVisits annotations on an AnnotatedNode, delegating to visitAnnotation(AnnotationNode).
node - the annotated node containing annotations to visitVisits a collection of AnnotationNodes by processing each annotation individually.
nodes - iterable collection of annotation nodes to visitVisits an AssertStatement, invoking the statement hook before parent traversal.
statement - the assert statement to visitVisits a BlockStatement, invoking the statement hook before parent traversal.
statement - the block statement to visitVisits a BreakStatement, invoking the statement hook before parent traversal.
statement - the break statement to visitVisits a CaseStatement, invoking the statement hook before parent traversal.
statement - the case statement to visitVisits a CatchStatement, processing variable annotations and invoking the statement hook.
statement - the catch statement to visitVisits a ClassNode, processing its annotations, package, imports, contents, and object initializers.
node - the class node to visitVisits a code statement container, traversing it if present.
code - the statement to visit, may be nullVisits a ClosureExpression with annotation processing, traversing parameter annotations before delegating to parent traversal.
expression - the closure expression to visitVisits a ConstructorNode, processing its annotations, parameter annotations, and code block.
node - the constructor node to visitVisits 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 nodeisConstructor - true if node is a constructor, false if it is a methodVisits a ContinueStatement, invoking the statement hook before parent traversal.
statement - the continue statement to visitVisits a DeclarationExpression with annotation processing, traversing expression annotations before delegating to parent traversal.
expression - the declaration expression to visitVisits a DoWhileStatement, invoking statement hooks before parent traversal.
statement - the do-while statement to visitVisits an ExpressionStatement, invoking the statement hook before parent traversal.
statement - the expression statement to visitVisits a FieldNode, processing its annotations and initial value expression if present.
node - the field node to visitVisits a ForStatement, invoking statement hooks and processing loop variable annotations.
statement - the for statement to visitVisits an IfStatement, invoking the statement hook before parent traversal.
statement - the if statement to visitVisits all import declarations from a ModuleNode, including regular imports, star imports, static imports, and static star imports, processing their annotations.
node - the module node containing imports, may be nullVisits a MethodNode, processing its annotations, parameter annotations, and code block.
node - the method node to visitVisits all object initializer statements in a class, typically static or instance initialization blocks.
node - the class node containing initializer statementsVisits a PackageNode if present, processing its annotations.
node - the package node, may be nullVisits a PropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.
node - the property node to visitVisits a ReturnStatement, invoking the statement hook before parent traversal.
statement - the return statement to visitHook method called when visiting any Statement. Subclasses may override to perform common processing on all statements.
statement - the statement being visited Called for each loop statement (for, while, do-while) that
carries statement-level annotations. Subclasses may override to process those annotations.
statement - the loop statement that may have statement-level annotationsVisits a SwitchStatement, invoking the statement hook before parent traversal.
statement - the switch statement to visitVisits a SynchronizedStatement, invoking the statement hook before parent traversal.
statement - the synchronized statement to visitVisits a ThrowStatement, invoking the statement hook before parent traversal.
statement - the throw statement to visitVisits a TryCatchStatement, invoking the statement hook before parent traversal.
statement - the try-catch statement to visitVisits a WhileStatement, invoking statement hooks before parent traversal.
statement - the while statement to visit