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 processing
- `visitStatementAnnotations(Statement)` - hook for statement annotations in loops
- `visitAnnotation(AnnotationNode)` - override to process annotations

Implementations must provide `getSourceUnit()` to support error reporting. The `ErrorCollecting` interface enables error accumulation during traversal.

See Also:
  - `for expression and basic statement processing`
  - `for class-level visiting interface`
  - `for error handling`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ClassCodeVisitorSupport()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.
  `protected final void`
  `visitAnnotations(Iterable<AnnotationNode> nodes)`
  Visits a collection of `AnnotationNode`s by processing each annotation individually.
  `void`
  `visitAnnotations(AnnotatedNode node)`
  Visits annotations on an `AnnotatedNode`, delegating to `visitAnnotation(AnnotationNode)`.
  `void`
  `visitAssertStatement(AssertStatement statement)`
  Visits an `AssertStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitBlockStatement(BlockStatement statement)`
  Visits a `BlockStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitBreakStatement(BreakStatement statement)`
  Visits a `BreakStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitCaseStatement(CaseStatement statement)`
  Visits a `CaseStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitCatchStatement(CatchStatement statement)`
  Visits a `CatchStatement`, processing variable annotations and invoking the statement hook.
  `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.
  `void`
  `visitClosureExpression(ClosureExpression expression)`
  Visits a `ClosureExpression` with annotation processing, traversing parameter annotations before delegating to parent traversal.
  `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).
  `void`
  `visitContinueStatement(ContinueStatement statement)`
  Visits a `ContinueStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitDeclarationExpression(DeclarationExpression expression)`
  Visits a `DeclarationExpression` with annotation processing, traversing expression annotations before delegating to parent traversal.
  `void`
  `visitDoWhileLoop(DoWhileStatement statement)`
  Visits a `DoWhileStatement`, invoking statement hooks before parent traversal.
  `void`
  `visitExpressionStatement(ExpressionStatement statement)`
  Visits an `ExpressionStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitField(FieldNode node)`
  Visits a `FieldNode`, processing its annotations and initial value expression if present.
  `void`
  `visitForLoop(ForStatement statement)`
  Visits a `ForStatement`, invoking statement hooks and processing loop variable annotations.
  `void`
  `visitIfElse(IfStatement statement)`
  Visits an `IfStatement`, invoking the statement hook before parent traversal.
  `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.
  `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.
  `void`
  `visitPackage(PackageNode node)`
  Visits a `PackageNode` if present, processing its annotations.
  `void`
  `visitProperty(PropertyNode node)`
  Visits a `PropertyNode`, processing its annotations, initial value expression, and getter/setter blocks if present.
  `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.
  `void`
  `visitSwitch(SwitchStatement statement)`
  Visits a `SwitchStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitSynchronizedStatement(SynchronizedStatement statement)`
  Visits a `SynchronizedStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitThrowStatement(ThrowStatement statement)`
  Visits a `ThrowStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitTryCatchFinally(TryCatchStatement statement)`
  Visits a `TryCatchStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitWhileLoop(WhileStatement statement)`
  Visits a `WhileStatement`, 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, visitVariableExpression`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor

  `visit, visit, visitEmptyExpression, visitListOfExpressions`

- ## Constructor Details

  - ### ClassCodeVisitorSupport

    public ClassCodeVisitorSupport()

