Skip to content

Commit 8965faa

Browse files
committed
GROOVY-9678
#1113
1 parent 1ae3081 commit 8965faa

File tree

6 files changed

+96
-27
lines changed

6 files changed

+96
-27
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BasicGroovyBuildTests.java

+32-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.io.File;
3030
import java.util.Arrays;
31+
import java.util.Collections;
3132
import java.util.Hashtable;
3233
import java.util.Map;
3334

@@ -2937,7 +2938,7 @@ public void testFieldInitializerFromOtherFile() throws Exception {
29372938
}
29382939

29392940
@Test // GRECLIPSE-1727
2940-
public void testTraitBasics() throws Exception {
2941+
public void testTraitBasics1() throws Exception {
29412942
IPath[] paths = createSimpleProject("Project", true);
29422943

29432944
//@formatter:off
@@ -2953,10 +2954,35 @@ public void testTraitBasics() throws Exception {
29532954
expectingNoProblems();
29542955
}
29552956

2956-
@Test // https://github.com/groovy/groovy-eclipse/issues/1267
2957+
@Test // GROOVY-9678
29572958
public void testTraitBasics2() throws Exception {
29582959
IPath[] paths = createSimpleProject("Project", true);
29592960

2961+
//@formatter:off
2962+
IPath c = env.addGroovyClass(paths[1], "C",
2963+
"class C implements T {\n" +
2964+
" static void m() {\n" +
2965+
" p = 2\n" +
2966+
" p += 1\n" +
2967+
" print p\n" +
2968+
" }\n" +
2969+
"}\n");
2970+
env.addGroovyClass(paths[1], "T",
2971+
"trait T {\n" +
2972+
" static p = 1\n" +
2973+
"}\n");
2974+
//@formatter:on
2975+
2976+
fullBuild(paths[0]);
2977+
expectingNoProblems();
2978+
assertEquals(Collections.emptySet(), ReconcilerUtils.reconcile(env.getUnit(c)));
2979+
expectingCompiledClasses("C", "T", "T$Trait$FieldHelper", "T$Trait$Helper", "T$Trait$StaticFieldHelper");
2980+
}
2981+
2982+
@Test // https://github.com/groovy/groovy-eclipse/issues/1267
2983+
public void testTraitBasics3() throws Exception {
2984+
IPath[] paths = createSimpleProject("Project", true);
2985+
29602986
//@formatter:off
29612987
env.addGroovyClass(paths[1], "p", "C",
29622988
"package p\n" +
@@ -2977,11 +3003,10 @@ public void testTraitBasics2() throws Exception {
29773003
"}\n");
29783004
//@formatter:on
29793005

2980-
incrementalBuild(paths[0]);
2981-
2982-
expectingCompiledClasses("p.C", "p.D", "p.T", "p.T$Trait$Helper");
2983-
assertTrue(ReconcilerUtils.reconcile(env.getUnit(d)).isEmpty());
3006+
fullBuild(paths[0]);
29843007
expectingNoProblems();
3008+
expectingCompiledClasses("p.C", "p.D", "p.T", "p.T$Trait$Helper");
3009+
assertEquals(Collections.emptySet(), ReconcilerUtils.reconcile(env.getUnit(d)));
29853010
}
29863011

29873012
@Test
@@ -3551,8 +3576,8 @@ public void testMultiProjectDependencies3() throws Exception {
35513576
bin.getLocation().toFile().delete(); // remove output folder
35523577
env.getProject(paths[0]).refreshLocal(1, null);
35533578

3554-
assertTrue(ReconcilerUtils.reconcile(env.getUnit(main)).isEmpty());
35553579
expectingNoProblems();
3580+
assertEquals(Collections.emptySet(), ReconcilerUtils.reconcile(env.getUnit(main)));
35563581
}
35573582

35583583
@Test

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/TraitsTests.java

+46
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,52 @@ public void testTraits9673() {
26212621
runConformTest(sources, "String");
26222622
}
26232623

2624+
@Test
2625+
public void testTraits9678() {
2626+
//@formatter:off
2627+
String[] sources = {
2628+
"C.groovy",
2629+
"class C implements T {\n" +
2630+
" static main(args) {\n" +
2631+
" p = 2\n" +
2632+
" p += 1\n" +
2633+
" print p\n" +
2634+
" }\n" +
2635+
"}\n",
2636+
2637+
"T.groovy",
2638+
"trait T {\n" +
2639+
" static p = 1\n" +
2640+
"}\n",
2641+
};
2642+
//@formatter:on
2643+
2644+
runConformTest(sources, "3");
2645+
}
2646+
2647+
@Test
2648+
public void testTraits9678a() {
2649+
//@formatter:off
2650+
String[] sources = {
2651+
"C.groovy",
2652+
"class C implements T {\n" +
2653+
" static main(args) {\n" +
2654+
" setP(2)\n" +
2655+
" setP(getP() + 1)\n" +
2656+
" print getP()\n" +
2657+
" }\n" +
2658+
"}\n",
2659+
2660+
"T.groovy",
2661+
"trait T {\n" +
2662+
" static p = 1\n" +
2663+
"}\n",
2664+
};
2665+
//@formatter:on
2666+
2667+
runConformTest(sources, "3");
2668+
}
2669+
26242670
@Test
26252671
public void testTraits9739() {
26262672
//@formatter:off

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/VariableScopeVisitor.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ private Variable findClassMember(final ClassNode node, final String name) {
193193
}
194194
}
195195

196-
for (ClassNode face : cn.getAllInterfaces()) {
197-
FieldNode fn = face.getDeclaredField(name);
196+
for (ClassNode in : cn.getAllInterfaces()) {
197+
FieldNode fn = in.getDeclaredField(name);
198198
if (fn != null) return fn;
199+
// GRECLIPSE add -- GROOVY-9678
200+
PropertyNode pn = in.getProperty(name);
201+
if (pn != null) return pn;
202+
// GRECLIPSE end
199203
}
200204
}
201205

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/VariableScopeVisitor.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,13 @@ private Variable findClassMember(final ClassNode node, final String name) {
196196
}
197197
}
198198

199-
for (ClassNode face : cn.getAllInterfaces()) {
200-
FieldNode fn = face.getDeclaredField(name);
199+
for (ClassNode in : cn.getAllInterfaces()) {
200+
FieldNode fn = in.getDeclaredField(name);
201201
if (fn != null) return fn;
202+
// GRECLIPSE add -- GROOVY-9678
203+
PropertyNode pn = in.getProperty(name);
204+
if (pn != null) return pn;
205+
// GRECLIPSE end
202206
}
203207
}
204208

base/org.codehaus.groovy40/src/org/codehaus/groovy/classgen/VariableScopeVisitor.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,13 @@ private Variable findClassMember(final ClassNode node, final String name) {
196196
}
197197
}
198198

199-
for (ClassNode face : cn.getAllInterfaces()) {
200-
FieldNode fn = face.getDeclaredField(name);
199+
for (ClassNode in : cn.getAllInterfaces()) {
200+
FieldNode fn = in.getDeclaredField(name);
201201
if (fn != null) return fn;
202+
// GRECLIPSE add -- GROOVY-9678
203+
PropertyNode pn = in.getProperty(name);
204+
if (pn != null) return pn;
205+
// GRECLIPSE end
202206
}
203207
}
204208

checkstyleConfig.xml

-14
Original file line numberDiff line numberDiff line change
@@ -861,20 +861,6 @@
861861
<property name="fileExtensions" value="groovy,java" />
862862
<property name="id" value="disabledTestCase" />
863863
</module>
864-
<!--module name="RegexpMultiline">
865-
<property name="message" value="Assertions.assertThat should be used instead of plain JUnit or Hamcrest asserts" />
866-
<property name="format" value="\b(?:org\.junit\.\s*)?Assert\s*\.\s*assert" />
867-
<property name="fileExtensions" value="java" />
868-
<property name="id" value="festAssertions" />
869-
<property name="severity" value="warning" />
870-
</module>
871-
<module name="RegexpMultiline">
872-
<property name="message" value="Keyword ''assert'' should be used instead of plain JUnit or Hamcrest asserts" />
873-
<property name="format" value="\b(?:org\.junit\.\s*)?Assert\s*\.\s*assert" />
874-
<property name="fileExtensions" value="groovy" />
875-
<property name="id" value="groovyAssertions" />
876-
<property name="severity" value="warning" />
877-
</module-->
878864

879865

880866
<!-- Copyright statement check -->

0 commit comments

Comments
 (0)