Skip to content

Commit

Permalink
GROOVY-10894
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jan 4, 2023
1 parent 285dd31 commit 5d936fa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,12 @@
package org.eclipse.jdt.groovy.core.tests.basic;

import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isAtLeastGroovy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.codehaus.groovy.ast.AnnotationNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.FieldNode;
import org.codehaus.groovy.control.CompilationUnit;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -3045,4 +3048,56 @@ public void testTraits10521() {

runConformTest(sources, "90[x]");
}

@Test
public void testTraits10894() {
//@formatter:off
String[] sources = {
"Script.groovy",
"new C()\n",

"C.groovy",
"class C implements T {\n" +
"}\n",

"T.groovy",
"trait T {\n" +
" @Validate String foo\n" +
"}\n",

"Validate.java",
"import java.lang.annotation.*;\n" +
"@Target(ElementType.TYPE_USE) \n" +
"@Retention(RetentionPolicy.RUNTIME)\n" +
"public @interface Validate { /**/ }\n" ,
};
//@formatter:on

if (isAtLeastGroovy(40)) {
runConformTest(sources);

ClassNode helper = getCUDeclFor("T.groovy").getCompilationUnit().getClassNode("T$Trait$FieldHelper");
for (FieldNode field : helper.getFields()) {
if (field.getName().endsWith("__foo")) {
java.util.List<AnnotationNode> typeTags =
field.getOriginType().getTypeAnnotations();
assertEquals(1, typeTags.size()); // no duplication
}
}
} else {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in C.groovy (at line 1)\n" +
"\tclass C implements T {\n" +
"\t^^^^^^^^^^^^^^^^^^^^^\n" +
"Groovy:Annotation @Validate is not allowed on element FIELD\n" +
"----------\n" +
"----------\n" +
"1. ERROR in T.groovy (at line 2)\n" +
"\t@Validate String foo\n" +
"\t^^^^^^^^^\n" +
"Groovy:Annotation @Validate is not allowed on element FIELD\n" +
"----------\n");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ private void processField(final FieldNode field, final MethodNode initializer, f
dummyField = new FieldNode(
dummyFieldName,
ACC_STATIC | ACC_PUBLIC | ACC_FINAL | ACC_SYNTHETIC,
field.getOriginType(),
field.getOriginType().getPlainNodeReference(),
fieldHelper,
null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ private void processField(final FieldNode field, final MethodNode initializer, f
dummyField = new FieldNode(
dummyFieldName,
ACC_PUBLIC | ACC_STATIC | ACC_FINAL | ACC_SYNTHETIC,
field.getOriginType(),
field.getOriginType().getPlainNodeReference(),
fieldHelper,
null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private void processField(final FieldNode field, final MethodNode initializer, f
dummyField = new FieldNode(
dummyFieldName,
ACC_PUBLIC | ACC_STATIC | ACC_FINAL | ACC_SYNTHETIC,
field.getOriginType(),
field.getOriginType().getPlainNodeReference(),
fieldHelper,
null
);
Expand Down

0 comments on commit 5d936fa

Please sign in to comment.