Skip to content

Commit

Permalink
Update the Groovy plugin to 5.0.0-alpha-3
Browse files Browse the repository at this point in the history
for #1370
  • Loading branch information
eric-milles committed Nov 27, 2023
1 parent d4dc9b3 commit 3bdcf30
Show file tree
Hide file tree
Showing 37 changed files with 1,543 additions and 592 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private static void assertDeclaration(IMember decl, BodyDeclaration body, int me
int bodyEnd = body.getStartPosition() + body.getLength();
if (bodyEnd > 0 && decl instanceof IMethod && (decl.getNameRange().getLength() == 0 ||
(Flags.isAbstract(decl.getFlags()) && !Flags.isAnnotation(decl.getDeclaringType().getFlags())))) {
bodyEnd += 1; // construcotrs and methods with a body have been set back by 1 for JDT compatibility
bodyEnd += 1; // constructors and methods with a body have been set back by 1 for JDT compatibility
} else if (body instanceof FieldDeclaration && source.charAt(source.indexOf(endTag) - 1) != ';') {
end -= endTag.length();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,35 +315,20 @@ public void testDGM24() {
public void testDGM25() {
//@formatter:off
String contents =
"[key:1].inject(1.0) { seed, entry -> null }";
//@formatter:on
assertExprType(contents, "seed", "java.math.BigDecimal");
}

@Test
public void testDGM26() {
//@formatter:off
String contents =
"[key:1].inject(1.0) { seed, entry -> entry.key.toUpperCase() + entry.value.intValue() }";
"[key:1].inject(1.0) { acc, entry -> null }";
//@formatter:on
assertExprType(contents, "acc", isAtLeastGroovy(50) ? "T" : "java.math.BigDecimal");
assertExprType(contents, "entry", "java.util.Map$Entry<java.lang.String,java.lang.Integer>");
}

@Test
public void testDGM26a() {
public void testDGM26() {
//@formatter:off
String contents =
"[key:1].inject(1.0) { seed, key, value -> key.toUpperCase() + value.intValue() }";
"[key:1].inject('prefix') { acc, key, value -> acc + key.toUpperCase() + value.intValue() }";
//@formatter:on
assertExprType(contents, "acc", isAtLeastGroovy(50) ? "T" : "java.lang.String");
assertExprType(contents, "key", "java.lang.String");
}

@Test
public void testDGM26b() {
//@formatter:off
String contents =
"[key:1].inject(1.0) { seed, key, value -> key.toUpperCase() + value.intValue() }";
//@formatter:on
assertExprType(contents, "value", "java.lang.Integer");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public void testTargetVersion() {
var x19x = isAtLeastGroovy(40) ? "19" : "17";
var x20x = isAtLeastGroovy(40) ? "20" : "17";
var x21x = isAtLeastGroovy(40) ? "21" : "17";
var x22x = isAtLeastGroovy(40) ? "22" : "17";

String[] inputs = {"1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "5", "6", "7", "8", "9", "9.0", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22"};
String[] expect = {"1.4", "1.4", "1.5", "1.6", "1.7", "1.8", "9", "1.5", "1.6", "1.7", "1.8", "9", "9", "10", "11", "12", "13", "14", "15", "16", "17", x18x, x19x, x20x, x21x, x21x};
String[] inputs = {"1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "5", "6", "7", "8", "9", "9.0", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"};
String[] expect = {"1.4", "1.4", "1.5", "1.6", "1.7", "1.8", "9", "1.5", "1.6", "1.7", "1.8", "9", "9", "10", "11", "12", "13", "14", "15", "16", "17", x18x, x19x, x20x, x21x, x22x, x22x};

if (isAtLeastGroovy(50)) Arrays.fill(expect, 0, 14, "11");
assertArrayEquals(expect, Arrays.stream(inputs).map(v -> { config.setTargetBytecode(v); return config.getTargetBytecode(); }).toArray(String[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4037,59 +4037,77 @@ public void testBuildingTwoGroovyFiles() {

@Test
public void testExtendingGroovyInterfaceWithJava() {
boolean interfaceDefaultMethod = isParrotParser() && isAtLeastGroovy(50);
//@formatter:off
String[] sources = {
"pkg/C.java",
"package pkg;\n" +
"public class C extends groovy.lang.GroovyObjectSupport implements I {" +
" public static void main(String[]argv) {\n" +
"p/C.java",
"package p;\n" +
"public class C implements I {" +
" public static void main(String[] args) {\n" +
" I i = new C();\n" +
" System.out.println( \"success\");" +
" System.out.println(i.foo());\n" +
" }\n" +
(!interfaceDefaultMethod ? "@Override public String foo() { return \"foobar\"; }\n" : "") +
"}\n",

"pkg/I.groovy",
"package pkg;\n" +
"interface I {}\n",
"p/I.groovy",
"package p\n" +
"interface I {\n" + (!interfaceDefaultMethod
?
" String foo()\n"
:
" default String foo() {\n" +
" 'foo' + I.this.bar()\n" +
" }\n" +
" private String bar() {\n" +
" 'bar'\n" +
" }\n") +
"}\n",
};
//@formatter:on

runConformTest(sources, "success");
runConformTest(sources, "foobar");
}

@Test
public void testExtendingJavaInterfaceWithGroovy() {
//@formatter:off
String[] sources = {
"pkg/C.groovy",
"package pkg;\n" +
"public class C implements I {" +
" public static void main(String[]argv) {\n" +
" I i = new C();\n" +
" System.out.println( \"success\");" +
"p/C.groovy",
"package p\n" +
"class C implements I {" +
" static main(args) {\n" +
" I i = new C()\n" +
" print i.foo()\n" +
" }\n" +
"}\n",

"pkg/I.java",
"package pkg;\n" +
"interface I {}\n",
"p/I.java",
"package p;\n" +
"interface I {\n" +
" default String foo() {\n" +
" return \"foo\" + bar();\n" +
" }\n" +
" private String bar() {\n" +
" return \"bar\";\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "success");
runConformTest(sources, "foobar");
}

// WMTM: the fix for the previous code that tracks why classes are generated
@Test
public void testExtendingJavaWithGroovyAndThenJavaAndThenGroovy() {
//@formatter:off
String[] sources = {
"p/D.groovy",
"package p;\n" +
"package p\n" +
"class D extends C {\n" +
" public static void main(String[] argv) {\n" +
" new C();\n" +
" print \"success\"\n" +
" static main(args) {\n" +
" new C()\n" +
" print 'success'\n" +
" }\n" +
"}\n",

Expand All @@ -4098,8 +4116,8 @@ public void testExtendingJavaWithGroovyAndThenJavaAndThenGroovy() {
"public class C extends B {}\n",

"p/B.groovy",
"package p;\n" +
"public class B extends A {}\n",
"package p\n" +
"class B extends A {}\n",

"p/A.java",
"package p;\n" +
Expand Down Expand Up @@ -4385,61 +4403,46 @@ public void testImplementingInterface11() {
"B.groovy",
"interface B extends A {\n" +
" default String m() {\n" +
" 'G'\n" +
" }\n" +
" static String sm() {\n" +
" 'S'\n" +
" 'B'\n" +
" }\n" +
"}\n",

"C.groovy",
"class C implements B {\n" +
" @Override String m() {\n" +
" 'C' + B.super.m() + sm()\n" +
" 'C' + " + (isAtLeastGroovy(50) ? "" : "B.") + "super.m()\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "CGS");
runConformTest(sources, "CB");
}

// WMTW: Groovy compilation unit scope adds the extra default import for java.util so List can be seen
@Test
public void testImplementingInterface_JavaExtendingGroovyAndImplementingMethod() {
//@formatter:off
String[] sources = {
"p/C.java",
"package p;\n" +
"import java.util.List;\n" +
"public class C extends groovy.lang.GroovyObjectSupport implements I {\n" +
"public class C implements I {\n" +
" public String m() { return \"\";}\n" +
" public static void main(String[] argv) {\n" +
" System.out.println( \"success\");\n" +
" }\n" +
"}\n",

"p/I.groovy",
"package p;\n" +
"public interface I {\n" +
" List m();\n" +
" List<?> m();\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in p\\C.java (at line 4)\n" +
"1. ERROR in p\\C.java (at line 3)\n" +
"\tpublic String m() { return \"\";}\n" +
"\t ^^^^^^\n" +
"The return type is incompatible with I.m()\n" +
"----------\n" +
// this verifies the position report for the error against the return value of the method
"----------\n" +
"1. WARNING in p\\I.groovy (at line 3)\n" +
"\tList m();\n" +
"\t^^^^\n" +
"List is a raw type. References to generic type List<E> should be parameterized\n" +
"----------\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ public void testCompileStatic6504() {
"@CompileStatic void test() {\n" +
" @ASTTest(phase=INSTRUCTION_SELECTION, value={\n" +
" def target = node.rightExpression.getNodeMetaData(DIRECT_METHOD_CALL_TARGET)\n" +
" assert target.declaringClass.name == 'java.util.Collection'\n" + // not java.lang.Object
" assert target.declaringClass.name == '" + (isAtLeastGroovy(50) ? "java.lang.Iterable" : "java.util.Collection") + "'\n" + // not java.lang.Object
" })\n" +
" int sum = ['a','bb','ccc'].inject(0) { int acc, String str -> acc += str.length(); acc }\n" +
" print sum" +
Expand Down Expand Up @@ -6990,7 +6990,7 @@ public void testCompileStatic9893a() {
runConformTest(sources, "String");
}

@Test(expected = AssertionError.class)
@Test
public void testCompileStatic9909() {
//@formatter:off
String[] sources = {
Expand Down Expand Up @@ -7025,7 +7025,22 @@ public void testCompileStatic9909() {
};
//@formatter:on

runConformTest(sources, "A");
if (isAtLeastGroovy(50)) {
runConformTest(sources, "A");
} else {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 5)\n" +
"\tA.super.m()\n" +
"\t^^^^^^^\n" +
"Groovy:The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 5)\n" +
"\tA.super.m()\n" +
"\t^^^^^^^\n" +
"Groovy:[Static type checking] - No such property: super for class: java.lang.Class\n" +
"----------\n");
}
}

@Test
Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy50/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<file-match-pattern match-pattern="groovy/classgen/AsmClassGenerator.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/ExtendedVerifier.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/Verifier.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/InvocationWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/WriterController.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticPropertyAccessHelper.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/control/CompilationUnit.java" include-pattern="false" />
Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy50/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2023-08-19: GROOVY_5_0_0_PRE_ALPHA
2023-08-22: GROOVY_5_0_0_ALPHA_1
2023-09-11: GROOVY_5_0_0_ALPHA_2
2023-11-27: GROOVY_5_0_0_ALPHA_3
20 changes: 10 additions & 10 deletions base/org.codehaus.groovy50/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ <h4>groovy-5.0.0.jar</h4>
<h4>groovy-test-5.0.0.jar</h4>

<ul>
<li>Obtained from: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/distribution/apache-groovy-binary-5.0.0-alpha-2.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/distribution/apache-groovy-binary-5.0.0-alpha-2.zip</a></li>
<li>Sources available at: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/sources/apache-groovy-src-5.0.0-alpha-2.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/sources/apache-groovy-src-5.0.0-alpha-2.zip</a></li>
<li>Obtained from: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/distribution/apache-groovy-binary-5.0.0-alpha-3.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/distribution/apache-groovy-binary-5.0.0-alpha-3.zip</a></li>
<li>Sources available at: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/sources/apache-groovy-src-5.0.0-alpha-3.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/sources/apache-groovy-src-5.0.0-alpha-3.zip</a></li>
<li>License kind: ASL</li>
<li>License URL: <a href="https://www.apache.org/licenses/LICENSE-2.0.html">https://www.apache.org/licenses/LICENSE-2.0.html</a></li>
<li>License text: <a href="about_files/asl2-license.txt">asl2-license.txt</a></li>
Expand All @@ -45,15 +45,15 @@ <h4>ivy-2.5.2.jar</h4>
<li>License text: <a href="about_files/asl2-license.txt">asl2-license.txt</a></li>
</ul>

<h4>groovy-console-5.0.0-alpha-2.jar</h4>
<h4>groovy-groovysh-5.0.0-alpha-2.jar</h4>
<h4>groovy-swing-5.0.0-alpha-2.jar</h4>
<h4>groovy-templates-5.0.0-alpha-2.jar</h4>
<h4>groovy-xml-5.0.0-alpha-2.jar</h4>
<h4>javaparser-core-3.25.5.jar</h4>
<h4>groovy-console-5.0.0-alpha-3.jar</h4>
<h4>groovy-groovysh-5.0.0-alpha-3.jar</h4>
<h4>groovy-swing-5.0.0-alpha-3.jar</h4>
<h4>groovy-templates-5.0.0-alpha-3.jar</h4>
<h4>groovy-xml-5.0.0-alpha-3.jar</h4>
<h4>javaparser-core-3.25.6.jar</h4>

<ul>
<li>Obtained from: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/distribution/apache-groovy-binary-5.0.0-alpha-2.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/distribution/apache-groovy-binary-5.0.0-alpha-2.zip</a></li>
<li>Obtained from: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/distribution/apache-groovy-binary-5.0.0-alpha-3.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/distribution/apache-groovy-binary-5.0.0-alpha-3.zip</a></li>
<li>License kind: ASL</li>
<li>License URL: <a href="https://www.apache.org/licenses/LICENSE-2.0.html">https://www.apache.org/licenses/LICENSE-2.0.html</a></li>
<li>License text: <a href="about_files/asl2-license.txt">asl2-license.txt</a></li>
Expand All @@ -62,7 +62,7 @@ <h4>javaparser-core-3.25.5.jar</h4>
<h4>jline-2.14.6.jar</h4>

<ul>
<li>Obtained from: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/distribution/apache-groovy-binary-5.0.0-alpha-2.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-2/distribution/apache-groovy-binary-5.0.0-alpha-2.zip</a></li>
<li>Obtained from: <a href="https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/distribution/apache-groovy-binary-5.0.0-alpha-3.zip">https://dist.apache.org/repos/dist/release/groovy/5.0.0-alpha-3/distribution/apache-groovy-binary-5.0.0-alpha-3.zip</a></li>
<li>License kind: BSD</li>
<li>License URL: <a href="https://www.opensource.org/licenses/bsd-license.php">https://www.opensource.org/licenses/bsd-license.php</a></li>
<li>License text: <a href="about_files/jline2-license.txt">jline2-license.txt</a></li>
Expand Down
2 changes: 1 addition & 1 deletion base/org.codehaus.groovy50/build.antlr4x
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<target name="build" depends="clean">
<resolve-dependencies pathid="classpath.antlr4">
<dependency org="me.sunlan" name="antlr4" rev="4.11.1.4">
<dependency org="me.sunlan" name="antlr4" rev="4.13.1.2">
<exclude name="org.abego.treelayout.core" />
</dependency>
</resolve-dependencies>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified base/org.codehaus.groovy50/lib/groovy-5.0.0-javadoc.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy50/lib/groovy-5.0.0-sources.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy50/lib/groovy-5.0.0.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy50/lib/groovy-test-5.0.0-javadoc.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy50/lib/groovy-test-5.0.0-sources.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy50/lib/groovy-test-5.0.0.jar
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion base/org.codehaus.groovy50/src/GroovyParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ switchExpressionLabel
;

expression
// must come before postfixExpression to resovle the ambiguities between casting and call on parentheses expression, e.g. (int)(1 / 2)
// must come before postfixExpression to resolve the ambiguities between casting and call on parentheses expression, e.g. (int)(1 / 2)
: castParExpression castOperandExpression #castExprAlt

// qualified names, array expressions, method invocation, post inc/dec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,21 @@ public static Expression transformInlineConstants(final Expression exp) {
if (pe.getObjectExpression() instanceof ClassExpression) {
ClassNode clazz = pe.getObjectExpression().getType();
FieldNode field = ClassNodeUtils.getField(clazz, pe.getPropertyAsString());
if (field != null && !field.isEnum() && field.isFinal() && field.isStatic() && field.hasInitialExpression()) {
Expression value = transformInlineConstants(field.getInitialValueExpression()); // GROOVY-10750
if (field != null && !field.isEnum() && field.isFinal() && field.isStatic()) {
Expression value = transformInlineConstants(field.getInitialValueExpression(), field.getType()); // GROOVY-10750, GROOVY-10068
if (value instanceof ConstantExpression) {
value = new ConstantExpression(((ConstantExpression) value).getValue());
// GROOVY-10068, et al.: retain field's type
if (!value.getType().equals(field.getType())
&& ClassHelper.isNumberType(field.getType()))
value.setType(field.getType());
// TODO: Boolean, Character, String
return configure(exp, (ConstantExpression) value);
return configure(exp, new ConstantExpression(((ConstantExpression) value).getValue()));
}
}
}
} else if (exp instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) exp;
if (ve.getAccessedVariable() instanceof FieldNode) {
FieldNode field = (FieldNode) ve.getAccessedVariable();
if (!field.isEnum() && field.isFinal() && field.isStatic()) {
Expression value = transformInlineConstants(field.getInitialValueExpression(), field.getType()); // GROOVY-11207, GROOVY-10068
if (value instanceof ConstantExpression) {
return configure(exp, new ConstantExpression(((ConstantExpression) value).getValue()));
}
}
}
Expand Down
Loading

0 comments on commit 3bdcf30

Please sign in to comment.