Package: org.codehaus.groovy.classgen

## [Java] Class AnnotationVisitor

- org.codehaus.groovy.classgen.AnnotationVisitor

-     public class AnnotationVisitor
      extends Object

  An Annotation visitor responsible for:

  - reading annotation metadata (@Retention, @Target, attribute types)
  - verify that an `AnnotationNode` conforms to annotation meta
  - enhancing an `AnnotationNode` AST to reflect real annotation meta

- - ### Constructor Summary

    Constructors
    Constructor and description
    `AnnotationVisitor(SourceUnit source, ErrorCollector errorCollector)` Creates a new annotation visitor.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `addError(String msg)` Reports an error against the current annotation.
    `` | `protected void` | `addError(String msg, ASTNode node)` Reports an error against the supplied AST node.
    `` | `public void` | `checkCircularReference(ClassNode searchClass, ClassNode attrType, Expression startExp)` Checks for circular references in nested annotations, which would cause infinite recursion.
    `` | `public void` | `checkReturnType(ClassNode attrType, ASTNode node)` Verifies that an annotation member return type is valid under Java annotation rules.
    `` | `public void` | `setReportClass(ClassNode node)` Sets the class to report errors against.
    `` | `public AnnotationNode` | `visit(AnnotationNode node)` Visits and validates an annotation node, checking that it conforms to annotation metadata and enhancing the AST to reflect real annotation semantics.
    `` | `protected void` | `visitAnnotationExpression(String attrName, AnnotationConstantExpression valueExpr, ClassNode attrType)` Validates a nested annotation attribute.
    `` | `protected void` | `visitConstantExpression(String attrName, ConstantExpression valueExpr, ClassNode attrType)` Validates a constant-valued annotation attribute.
    `` | `protected void` | `visitEnumExpression(String attrName, PropertyExpression valueExpr, ClassNode attrType)` Validates an enum-valued annotation attribute.
    `` | `protected void` | `visitExpression(String attrName, Expression valueExpr, ClassNode attrType)` Validates an annotation attribute value against its declared type.
    `` | `protected void` | `visitListExpression(String attrName, ListExpression listExpr, ClassNode elementType)` Validates each element of an array-valued annotation attribute.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### public AnnotationVisitor(SourceUnit source, ErrorCollector errorCollector)

      Creates a new annotation visitor.

      Parameters:
        `source` - the source unit being compiled
        `errorCollector` - the error collector for reporting validation errors

  - ### Method Detail

    - #### protected void addError(String msg)

      Reports an error against the current annotation.

      Parameters:
        `msg` - the error message

    - #### protected void addError(String msg, ASTNode node)

      Reports an error against the supplied AST node.

      Parameters:
        `msg` - the error message
        `node` - the node to associate with the error

    - #### public void checkCircularReference(ClassNode searchClass, ClassNode attrType, Expression startExp)

      Checks for circular references in nested annotations, which would cause infinite recursion.

      Parameters:
        `searchClass` - the annotation class being searched for in the dependency chain
        `attrType` - the attribute type to check
        `startExp` - the expression where the check started, for error reporting

    - #### public void checkReturnType(ClassNode attrType, ASTNode node)

      Verifies that an annotation member return type is valid under Java annotation rules.

      Parameters:
        `attrType` - the declared return type
        `node` - the node to report against on error

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

      Sets the class to report errors against.

      Parameters:
        `node` - the class node for error reporting

    - #### public AnnotationNode visit(AnnotationNode node)

      Visits and validates an annotation node, checking that it conforms to annotation metadata and enhancing the AST to reflect real annotation semantics.

      Parameters:
        `node` - the annotation node to visit and validate
      Returns:
        the validated and potentially modified annotation node

    - #### protected void visitAnnotationExpression(String attrName, AnnotationConstantExpression valueExpr, ClassNode attrType)

      Validates a nested annotation attribute.

      Parameters:
        `attrName` - the attribute name
        `valueExpr` - the nested annotation expression
        `attrType` - the declared annotation type

    - #### protected void visitConstantExpression(String attrName, ConstantExpression valueExpr, ClassNode attrType)

      Validates a constant-valued annotation attribute.

      Parameters:
        `attrName` - the attribute name
        `valueExpr` - the constant expression
        `attrType` - the declared attribute type

    - #### protected void visitEnumExpression(String attrName, PropertyExpression valueExpr, ClassNode attrType)

      Validates an enum-valued annotation attribute.

      Parameters:
        `attrName` - the attribute name
        `valueExpr` - the enum constant expression
        `attrType` - the declared enum type

    - #### protected void visitExpression(String attrName, Expression valueExpr, ClassNode attrType)

      Validates an annotation attribute value against its declared type.

      Parameters:
        `attrName` - the attribute name
        `valueExpr` - the supplied value expression
        `attrType` - the declared attribute type

    - #### protected void visitListExpression(String attrName, ListExpression listExpr, ClassNode elementType)

      Validates each element of an array-valued annotation attribute.

      Parameters:
        `attrName` - the attribute name
        `listExpr` - the list expression representing the attribute value
        `elementType` - the declared component type