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
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotation(AnnotationNode annotation) Attaches an annotation node to this AST node.addAnnotation(ClassNode type) Adds a new annotation of the specified type to this node.voidaddAnnotations(List<AnnotationNode> annotations) Attaches a list of annotations to this AST node.Returns all annotations attached to this AST node.getAnnotations(ClassNode type) Returns annotations of a specific type attached to this AST node.Returns the class that declares this annotated node.Returns the Groovydoc associated with this node.Returns this node instance (used byGroovydocHolderinterface).booleanChecks whether this node has a real source position.booleanChecks whether this node was added by the compiler (synthetic).voidsetDeclaringClass(ClassNode declaringClass) Sets the class that declares this annotated node.voidsetHasNoRealSourcePosition(boolean hasNoRealSourcePosition) Marks whether this node has a real source position.voidsetSynthetic(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, visitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
AnnotatedNode
public AnnotatedNode()
-
-
Method Details
-
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
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
Adds a new annotation of the specified type to this node. Creates anAnnotationNodeand attaches it.- Parameters:
type- the annotation type as aClassNode- Returns:
- the newly created
AnnotationNode
-
addAnnotation
Attaches an annotation node to this AST node. Does nothing if the annotation is null. Lazily initializes the annotations list.- Parameters:
annotation- theAnnotationNodeto attach
-
addAnnotations
Attaches a list of annotations to this AST node. Individually adds each annotation in the list.- Parameters:
annotations- list ofAnnotationNodeobjects to attach
-
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
Sets the class that declares this annotated node. Establishes the ownership relationship for class members.- Parameters:
declaringClass- the declaringClassNode
-
getGroovydoc
Returns the Groovydoc associated with this node. Groovydoc is documentation metadata attached to source elements. ReturnsGroovydoc.EMPTY_GROOVYDOCif no documentation is available.- Specified by:
getGroovydocin interfaceGroovydocHolder<AnnotatedNode>- Returns:
- the
Groovydocfor this node
-
getInstance
Returns this node instance (used byGroovydocHolderinterface).- Specified by:
getInstancein interfaceGroovydocHolder<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:
-
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 thesyntheticmodifier 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 thesyntheticmodifier for classes, fields, and methods in bytecode.- Parameters:
synthetic- true to mark as compiler-generated, false for user-written
-