Class AnnotationNode
- All Implemented Interfaces:
NodeMetaDataHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBit forElementType.ANNOTATION_TYPE.static final intBit forElementType.CONSTRUCTOR.static final intBit forElementType.FIELD.static final intGroovy-only target for annotations on import statements.static final intBit forElementType.LOCAL_VARIABLE.static final intBit forElementType.METHOD.static final intBit forElementType.PACKAGE.static final intBit forElementType.PARAMETER.static final intBit forElementType.RECORD_COMPONENT.static final intGroovy-only target for statement-level annotations (e.g.static final intBit forElementType.TYPE_PARAMETER.static final intMask for a type or module target.static final intBit forElementType.TYPE_USE. -
Constructor Summary
ConstructorsConstructorDescriptionAnnotationNode(ClassNode type) Creates an annotation use of the given annotation type. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMember(String name, Expression value) Stores a member expression the first timenamehas no value.Returns the annotation class passed to the constructor.Returns the expression stored for one member.Returns the member expressions in insertion order.getText()Returns a human-readable text representation of this AST node.booleanFlag corresponding toRetentionPolicy.CLASS.booleanFlag corresponding toRetentionPolicy.RUNTIME.booleanFlag corresponding toRetentionPolicy.SOURCE.booleanDeprecated.since 6.0.0booleanisTargetAllowed(int target) Reports whether every bit set intargetis permitted for this annotation type.voidsetAllowedTargets(int ignored) Deprecated.since 6.0.0; targets are no longer stored on the annotation usevoidsetClassRetention(boolean ignored) Deprecated.since 6.0.0; retention is no longer stored on the annotation usevoidsetMember(String name, Expression value) Stores a member expression, replacing a value already recorded for the same name.voidsetRuntimeRetention(boolean ignored) Deprecated.since 6.0.0; retention is no longer stored on the annotation usevoidsetSourceRetention(boolean ignored) Deprecated.since 6.0.0; retention is no longer stored on the annotation usestatic StringtargetToName(int target) Names one target bit for error messages.toString()Methods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Field Details
-
CONSTRUCTOR_TARGET
public static final int CONSTRUCTOR_TARGETBit forElementType.CONSTRUCTOR. Combined with the other target bits byisTargetAllowed(int).- See Also:
-
METHOD_TARGET
public static final int METHOD_TARGETBit forElementType.METHOD. Combined with the other target bits byisTargetAllowed(int).- See Also:
-
FIELD_TARGET
public static final int FIELD_TARGETBit forElementType.FIELD. Combined with the other target bits byisTargetAllowed(int).- See Also:
-
PARAMETER_TARGET
public static final int PARAMETER_TARGETBit forElementType.PARAMETER. Combined with the other target bits byisTargetAllowed(int).- See Also:
-
LOCAL_VARIABLE_TARGET
public static final int LOCAL_VARIABLE_TARGETBit forElementType.LOCAL_VARIABLE. Combined with the other target bits byisTargetAllowed(int).- See Also:
-
ANNOTATION_TARGET
public static final int ANNOTATION_TARGETBit forElementType.ANNOTATION_TYPE. The low bit is clear, sotargetToName(int)reports it as ANNOTATION rather than TYPE.- See Also:
-
PACKAGE_TARGET
public static final int PACKAGE_TARGETBit forElementType.PACKAGE. Combined with the other target bits byisTargetAllowed(int).- See Also:
-
TYPE_PARAMETER_TARGET
public static final int TYPE_PARAMETER_TARGETBit forElementType.TYPE_PARAMETER. Not part of the mask used when the annotation type has noTarget.- See Also:
-
TYPE_USE_TARGET
public static final int TYPE_USE_TARGETBit forElementType.TYPE_USE. Not part of the mask used when the annotation type has noTarget.- See Also:
-
RECORD_COMPONENT_TARGET
public static final int RECORD_COMPONENT_TARGETBit forElementType.RECORD_COMPONENT. Included in the mask used when the annotation type has noTarget.- See Also:
-
STATEMENT_TARGET
public static final int STATEMENT_TARGETGroovy-only target for statement-level annotations (e.g. onfor/whileloops).- See Also:
-
IMPORT_TARGET
public static final int IMPORT_TARGETGroovy-only target for annotations on import statements.- See Also:
-
TYPE_TARGET
public static final int TYPE_TARGETMask for a type or module target.ElementType.TYPEandElementType.MODULEboth map here. The low bit keeps it distinct fromANNOTATION_TARGET, andtargetToName(int)reports every value with that bit set as TYPE.- See Also:
-
-
Constructor Details
-
AnnotationNode
Creates an annotation use of the given annotation type. No member values are stored untiladdMember(String, Expression)orsetMember(String, Expression)is called. ThrowsNullPointerExceptioniftypeisnull.- Parameters:
type- the annotation class; stored as given and not copied
-
-
Method Details
-
addMember
Stores a member expression the first timenamehas no value. A missing member and a member set tonullare both treated as unset. Members are kept in insertion order.setMember(String, Expression)overwrites a stored value instead of rejecting it. ThrowsGroovyBugErrorif a non-null value is already stored forname.- Parameters:
name- the annotation member namevalue- the member expression, stored without checking it against the annotation type
-
setMember
Stores 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.- Parameters:
name- the annotation member namevalue- the member expression to store
-
setAllowedTargets
Deprecated.since 6.0.0; targets are no longer stored on the annotation useDoes nothing. Allowed targets are read from the annotation type'sTargetbyisTargetAllowed(int).- Parameters:
ignored- unused bitmask of targets
-
setClassRetention
Deprecated.since 6.0.0; retention is no longer stored on the annotation useDoes nothing. Class retention is derived from the annotation type'sRetentionbyhasClassRetention().- Parameters:
ignored- unused retention flag
-
setSourceRetention
Deprecated.since 6.0.0; retention is no longer stored on the annotation useDoes nothing. Source retention is derived from the annotation type'sRetentionbyhasSourceRetention().- Parameters:
ignored- unused retention flag
-
setRuntimeRetention
Deprecated.since 6.0.0; retention is no longer stored on the annotation useDoes nothing. Runtime retention is derived from the annotation type'sRetentionbyhasRuntimeRetention().- Parameters:
ignored- unused retention flag
-
getClassNode
Returns the annotation class passed to the constructor. This call does not resolve or redirect that class node.- Returns:
- the annotation type
-
getMembers
Returns 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.- Returns:
- the member map, never
null
-
getMember
Returns the expression stored for one member.- Parameters:
name- the member name- Returns:
- the member expression, or
nullwhen that member has not been set
-
isBuiltIn
Deprecated.since 6.0.0Always reports that the annotation is not built in. Annotation nodes no longer distinguish built-in annotations.- Returns:
false
-
isTargetAllowed
public boolean isTargetAllowed(int target) Reports whether every bit set intargetis permitted for this annotation type.The annotation class must already be a primary class node or resolved. The first check decodes
Targetfrom that class and caches the mask on the resolved class. Only avaluethat is aListExpressionis decoded. APropertyExpressionin that list contributes the bit for theElementTypeit names; any other entry is skipped. If noTargetannotation 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.TYPEandElementType.MODULEboth contributeTYPE_TARGET. AnElementTypeconstant with no mapped bit fails withGroovyBugError. A property name that is not anElementTypeconstant aborts the lookup.ExtendedTargetis then OR-ed in.ExtendedElementType.IMPORTcontributesIMPORT_TARGETandExtendedElementType.LOOPcontributesSTATEMENT_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. ThrowsIllegalStateExceptionif the annotation class is neither primary nor resolved.- Parameters:
target- bitmask of element kinds, usually one*_TARGETconstant- Returns:
truewhen every bit set intargetis allowed
-
hasRuntimeRetention
public boolean hasRuntimeRetention()Flag corresponding toRetentionPolicy.RUNTIME.- Returns:
- true if the annotation should be visible at runtime; false otherwise
-
hasSourceRetention
public boolean hasSourceRetention()Flag corresponding toRetentionPolicy.SOURCE.- Returns:
- true if the annotation is only allowed in sources; false otherwise
-
hasClassRetention
public boolean hasClassRetention()Flag corresponding toRetentionPolicy.CLASS. This is the default when noRetentionannotation is present.- Returns:
- true if the annotation is written in the bytecode but not visible at runtime; false otherwise
-
toString
-
getText
Description copied from class:ASTNodeReturns a human-readable text representation of this AST node. Used for debugging and error messages. Default implementation returns a message indicating the representation is not yet implemented for this node type. -
targetToName
Names one target bit for error messages. Any value with the low bit set isTYPE, which is howTYPE_TARGETis told apart fromANNOTATION_TARGET. Every other value must equal exactly one*_TARGETconstant; a mix of bits is not split apart.- Parameters:
target- a target bitmask, normally one constant- Returns:
- the element-kind name, or
unknown targetwhen nothing matches
-