MCPcopy Create free account
hub / github.com/apache/groovy / AnnotationNode

Class AnnotationNode

src/main/java/org/codehaus/groovy/ast/AnnotationNode.java:44–310  ·  view source on GitHub ↗

Represents an annotation which can be attached to interfaces, classes, methods, fields, parameters, and other places.

Source from the content-addressed store, hash-verified

42 * Represents an annotation which can be attached to interfaces, classes, methods, fields, parameters, and other places.
43 */
44public class AnnotationNode extends ASTNode {
45
46 public static final int CONSTRUCTOR_TARGET = 1 << 1;
47 public static final int METHOD_TARGET = 1 << 2;
48 public static final int FIELD_TARGET = 1 << 3;
49 public static final int PARAMETER_TARGET = 1 << 4;
50 public static final int LOCAL_VARIABLE_TARGET = 1 << 5;
51 public static final int ANNOTATION_TARGET = 1 << 6;
52 public static final int PACKAGE_TARGET = 1 << 7;
53 public static final int TYPE_PARAMETER_TARGET = 1 << 8;
54 public static final int TYPE_USE_TARGET = 1 << 9;
55 public static final int RECORD_COMPONENT_TARGET = 1 << 10;
56 /** Groovy-only target for statement-level annotations (e.g. on {@code for}/{@code while} loops). */
57 public static final int STATEMENT_TARGET = 1 << 11;
58 /** Groovy-only target for annotations on import statements. */
59 public static final int IMPORT_TARGET = 1 << 12;
60 public static final int TYPE_TARGET = ANNOTATION_TARGET | 1; // GROOVY-7151
61
62 private final ClassNode classNode;
63 private Map<String, Expression> members;
64
65 public AnnotationNode(final ClassNode type) {
66 classNode = requireNonNull(type);
67 }
68
69 public void addMember(final String name, final Expression value) {
70 ensureMembers();
71 Expression oldValue = members.get(name);
72 if (oldValue == null) {
73 members.put(name, value);
74 } else {
75 throw new GroovyBugError(String.format("Annotation member %s has already been added", name));
76 }
77 }
78
79 public void setMember(final String name, final Expression value) {
80 ensureMembers();
81 members.put(name, value);
82 }
83
84 private void ensureMembers() {
85 if (members == null) {
86 members = new LinkedHashMap<>();
87 }
88 }
89
90 @Deprecated(since = "6.0.0")
91 public void setAllowedTargets(final int ignored) {
92 }
93
94 @Deprecated(since = "6.0.0")
95 public void setClassRetention(final boolean ignored) {
96 }
97
98 @Deprecated(since = "6.0.0")
99 public void setSourceRetention(final boolean ignored) {
100 }
101

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected