Package: org.codehaus.groovy.ast

## [Java] Class AnnotatedNode

- org.codehaus.groovy.ast.AnnotatedNode

- All Implemented Interfaces and Traits:
    GroovydocHolder

      public class AnnotatedNode
      extends ASTNode
      implements GroovydocHolder

  Base class for any AST node which is capable of being annotated

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public AnnotationNode` | `addAnnotation(ClassNode type)` Adds a new annotation of the specified type to this node.
    `` | `public void` | `addAnnotation(AnnotationNode annotation)` Attaches an annotation node to this AST node.
    `` | `public void` | `addAnnotations(List<AnnotationNode> annotations)` Attaches a list of annotations to this AST node.
    `` | `public List<AnnotationNode>` | `getAnnotations()` Returns all annotations attached to this AST node.
    `` | `public List<AnnotationNode>` | `getAnnotations(ClassNode type)` Returns annotations of a specific type attached to this AST node.
    `` | `public ClassNode` | `getDeclaringClass()` Returns the class that declares this annotated node.
    `` | `public Groovydoc` | `getGroovydoc()` Returns the Groovydoc associated with this node.
    `` | `public AnnotatedNode` | `getInstance()` Returns this node instance (used by GroovydocHolder interface).
    `` | `public boolean` | `hasNoRealSourcePosition()` Checks whether this node has a real source position.
    `` | `public boolean` | `isSynthetic()` Checks whether this node was added by the compiler (synthetic).
    `` | `public void` | `setDeclaringClass(ClassNode declaringClass)` Sets the class that declares this annotated node.
    `` | `public void` | `setHasNoRealSourcePosition(boolean hasNoRealSourcePosition)` Marks whether this node has a real source position.
    `` | `public void` | `setSynthetic(boolean synthetic)` Marks this node as having been added by the compiler (synthetic).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ASTNode` | `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

- - ### Method Detail

    - #### public AnnotationNode addAnnotation(ClassNode type)

      Adds a new annotation of the specified type to this node. Creates an AnnotationNode and attaches it.

      Parameters:
        `type` - the annotation type as a ClassNode
      Returns:
        the newly created AnnotationNode

    - #### public void addAnnotation(AnnotationNode annotation)

      Attaches an annotation node to this AST node. Does nothing if the annotation is null. Lazily initializes the annotations list.

      Parameters:
        `annotation` - the AnnotationNode to attach

    - #### public void addAnnotations(List<AnnotationNode> annotations)

      Attaches a list of annotations to this AST node. Individually adds each annotation in the list.

      Parameters:
        `annotations` - list of AnnotationNode objects to attach

    - #### public List<AnnotationNode> getAnnotations()

      Returns all annotations attached to this AST node. Annotations are runtime-visible or source-level metadata attached to language elements.

      Returns:
        list of AnnotationNode, or empty list if none

    - #### public List<AnnotationNode> getAnnotations(ClassNode type)

      Returns annotations of a specific type attached to this AST node. Filters the annotation list by the provided type.

      Parameters:
        `type` - the annotation type to filter by
      Returns:
        list of matching AnnotationNode, or empty list if none

    - #### public ClassNode getDeclaringClass()

      Returns the class that declares this annotated node. For class members (fields, methods), this is the enclosing class. Returns null for top-level declarations.

      Returns:
        the declaring ClassNode, or null if none

    - #### public Groovydoc getGroovydoc()

      Returns the Groovydoc associated with this node. Groovydoc is documentation metadata attached to source elements. Returns Groovydoc.EMPTY_GROOVYDOC if no documentation is available.

      Returns:
        the Groovydoc for this node

    - #### public AnnotatedNode getInstance()

      Returns this node instance (used by GroovydocHolder interface).

      Returns:
        this AnnotatedNode

    - #### public boolean hasNoRealSourcePosition()

      Checks whether this node has a real source position. Returns false for compiler-generated nodes (like default constructors). This flag distinguishes user-written code from synthetic compiler output.

      Returns:
        true if this node was explicitly written in source code
      See Also:
        hasNoRealSourcePosition()

    - #### public boolean isSynthetic()

      Checks whether this node was added by the compiler (synthetic). Synthetic nodes include auto-generated methods, constructors, and other compiler-inserted elements. Note: This flag is distinct from the `synthetic` modifier for classes, fields, and methods in bytecode.

      Returns:
        true if this node was generated by the compiler, false if user-written

    - #### public void setDeclaringClass(ClassNode declaringClass)

      Sets the class that declares this annotated node. Establishes the ownership relationship for class members.

      Parameters:
        `declaringClass` - the declaring ClassNode

    - #### public void setHasNoRealSourcePosition(boolean hasNoRealSourcePosition)

      Marks whether this node has a real source position. Used to distinguish compiler-generated nodes from user-written code.

      Parameters:
        `hasNoRealSourcePosition` - false if this node was explicitly written in source

    - #### public void setSynthetic(boolean synthetic)

      Marks this node as having been added by the compiler (synthetic). Synthetic nodes include auto-generated methods, constructors, and other compiler-inserted elements. Note: This flag is distinct from the `synthetic` modifier for classes, fields, and methods in bytecode.

      Parameters:
        `synthetic` - true to mark as compiler-generated, false for user-written