Package: org.codehaus.groovy.ast

## [Java] Class ClassCodeVisitorSupport

- org.codehaus.groovy.ast.ClassCodeVisitorSupport

- All Implemented Interfaces and Traits:
    ErrorCollecting, GroovyClassVisitor

      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

- - ### Methods Summary

    Methods
    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.
    `` | `public void` | `visitYieldStatement(YieldStatement statement)` Visits a YieldStatement, invoking the statement hook before parent traversal (GROOVY-12255).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class CodeVisitorSupport` | `afterSwitchCaseStatementsVisited, afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSwitchExpression, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop, visitYieldStatement`

- - ### Method Detail

    - #### 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.

      The error counts towards the configured error tolerance, so visitation may be cut short once that many errors have been collected (GROOVY-12306). Use ErrorCollector.addErrorAndContinue directly to report an error which must never bail out.

      Parameters:
        `error` - the error message to report
        `node` - the AST node associated with the error location
      See Also:
        ErrorCollecting

    - #### 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

    - #### 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

    - #### public void visitAnnotations(AnnotatedNode node)

      Visits annotations on an AnnotatedNode, delegating to visitAnnotation(AnnotationNode).

      Parameters:
        `node` - the annotated node containing annotations to visit

    - #### protected final void visitAnnotations(Iterable<AnnotationNode> nodes)

      Visits a collection of AnnotationNodes by processing each annotation individually.

      Parameters:
        `nodes` - iterable collection of annotation nodes to visit

    - #### public void visitAssertStatement(AssertStatement statement)

      Visits an AssertStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the assert statement to visit

    - #### public void visitBlockStatement(BlockStatement statement)

      Visits a BlockStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the block statement to visit

    - #### public void visitBreakStatement(BreakStatement statement)

      Visits a BreakStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the break statement to visit

    - #### public void visitCaseStatement(CaseStatement statement)

      Visits a CaseStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the case statement to visit

    - #### public void visitCatchStatement(CatchStatement statement)

      Visits a CatchStatement, processing variable annotations and invoking the statement hook.

      Parameters:
        `statement` - the catch statement to visit

    - #### public void visitClass(ClassNode node)

      Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers.

      Parameters:
        `node` - the class node to visit

    - #### protected void visitClassCodeContainer(Statement code)

      Visits a code statement container, traversing it if present.

      Parameters:
        `code` - the statement to visit, may be null

    - #### public void visitClosureExpression(ClosureExpression expression)

      Visits a ClosureExpression with annotation processing, traversing parameter annotations before delegating to parent traversal.

      Parameters:
        `expression` - the closure expression to visit

    - #### public void visitConstructor(ConstructorNode node)

      Visits a ConstructorNode, processing its annotations, parameter annotations, and code block.

      Parameters:
        `node` - the constructor node to visit

    - #### 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

    - #### public void visitContinueStatement(ContinueStatement statement)

      Visits a ContinueStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the continue statement to visit

    - #### public void visitDeclarationExpression(DeclarationExpression expression)

      Visits a DeclarationExpression with annotation processing, traversing expression annotations before delegating to parent traversal.

      Parameters:
        `expression` - the declaration expression to visit

    - #### public void visitDoWhileLoop(DoWhileStatement statement)

      Visits a DoWhileStatement, invoking statement hooks before parent traversal.

      Parameters:
        `statement` - the do-while statement to visit

    - #### public void visitExpressionStatement(ExpressionStatement statement)

      Visits an ExpressionStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the expression statement to visit

    - #### public void visitField(FieldNode node)

      Visits a FieldNode, processing its annotations and initial value expression if present.

      Parameters:
        `node` - the field node to visit

    - #### public void visitForLoop(ForStatement statement)

      Visits a ForStatement, invoking statement hooks and processing loop variable annotations.

      Parameters:
        `statement` - the for statement to visit

    - #### public void visitIfElse(IfStatement statement)

      Visits an IfStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the if statement to visit

    - #### 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

    - #### public void visitMethod(MethodNode node)

      Visits a MethodNode, processing its annotations, parameter annotations, and code block.

      Parameters:
        `node` - the method node to visit

    - #### 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

    - #### public void visitPackage(PackageNode node)

      Visits a PackageNode if present, processing its annotations.

      Parameters:
        `node` - the package node, may be null

    - #### public void visitProperty(PropertyNode node)

      Visits a PropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.

      Parameters:
        `node` - the property node to visit

    - #### public void visitReturnStatement(ReturnStatement statement)

      Visits a ReturnStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the return statement to visit

    - #### 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

    - #### 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

    - #### public void visitSwitch(SwitchStatement statement)

      Visits a SwitchStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the switch statement to visit

    - #### public void visitSynchronizedStatement(SynchronizedStatement statement)

      Visits a SynchronizedStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the synchronized statement to visit

    - #### public void visitThrowStatement(ThrowStatement statement)

      Visits a ThrowStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the throw statement to visit

    - #### public void visitTryCatchFinally(TryCatchStatement statement)

      Visits a TryCatchStatement, invoking the statement hook before parent traversal.

      Parameters:
        `statement` - the try-catch statement to visit

    - #### public void visitWhileLoop(WhileStatement statement)

      Visits a WhileStatement, invoking statement hooks before parent traversal.

      Parameters:
        `statement` - the while statement to visit

    - #### public void visitYieldStatement(YieldStatement statement)

      Visits a YieldStatement, invoking the statement hook before parent traversal (GROOVY-12255).

      Parameters:
        `statement` - the yield statement to visit
      Since:
        6.0.0