Skip to content

Commit 71b6eb9

Browse files
committed
GROOVY-11838: TYPE_USE and TYPE_PARAMETER not in default targets
1 parent ff4da8d commit 71b6eb9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/main/java/org/codehaus/groovy/ast/AnnotationNode.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ public class AnnotationNode extends ASTNode {
4747
public static final int RECORD_COMPONENT_TARGET = 1 << 10;
4848
public static final int TYPE_TARGET = ANNOTATION_TARGET | 1; // GROOVY-7151
4949

50-
private static final int ALL_TARGETS = TYPE_TARGET | CONSTRUCTOR_TARGET | METHOD_TARGET
51-
| FIELD_TARGET | PARAMETER_TARGET | LOCAL_VARIABLE_TARGET | ANNOTATION_TARGET
52-
| PACKAGE_TARGET | TYPE_PARAMETER_TARGET | TYPE_USE_TARGET | RECORD_COMPONENT_TARGET;
53-
5450
private final ClassNode classNode;
5551
private Map<String, Expression> members;
56-
private int allowedTargets = ALL_TARGETS;
52+
private int allowedTargets = 0x4FF; // GROOVY-11838: JLS 9.6.4.1
5753
private boolean runtimeRetention = false, sourceRetention = false, /*explicit*/ classRetention = false;
5854

5955
public AnnotationNode(final ClassNode type) {

src/test/groovy/org/codehaus/groovy/ast/AnnotationNodeTest.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ import static org.junit.jupiter.api.Assertions.*
2525

2626
final class AnnotationNodeTest {
2727

28+
// GROOVY-11838
29+
@Test
30+
void testIsTargetAllowed() {
31+
def node = new AnnotationNode(ClassHelper.OVERRIDE_TYPE)
32+
33+
assertTrue(node.isTargetAllowed(AnnotationNode.TYPE_TARGET))
34+
assertTrue(node.isTargetAllowed(AnnotationNode.FIELD_TARGET))
35+
assertTrue(node.isTargetAllowed(AnnotationNode.METHOD_TARGET))
36+
37+
assertFalse(node.isTargetAllowed(AnnotationNode.TYPE_USE_TARGET))
38+
assertFalse(node.isTargetAllowed(AnnotationNode.TYPE_PARAMETER_TARGET))
39+
}
40+
2841
@Test
2942
void testGetText() {
3043
def node = new AnnotationNode(ClassHelper.OVERRIDE_TYPE)

0 commit comments

Comments
 (0)