public class AnnotationNode
extends ASTNode
Represents an annotation which can be attached to interfaces, classes, methods, fields, parameters, and other places.
| Modifiers | Name | Description |
|---|---|---|
static int |
ANNOTATION_TARGET |
Bit for ElementType.ANNOTATION_TYPE. |
static int |
CONSTRUCTOR_TARGET |
Bit for ElementType.CONSTRUCTOR. |
static int |
FIELD_TARGET |
Bit for ElementType.FIELD. |
static int |
IMPORT_TARGET |
Groovy-only target for annotations on import statements. |
static int |
LOCAL_VARIABLE_TARGET |
Bit for ElementType.LOCAL_VARIABLE. |
static int |
METHOD_TARGET |
Bit for ElementType.METHOD. |
static int |
PACKAGE_TARGET |
Bit for ElementType.PACKAGE. |
static int |
PARAMETER_TARGET |
Bit for ElementType.PARAMETER. |
static int |
RECORD_COMPONENT_TARGET |
Bit for ElementType.RECORD_COMPONENT. |
static int |
STATEMENT_TARGET |
Groovy-only target for statement-level annotations (e.g. on for/while loops). |
static int |
TYPE_PARAMETER_TARGET |
Bit for ElementType.TYPE_PARAMETER. |
static int |
TYPE_TARGET |
|
static int |
TYPE_USE_TARGET |
Bit for ElementType.TYPE_USE. |
| Constructor and description |
|---|
AnnotationNode(ClassNode type)Creates an annotation use of the given annotation type. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addMember(String name, Expression value)Stores a member expression the first time name has no value.
|
|
public ClassNode |
getClassNode()Returns the annotation class passed to the constructor. |
|
public Expression |
getMember(String name)Returns the expression stored for one member. |
|
public Map<String, Expression> |
getMembers()Returns the member expressions in insertion order. |
|
public String |
getText() |
|
public boolean |
hasClassRetention()Flag corresponding to RetentionPolicy.CLASS.
|
|
public boolean |
hasRuntimeRetention()Flag corresponding to RetentionPolicy.RUNTIME. |
|
public boolean |
hasSourceRetention()Flag corresponding to RetentionPolicy.SOURCE. |
|
public boolean |
isBuiltIn()Always reports that the annotation is not built in. |
|
public boolean |
isTargetAllowed(int target)Reports whether every bit set in target is permitted for this annotation type. |
|
public void |
setAllowedTargets(int ignored)Does nothing. |
|
public void |
setClassRetention(boolean ignored)Does nothing. |
|
public void |
setMember(String name, Expression value)Stores a member expression, replacing a value already recorded for the same name. |
|
public void |
setRuntimeRetention(boolean ignored)Does nothing. |
|
public void |
setSourceRetention(boolean ignored)Does nothing. |
|
public static String |
targetToName(int target)Names one target bit for error messages. |
|
public String |
toString() |
| Methods inherited from class | Name |
|---|---|
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Bit for ElementType.ANNOTATION_TYPE. The low bit is clear, so targetToName(int) reports it as ANNOTATION rather than TYPE.
Bit for ElementType.CONSTRUCTOR. Combined with the other target bits by isTargetAllowed(int).
Bit for ElementType.FIELD. Combined with the other target bits by isTargetAllowed(int).
Groovy-only target for annotations on import statements.
Bit for ElementType.LOCAL_VARIABLE. Combined with the other target bits by isTargetAllowed(int).
Bit for ElementType.METHOD. Combined with the other target bits by isTargetAllowed(int).
Bit for ElementType.PACKAGE. Combined with the other target bits by isTargetAllowed(int).
Bit for ElementType.PARAMETER. Combined with the other target bits by isTargetAllowed(int).
Bit for ElementType.RECORD_COMPONENT. Included in the mask used when the annotation type has no Target.
Groovy-only target for statement-level annotations (e.g. on for/while loops).
Bit for ElementType.TYPE_PARAMETER. Not part of the mask used when the annotation type has no Target.
Bit for ElementType.TYPE_USE. Not part of the mask used when the annotation type has no Target.
Creates an annotation use of the given annotation type.
No member values are stored until addMember(String, Expression) or
setMember(String, Expression) is called.
Throws NullPointerException if type is null.
type - the annotation class; stored as given and not copied Stores a member expression the first time name has no value.
A missing member and a member set to null are both treated as unset.
Members are kept in insertion order.
setMember(String, Expression) overwrites a stored value instead of rejecting it.
Throws GroovyBugError if a non-null value is already stored for name.
name - the annotation member namevalue - the member expression, stored without checking it against the annotation typeReturns the annotation class passed to the constructor. This call does not resolve or redirect that class node.
Returns the expression stored for one member.
name - the member namenull when that member has not been setReturns the member expressions in insertion order. Before any member is stored the result is an immutable empty map, and later additions are not visible through it. Once a member has been stored the result is the live map.
null Flag corresponding to RetentionPolicy.CLASS.
This is the default when no Retention annotation is present.
Flag corresponding to RetentionPolicy.RUNTIME.
Flag corresponding to RetentionPolicy.SOURCE.
Always reports that the annotation is not built in. Annotation nodes no longer distinguish built-in annotations.
false Reports whether every bit set in target is permitted for this annotation type.
The annotation class must already be a primary class node or resolved. The first check decodes
Target from that class and caches the mask on the resolved class.
Only a value that is a ListExpression is decoded. A PropertyExpression in
that list contributes the bit for the ElementType it names; any other entry is skipped. If no
Target annotation has such a list, the mask is the JLS 9.6.4.1 default: declaration contexts
other than type parameters, and not type-use.
ElementType.TYPE and ElementType.MODULE both contribute TYPE_TARGET. An
ElementType constant with no mapped bit fails with GroovyBugError. A property name
that is not an ElementType constant aborts the lookup.
ExtendedTarget is then OR-ed in. ExtendedElementType.IMPORT contributes
IMPORT_TARGET and ExtendedElementType.LOOP contributes STATEMENT_TARGET;
an unknown extended element contributes nothing.
A requested combination is allowed only when all of its bits are in the mask. A target of zero is
always allowed.
Throws IllegalStateException if the annotation class is neither primary nor resolved.
target - bitmask of element kinds, usually one *_TARGET constanttrue when every bit set in target is allowedDoes nothing. Allowed targets are read from the annotation type's Target by isTargetAllowed(int).
ignored - unused bitmask of targetsDoes nothing. Class retention is derived from the annotation type's Retention by hasClassRetention().
ignored - unused retention flagStores a member expression, replacing a value already recorded for the same name. The map preserves insertion order, so replacing a name does not move it.
name - the annotation member namevalue - the member expression to storeDoes nothing. Runtime retention is derived from the annotation type's Retention by hasRuntimeRetention().
ignored - unused retention flagDoes nothing. Source retention is derived from the annotation type's Retention by hasSourceRetention().
ignored - unused retention flag Names one target bit for error messages.
Any value with the low bit set is TYPE, which is how TYPE_TARGET is told apart from
ANNOTATION_TARGET.
Every other value must equal exactly one *_TARGET constant; a mix of bits is not split apart.
target - a target bitmask, normally one constantunknown target when nothing matchesCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.