Package org.codehaus.groovy.ast

# Class AnnotatedNode

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode

All Implemented Interfaces:
  `GroovydocHolder<AnnotatedNode>`, `NodeMetaDataHandler`

Direct Known Subclasses:
  `ClassNode`, `Expression`, `FieldNode`, `ImportNode`, `MethodNode`, `PackageNode`, `Parameter`, `PropertyNode`, `RecordComponentNode`

public class AnnotatedNode extends ASTNode implements GroovydocHolder<AnnotatedNode>
Base class for any AST node which is capable of being annotated

- ## Field Summary

  ### Fields inherited from interface groovy.lang.groovydoc.GroovydocHolder

  `DOC_COMMENT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AnnotatedNode()`

- ## Method Summary

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

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

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

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## Constructor Details

  - ### AnnotatedNode

    public AnnotatedNode()

- ## Method Details

  - ### getAnnotations

    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

  - ### getAnnotations

    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

  - ### addAnnotation

    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`

  - ### addAnnotation

    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

  - ### addAnnotations

    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

  - ### getDeclaringClass

    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

  - ### setDeclaringClass

    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`

  - ### getGroovydoc

    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.
    Specified by:
      `getGroovydoc` in interface `GroovydocHolder<AnnotatedNode>`
    Returns:
      the `Groovydoc` for this node

  - ### getInstance

    public AnnotatedNode getInstance()
    Returns this node instance (used by `GroovydocHolder` interface).
    Specified by:
      `getInstance` in interface `GroovydocHolder<AnnotatedNode>`
    Returns:
      this AnnotatedNode

  - ### hasNoRealSourcePosition

    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()`

  - ### setHasNoRealSourcePosition

    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

  - ### isSynthetic

    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

  - ### setSynthetic

    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