- ## Method Details

  - ### visitClass

    public void visitClass(ClassNode node)
    Visits a `ClassNode`, processing its annotations, package, imports, contents, and object initializers.
    Specified by:
      `visitClass` in interface `GroovyClassVisitor`
    Parameters:
      `node` - the class node to visit

  - ### visitAnnotations

    public void visitAnnotations(AnnotatedNode node)
    Visits annotations on an `AnnotatedNode`, delegating to `visitAnnotation(AnnotationNode)`.
    Parameters:
      `node` - the annotated node containing annotations to visit

  - ### visitAnnotations

    protected final void visitAnnotations(Iterable<AnnotationNode> nodes)
    Visits a collection of `AnnotationNode`s by processing each annotation individually.
    Parameters:
      `nodes` - iterable collection of annotation nodes to visit

  - ### visitAnnotation

    protected void visitAnnotation(AnnotationNode node)
    Visits an individual `AnnotationNode`, traversing all member expression values. Subclasses may override to perform custom annotation processing.
    Parameters:
      `node` - the annotation node to visit

  - ### visitPackage

    public void visitPackage(PackageNode node)
    Visits a `PackageNode` if present, processing its annotations.
    Parameters:
      `node` - the package node, may be null

  - ### visitImports

    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.
    Parameters:
      `node` - the module node containing imports, may be null

  - ### visitConstructor

    public void visitConstructor(ConstructorNode node)
    Visits a `ConstructorNode`, processing its annotations, parameter annotations, and code block.
    Specified by:
      `visitConstructor` in interface `GroovyClassVisitor`
    Parameters:
      `node` - the constructor node to visit

  - ### visitMethod

    public void visitMethod(MethodNode node)
    Visits a `MethodNode`, processing its annotations, parameter annotations, and code block.
    Specified by:
      `visitMethod` in interface `GroovyClassVisitor`
    Parameters:
      `node` - the method node to visit

  - ### visitConstructorOrMethod

    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.
    Parameters:
      `node` - the method or constructor node
      `isConstructor` - true if node is a constructor, false if it is a method

  - ### visitField

    public void visitField(FieldNode node)
    Visits a `FieldNode`, processing its annotations and initial value expression if present.
    Specified by:
      `visitField` in interface `GroovyClassVisitor`
    Parameters:
      `node` - the field node to visit

  - ### visitProperty

    public void visitProperty(PropertyNode node)
    Visits a `PropertyNode`, processing its annotations, initial value expression, and getter/setter blocks if present.
    Specified by:
      `visitProperty` in interface `GroovyClassVisitor`
    Parameters:
      `node` - the property node to visit

  - ### visitClassCodeContainer

    protected void visitClassCodeContainer(Statement code)
    Visits a code statement container, traversing it if present.
    Parameters:
      `code` - the statement to visit, may be null

  - ### visitObjectInitializerStatements

    protected void visitObjectInitializerStatements(ClassNode node)
    Visits all object initializer statements in a class, typically static or instance initialization blocks.
    Parameters:
      `node` - the class node containing initializer statements

  - ### visitClosureExpression

    public void visitClosureExpression(ClosureExpression expression)
    Visits a `ClosureExpression` with annotation processing, traversing parameter annotations before delegating to parent traversal.
    Specified by:
      `visitClosureExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitClosureExpression` in class `CodeVisitorSupport`
    Parameters:
      `expression` - the closure expression to visit

  - ### visitDeclarationExpression

    public void visitDeclarationExpression(DeclarationExpression expression)
    Visits a `DeclarationExpression` with annotation processing, traversing expression annotations before delegating to parent traversal.
    Specified by:
      `visitDeclarationExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitDeclarationExpression` in class `CodeVisitorSupport`
    Parameters:
      `expression` - the declaration expression to visit

  - ### visitAssertStatement

    public void visitAssertStatement(AssertStatement statement)
    Visits an `AssertStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitAssertStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitAssertStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the assert statement to visit

  - ### visitBlockStatement

    public void visitBlockStatement(BlockStatement statement)
    Visits a `BlockStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitBlockStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitBlockStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the block statement to visit
    See Also:
      - `CodeVisitorSupport.visitForLoop(ForStatement)`
      - `CodeVisitorSupport.visitWhileLoop(WhileStatement)`

  - ### visitBreakStatement

    public void visitBreakStatement(BreakStatement statement)
    Visits a `BreakStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitBreakStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitBreakStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the break statement to visit

  - ### visitCaseStatement

    public void visitCaseStatement(CaseStatement statement)
    Visits a `CaseStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitCaseStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitCaseStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the case statement to visit

  - ### visitCatchStatement

    public void visitCatchStatement(CatchStatement statement)
    Visits a `CatchStatement`, processing variable annotations and invoking the statement hook.
    Specified by:
      `visitCatchStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitCatchStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the catch statement to visit

  - ### visitContinueStatement

    public void visitContinueStatement(ContinueStatement statement)
    Visits a `ContinueStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitContinueStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitContinueStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the continue statement to visit

  - ### visitDoWhileLoop

    public void visitDoWhileLoop(DoWhileStatement statement)
    Visits a `DoWhileStatement`, invoking statement hooks before parent traversal.
    Specified by:
      `visitDoWhileLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitDoWhileLoop` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the do-while statement to visit

  - ### visitExpressionStatement

    public void visitExpressionStatement(ExpressionStatement statement)
    Visits an `ExpressionStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitExpressionStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitExpressionStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the expression statement to visit

  - ### visitForLoop

    public void visitForLoop(ForStatement statement)
    Visits a `ForStatement`, invoking statement hooks and processing loop variable annotations.
    Specified by:
      `visitForLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitForLoop` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the for statement to visit

  - ### visitIfElse

    public void visitIfElse(IfStatement statement)
    Visits an `IfStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitIfElse` in interface `GroovyCodeVisitor`
    Overrides:
      `visitIfElse` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the if statement to visit

  - ### visitReturnStatement

    public void visitReturnStatement(ReturnStatement statement)
    Visits a `ReturnStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitReturnStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitReturnStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the return statement to visit

  - ### visitSwitch

    public void visitSwitch(SwitchStatement statement)
    Visits a `SwitchStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitSwitch` in interface `GroovyCodeVisitor`
    Overrides:
      `visitSwitch` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the switch statement to visit

  - ### visitSynchronizedStatement

    public void visitSynchronizedStatement(SynchronizedStatement statement)
    Visits a `SynchronizedStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitSynchronizedStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitSynchronizedStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the synchronized statement to visit

  - ### visitThrowStatement

    public void visitThrowStatement(ThrowStatement statement)
    Visits a `ThrowStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitThrowStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitThrowStatement` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the throw statement to visit

  - ### visitTryCatchFinally

    public void visitTryCatchFinally(TryCatchStatement statement)
    Visits a `TryCatchStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitTryCatchFinally` in interface `GroovyCodeVisitor`
    Overrides:
      `visitTryCatchFinally` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the try-catch statement to visit

  - ### visitWhileLoop

    public void visitWhileLoop(WhileStatement statement)
    Visits a `WhileStatement`, invoking statement hooks before parent traversal.
    Specified by:
      `visitWhileLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitWhileLoop` in class `CodeVisitorSupport`
    Parameters:
      `statement` - the while statement to visit

  - ### visitStatement

    protected void visitStatement(Statement statement)
    Hook method called when visiting any `Statement`. Subclasses may override to perform common processing on all statements.
    Parameters:
      `statement` - the statement being visited

  - ### visitStatementAnnotations

    protected void visitStatementAnnotations(Statement statement)
    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

    protected abstract SourceUnit getSourceUnit()
    Provides access to the `SourceUnit` for error reporting during visitation. Implementations must override this method.
    Returns:
      the source unit for this visitor

  - ### addError

    public void addError(String error, ASTNode node)
    Adds an error message associated with an AST node to the source unit. Errors are accumulated and reported after visitation completes.
    Specified by:
      `addError` in interface `ErrorCollecting`
    Parameters:
      `error` - the error message to report
      `node` - the AST node associated with the error location
    See Also:
      - `ErrorCollecting`