Skip to content

Commit 092b3f7

Browse files
committed
Update the Groovy plugin to 4.0.12
for #1477
1 parent 2dcc6a5 commit 092b3f7

File tree

42 files changed

+471
-314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+471
-314
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package org.eclipse.jdt.core.groovy.tests.search;
1717

18+
import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isAtLeastGroovy;
19+
1820
import org.junit.Test;
1921

2022
public final class Groovy25InferencingTests extends InferencingTestSuite {
@@ -98,7 +100,7 @@ public void testCompileStaticVariableAssignment7() {
98100
" Map map = [:]\n" +
99101
"}\n";
100102

101-
assertType(contents, "map", "java.util.LinkedHashMap");
103+
assertType(contents, "map", "java.util.LinkedHashMap" + (!isAtLeastGroovy(40) ? "" : "<java.lang.Object,java.lang.Object>"));
102104
}
103105

104106
@Test

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

Lines changed: 94 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -746,74 +746,140 @@ public void testStaticImport1() {
746746
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
747747

748748
String contents = "import static p.Other.FOO";
749+
assertKnown(contents, "p.Other", "p.Other", "p.Other");
749750
assertKnown(contents, "FOO", "p.Other", "java.lang.Integer");
751+
assertKnown(contents + "\nFOO", "FOO", "p.Other", "java.lang.Integer");
750752
}
751753

752754
@Test
753755
public void testStaticImport2() {
754756
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
755757

756758
String contents = "import static p.Other.FOO as BAR";
759+
assertKnown(contents, "p.Other", "p.Other", "p.Other");
757760
assertKnown(contents, "FOO", "p.Other", "java.lang.Integer");
761+
assertKnown(contents + "\nBAR", "BAR", "p.Other", "java.lang.Integer");
762+
assertUnknown(contents + "\nFOO", "FOO");
758763
}
759764

760765
@Test
761766
public void testStaticImport3() {
762767
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
763768

764-
String contents = "import static p.Other.FOO\nFOO";
765-
assertKnown(contents, "FOO", "p.Other", "java.lang.Integer");
769+
String contents = "import static p.Other.FO";
770+
assertUnknown(contents, "FO");
766771
}
767772

768773
@Test
769774
public void testStaticImport4() {
770775
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
771776

772-
String contents = "import static p.Other.FOO as BAR\nFOO";
773-
assertUnknown(contents, "FOO");
777+
String contents = "import static p.Other.BAR";
778+
assertKnown(contents, "BAR", "p.Other", "java.lang.Boolean");
779+
assertKnown(contents + "\nBAR", "BAR", "p.Other", "java.lang.Boolean");
774780
}
775781

776782
@Test
777783
public void testStaticImport5() {
778784
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
779785

780-
String contents = "import static p.Other.FO";
781-
assertUnknown(contents, "FO");
786+
String contents = "import static p.Other.*\nFOO";
787+
assertKnown(contents, "p.Other", "p.Other", "p.Other");
788+
assertKnown(contents, "FOO", "p.Other", "java.lang.Integer");
782789
}
783790

784791
@Test
785792
public void testStaticImport6() {
786-
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
793+
createUnit("p", "Other", "package p\nclass Other { public static int FOO}");
794+
795+
String contents =
796+
"import static p.Other.FOO as bar\n" +
797+
"class C {\n" +
798+
" def FOO\n" +
799+
" void m() {\n" +
800+
" def x = bar;\n" +
801+
" bar = x\n" +
802+
" }\n" +
803+
"\n}";
787804

788-
String contents = "import static p.Other.BAR\nBAR";
789-
int offset = contents.indexOf("BAR");
790-
assertType(contents, offset, offset + "BAR".length(), "java.lang.Boolean");
791-
offset = contents.lastIndexOf("BAR");
792-
assertType(contents, offset, offset + "BAR".length(), "java.lang.Boolean");
805+
int offset = contents.indexOf("bar;");
806+
assertType(contents, offset, offset + 3, "java.lang.Integer");
807+
assertDeclaration(contents, offset, offset + 3, "p.Other", "FOO", DeclarationKind.FIELD);
808+
809+
/**/offset = contents.lastIndexOf("bar");
810+
assertType(contents, offset, offset + 3, "java.lang.Integer");
811+
assertDeclaration(contents, offset, offset + 3, "p.Other", "FOO", DeclarationKind.FIELD);
793812
}
794813

795814
@Test
796815
public void testStaticImport7() {
797-
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
816+
createUnit("p", "Other", "package p\nclass Other { public static int FOO}");
798817

799-
String contents = "import static p.Other.FOO\nFOO";
800-
assertKnown(contents, "p.Other", "p.Other", "p.Other");
818+
String contents =
819+
"import static p.Other.FOO as bar\n" +
820+
"@groovy.transform.CompileStatic\n" +
821+
"class C {\n" +
822+
" def FOO\n" +
823+
" void m() {\n" +
824+
" def x = bar;\n" +
825+
" bar = x\n" +
826+
" }\n" +
827+
"\n}";
828+
829+
int offset = contents.indexOf("bar;");
830+
assertType(contents, offset, offset + 3, "java.lang.Integer");
831+
assertDeclaration(contents, offset, offset + 3, "p.Other", "FOO", DeclarationKind.FIELD);
832+
833+
/**/offset = contents.lastIndexOf("bar");
834+
assertType(contents, offset, offset + 3, "java.lang.Integer");
835+
assertDeclaration(contents, offset, offset + 3, "p.Other", "FOO", DeclarationKind.FIELD);
801836
}
802837

803838
@Test
804839
public void testStaticImport8() {
805-
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
840+
createUnit("p", "Other", "package p\nclass Other { static int FOO}");
806841

807-
String contents = "import static p.Other.FOO as BAR\nFOO";
808-
assertKnown(contents, "p.Other", "p.Other", "p.Other");
842+
String contents =
843+
"import static p.Other.FOO as bar\n" +
844+
"class C {\n" +
845+
" def FOO\n" +
846+
" void m() {\n" +
847+
" def x = bar;\n" +
848+
" bar = x\n" +
849+
" }\n" +
850+
"\n}";
851+
852+
int offset = contents.indexOf("bar;");
853+
assertType(contents, offset, offset + 3, "java.lang.Integer");
854+
assertDeclaration(contents, offset, offset + 3, "p.Other", "getFOO", DeclarationKind.METHOD);
855+
856+
/**/offset = contents.lastIndexOf("bar");
857+
assertType(contents, offset, offset + 3, "java.lang.Void");
858+
assertDeclaration(contents, offset, offset + 3, "p.Other", "setFOO", DeclarationKind.METHOD);
809859
}
810860

811861
@Test
812862
public void testStaticImport9() {
813-
createUnit("p", "Other", "package p\nclass Other { static int FOO\n static boolean BAR() {}}");
863+
createUnit("p", "Other", "package p\nclass Other { static int FOO}");
814864

815-
String contents = "import static p.Other.*\nFOO";
816-
assertKnown(contents, "p.Other", "p.Other", "p.Other");
865+
String contents =
866+
"import static p.Other.FOO as bar\n" +
867+
"@groovy.transform.CompileStatic\n" +
868+
"class C {\n" +
869+
" def FOO\n" +
870+
" void m() {\n" +
871+
" def x = bar;\n" +
872+
" bar = x\n" +
873+
" }\n" +
874+
"\n}";
875+
876+
int offset = contents.indexOf("bar;");
877+
assertType(contents, offset, offset + 3, "java.lang.Integer");
878+
assertDeclaration(contents, offset, offset + 3, "p.Other", "getFOO", DeclarationKind.METHOD);
879+
880+
/**/offset = contents.lastIndexOf("bar");
881+
assertType(contents, offset, offset + 3, "java.lang.Void");
882+
assertDeclaration(contents, offset, offset + 3, "p.Other", "setFOO", DeclarationKind.METHOD);
817883
}
818884

819885
@Test // https://github.com/groovy/groovy-eclipse/issues/539
@@ -861,9 +927,9 @@ public void testStaticImport13() {
861927
"\n";
862928
int offset = contents.indexOf("isSomething(s)");
863929
assertDeclaringType(contents, offset, offset + "isSomething".length(), "p.A");
864-
offset = contents.indexOf("isSomething(i)");
930+
/**/offset = contents.indexOf("isSomething(i)");
865931
assertDeclaringType(contents, offset, offset + "isSomething".length(), "p.B");
866-
offset = contents.indexOf("isSomething(a)");
932+
/**/offset = contents.indexOf("isSomething(a)");
867933
assertDeclaringType(contents, offset, offset + "isSomething".length(), "C");
868934
}
869935

@@ -885,9 +951,9 @@ public void testStaticImport14() {
885951
"\n";
886952
int offset = contents.indexOf("isSomething(s)");
887953
assertDeclaringType(contents, offset, offset + "isSomething".length(), "p.A");
888-
offset = contents.indexOf("isSomething(i)");
954+
/**/offset = contents.indexOf("isSomething(i)");
889955
assertDeclaringType(contents, offset, offset + "isSomething".length(), "p.B");
890-
offset = contents.indexOf("isSomething(a)");
956+
/**/offset = contents.indexOf("isSomething(a)");
891957
assertDeclaringType(contents, offset, offset + "isSomething".length(), "C");
892958
}
893959

@@ -906,9 +972,9 @@ public void testStaticImport15() {
906972
"wasSomething(a)\n";
907973
int offset = contents.indexOf("wasSomething(s)");
908974
assertDeclaringType(contents, offset, offset + "wasSomething".length(), "p.A");
909-
offset = contents.indexOf("wasSomething(i)");
975+
/**/offset = contents.indexOf("wasSomething(i)");
910976
assertDeclaringType(contents, offset, offset + "wasSomething".length(), "p.B");
911-
offset = contents.indexOf("wasSomething(a)");
977+
/**/offset = contents.indexOf("wasSomething(a)");
912978
assertDeclaringType(contents, offset, offset + "wasSomething".length(), DEFAULT_UNIT_NAME);
913979
}
914980

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected String[] getDefaultClassPaths() {
134134
String[] cps = super.getDefaultClassPaths();
135135
String[] newcps = Arrays.copyOf(cps, cps.length + 2);
136136

137-
String[] groovyVersions = {"4.0.11", "3.0.17-indy"};
137+
String[] groovyVersions = {"4.0.12", "3.0.17-indy"};
138138
String[] ivyVersions = {"2.5.1", "2.5.0"};
139139
try {
140140
URL groovyJar = null;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,4 +3085,25 @@ public void testTraits10894() {
30853085
"----------\n");
30863086
}
30873087
}
3088+
3089+
@Test
3090+
public void testTraits11012() {
3091+
//@formatter:off
3092+
String[] sources = {
3093+
"Script.groovy",
3094+
"trait Bar<T> {\n" +
3095+
" T get(x,y) {\n" +
3096+
" }\n" +
3097+
"}\n" +
3098+
"class Foo<V> implements Bar<V> {\n" +
3099+
"}\n" +
3100+
"@groovy.transform.TypeChecked test(Foo<Number> foo) {\n" +
3101+
" Number x = foo.get(null, null)\n" + // Cannot assign value of type Object to variable of type Number
3102+
"}\n" +
3103+
"test(new Foo<Number>())\n",
3104+
};
3105+
//@formatter:on
3106+
3107+
runConformTest(sources);
3108+
}
30883109
}

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/GrabTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ public void testGrab() {
3535
"}\n",
3636

3737
"Test.groovy",
38-
"@Grab('joda-time:joda-time:2.11.2;transitive=false')\n" +
38+
"@Grab('joda-time:joda-time:2.12.5;transitive=false')\n" +
3939
"import org.joda.time.DateTime\n" +
4040
"void printDate() {\n" +
4141
" def now = new DateTime()\n" +
@@ -67,7 +67,7 @@ public void testGrabError() {
6767

6868
"Test.groovy",
6969
"@Grapes([\n" +
70-
" @Grab('joda-time:joda-time:2.11.2;transitive=false'),\n" +
70+
" @Grab('joda-time:joda-time:2.12.5;transitive=false'),\n" +
7171
" @Grab(group='org.aspectj', module='aspectjweaver', version='1.x')\n" +
7272
"])\n" +
7373
"class Test {\n" +

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/RecordTypeTests.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,31 @@ public void testRecordType6() {
158158
runConformTest(sources, "", "Assertion failed");
159159
}
160160

161-
@Test
161+
@Test // GROOVY-11041
162162
public void testRecordType7() {
163163
assumeTrue(isParrotParser());
164164

165+
//@formatter:off
166+
String[] sources = {
167+
"Script.groovy",
168+
"print new Simple(1,'x').n()\n",
169+
170+
"Simple.groovy",
171+
"record Simple(Number n, String s) {\n" +
172+
" Number n() {\n" +
173+
" n + 41\n" +
174+
" }\n" +
175+
"}\n",
176+
};
177+
//@formatter:on
178+
179+
runConformTest(sources, "42");
180+
}
181+
182+
@Test
183+
public void testRecordType8() {
184+
assumeTrue(isParrotParser());
185+
165186
//@formatter:off
166187
String[] sources = {
167188
"Main.java",
@@ -185,7 +206,7 @@ public void testRecordType7() {
185206
}
186207

187208
@Test
188-
public void testRecordType8() {
209+
public void testRecordType9() {
189210
assumeTrue(isParrotParser());
190211

191212
//@formatter:off
@@ -252,7 +273,7 @@ public void testRecordType8() {
252273
}
253274

254275
@Test
255-
public void testRecordType9() {
276+
public void testRecordType10() {
256277
assumeTrue(isParrotParser());
257278

258279
//@formatter:off

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8142,4 +8142,33 @@ public void testCompileStatic10933() {
81428142

81438143
runConformTest(sources, "[works]");
81448144
}
8145+
8146+
@Test
8147+
public void testCompileStatic11029() {
8148+
//@formatter:off
8149+
String[] sources = {
8150+
"Main.groovy",
8151+
"class Foo {\n" +
8152+
" Object myThing\n" +
8153+
"}\n" +
8154+
"@groovy.transform.CompileStatic\n" +
8155+
"class Bar extends Foo {\n" +
8156+
" @Override\n" +
8157+
" Object getMyThing() {\n" +
8158+
" super.myThing\n" +
8159+
" }\n" +
8160+
" @Override\n" +
8161+
" void setMyThing(Object object) {\n" +
8162+
" super.myThing = object\n" +
8163+
" }\n" +
8164+
"}\n" +
8165+
"def bar = new Bar()\n" +
8166+
"def value = 'works'\n" +
8167+
"bar.myThing = value\n" +
8168+
"print(bar.myThing);\n",
8169+
};
8170+
//@formatter:on
8171+
8172+
runConformTest(sources, "works");
8173+
}
81458174
}

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ public void testTypeChecked8136() {
19431943
"1. ERROR in Main.groovy (at line 5)\n" +
19441944
"\tMVM m = [:]\n" +
19451945
"\t ^^^\n" +
1946-
"Groovy:[Static type checking] - Cannot find matching constructor MVM(java.util.LinkedHashMap)\n" +
1946+
"Groovy:[Static type checking] - Cannot find matching constructor MVM(java.util.LinkedHashMap" + (isAtLeastGroovy(40) ? "<#K, #V>" : "") + ")\n" +
19471947
"----------\n");
19481948
}
19491949

@@ -1966,7 +1966,7 @@ public void testTypeChecked8136a() {
19661966
"1. ERROR in Main.groovy (at line 5)\n" +
19671967
"\tMVM m = [:]\n" +
19681968
"\t ^^^\n" +
1969-
"Groovy:[Static type checking] - Cannot find matching constructor MVM(java.util.LinkedHashMap)\n" +
1969+
"Groovy:[Static type checking] - Cannot find matching constructor MVM(java.util.LinkedHashMap" + (isAtLeastGroovy(40) ? "<#K, #V>" : "") + ")\n" +
19701970
"----------\n");
19711971
}
19721972

0 commit comments

Comments
 (0)