From 844e64a723d15d8a30f2c45a8f09e641cee3a28c Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 4 Apr 2024 18:04:04 +0200 Subject: [PATCH 01/26] Java 21 in GitHub Actions --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 68dcac51873..f3a44d021aa 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: - name: 'Set up Java' uses: actions/setup-java@v4 with: - java-version: 17 + java-version: 21 distribution: 'temurin' - name: 'Cache Maven packages' @@ -72,7 +72,7 @@ jobs: - name: 'Set up Java' uses: actions/setup-java@v4 with: - java-version: 17 + java-version: 21 distribution: 'temurin' - name: 'Cache Maven packages' From 47bb3542a2741cd510f56e55fc44a1a14275cb23 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 4 Apr 2024 18:12:11 +0200 Subject: [PATCH 02/26] Added Java 21 to toolchains.xml --- releng/toolchains.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/releng/toolchains.xml b/releng/toolchains.xml index b12a3999dc8..304a249d4be 100644 --- a/releng/toolchains.xml +++ b/releng/toolchains.xml @@ -22,4 +22,14 @@ ${env.JAVA_HOME_17_X64} + + jdk + + JavaSE-21 + 21 + + + ${env.JAVA_HOME_21_X64} + + From 80273b73cf0f4e2f158767786b8fec0510a0b632 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 4 Apr 2024 19:51:21 +0200 Subject: [PATCH 03/26] strict-jdk-21 profile --- .github/workflows/maven.yml | 4 ++-- pom.xml | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f3a44d021aa..bb7c3ee57e4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,7 +46,7 @@ jobs: - name: Build and test uses: coactions/setup-xvfb@v1.0.1 with: - run: ./mvnw clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.full.releng + run: ./mvnw --toolchains releng/toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.full.releng - name: Archive Test Results uses: actions/upload-artifact@v4 @@ -86,7 +86,7 @@ jobs: run: echo "MAVEN_WRAPPER_HOME=$(./mvnw --version | grep "Maven home:" | cut -c 13-)" >> "$GITHUB_ENV" - name: Build Maven artifacts - run: ./mvnw clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.maven.releng + run: ./mvnw --toolchains releng/toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.maven.releng - name: Archive Test Results uses: actions/upload-artifact@v4 diff --git a/pom.xml b/pom.xml index 1809a8af788..6f96234e04f 100644 --- a/pom.xml +++ b/pom.xml @@ -426,7 +426,6 @@ org.apache.maven.plugins maven-toolchains-plugin - 3.1.0 @@ -446,6 +445,34 @@ + + strict-jdk-21 + + [21,) + + + + + org.apache.maven.plugins + maven-toolchains-plugin + + + + toolchain + + + + + + + 21 + + + + + + + @@ -471,6 +498,11 @@ + + org.apache.maven.plugins + maven-toolchains-plugin + 3.1.0 + org.apache.maven.plugins maven-compiler-plugin From b7d1e6fdde88a14a97f12d4f05822e0d3edc7fe0 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Fri, 5 Apr 2024 08:25:13 +0200 Subject: [PATCH 04/26] maven.compiler.release 21 in strict-jdk-21 profile --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index 6f96234e04f..fee1c08921d 100644 --- a/pom.xml +++ b/pom.xml @@ -450,6 +450,15 @@ [21,) + + + 21 + From f8f495745b3bc43c8e0b405e5f4ed504edb69bf0 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sat, 6 Apr 2024 18:48:38 +0200 Subject: [PATCH 05/26] ContentAssistTest not dependent on Java API --- .../xbase/web/test/ContentAssistTest.java | 385 ++++++++---------- 1 file changed, 178 insertions(+), 207 deletions(-) diff --git a/org.eclipse.xtext.xbase.web/src/test/java/org/eclipse/xtext/xbase/web/test/ContentAssistTest.java b/org.eclipse.xtext.xbase.web/src/test/java/org/eclipse/xtext/xbase/web/test/ContentAssistTest.java index 44edb0f0e89..5b409a81c49 100644 --- a/org.eclipse.xtext.xbase.web/src/test/java/org/eclipse/xtext/xbase/web/test/ContentAssistTest.java +++ b/org.eclipse.xtext.xbase.web/src/test/java/org/eclipse/xtext/xbase/web/test/ContentAssistTest.java @@ -123,214 +123,185 @@ public void testPropertyType() { @Test public void testListMethods() { - String model = "entity Foo { op bar(): void { #['blub'].add| } }"; + String model = "entity Bar {\n" + + " op nop(String s) : void { }\n" + + " op add(String s) : boolean { false }\n" + + " op addAll(Iterable strings) : boolean { false }\n" + + " op addFirst(String s) : boolean { false }\n" + + "}\n" + + "entity Foo { op bar(): void { new Bar().add| } }"; String expectedResult = - "ContentAssistResult [\n" + - " stateId = \"-80000000\"\n" + - " entries = ArrayList (\n" + - " ContentAssistEntry [\n" + - " prefix = \"add\"\n" + - " proposal = \"add()\"\n" + - " label = \"add(E arg0) : boolean\"\n" + - " description = \"List\"\n" + - " escapePosition = 45\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList (\n" + - " [44:0]\n" + - " )\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"add\"\n" + - " proposal = \"add()\"\n" + - " label = \"add(int arg0, E arg1) : void\"\n" + - " description = \"List\"\n" + - " escapePosition = 45\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList (\n" + - " [44:0]\n" + - " )\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"add\"\n" + - " proposal = \"addAll()\"\n" + - " label = \"addAll(Collection arg0) : boolean\"\n" + - " description = \"List\"\n" + - " escapePosition = 48\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList (\n" + - " [47:0]\n" + - " )\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"add\"\n" + - " proposal = \"addAll()\"\n" + - " label = \"addAll(Iterable arg1) : boolean\"\n" + - " description = \"CollectionExtensions\"\n" + - " escapePosition = 48\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList (\n" + - " [47:0]\n" + - " )\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"add\"\n" + - " proposal = \"addAll()\"\n" + - " label = \"addAll(T... arg1) : boolean\"\n" + - " description = \"CollectionExtensions\"\n" + - " escapePosition = 48\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList (\n" + - " [47:0]\n" + - " )\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"add\"\n" + - " proposal = \"addAll()\"\n" + - " label = \"addAll(int arg0, Collection arg1) : boolean\"\n" + - " description = \"List\"\n" + - " escapePosition = 48\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList (\n" + - " [47:0]\n" + - " )\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"!=\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"!==\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"&&\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"+\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"->\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"<\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"<=\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"<=>\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"==\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"===\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"=>\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \">\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \">=\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"?:\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"||\"\n" + - " description = \"JvmOperation\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList ()\n" + - " kind = \"REFERENCE\"\n" + - " ],\n" + - " ContentAssistEntry [\n" + - " prefix = \"\"\n" + - " proposal = \"\"value\"\"\n" + - " description = \"STRING\"\n" + - " textReplacements = ArrayList ()\n" + - " editPositions = ArrayList (\n" + - " [44:5]\n" + - " )\n" + - " kind = \"TEXT\"\n" + - " ]\n" + - " )\n]"; + "ContentAssistResult [\n" + + " stateId = \"-80000000\"\n" + + " entries = ArrayList (\n" + + " ContentAssistEntry [\n" + + " prefix = \"add\"\n" + + " proposal = \"add()\"\n" + + " label = \"add(String s) : boolean\"\n" + + " description = \"Bar\"\n" + + " escapePosition = 232\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList (\n" + + " [231:0]\n" + + " )\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"add\"\n" + + " proposal = \"addAll()\"\n" + + " label = \"addAll(Iterable strings) : boolean\"\n" + + " description = \"Bar\"\n" + + " escapePosition = 235\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList (\n" + + " [234:0]\n" + + " )\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"add\"\n" + + " proposal = \"addFirst()\"\n" + + " label = \"addFirst(String s) : boolean\"\n" + + " description = \"Bar\"\n" + + " escapePosition = 237\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList (\n" + + " [236:0]\n" + + " )\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"!=\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"!==\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"&&\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"+\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"->\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"<\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"<=\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"<=>\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"==\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"===\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"=>\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \">\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \">=\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"?:\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"||\"\n" + + " description = \"JvmOperation\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList ()\n" + + " kind = \"REFERENCE\"\n" + + " ],\n" + + " ContentAssistEntry [\n" + + " prefix = \"\"\n" + + " proposal = \"\"value\"\"\n" + + " description = \"STRING\"\n" + + " textReplacements = ArrayList ()\n" + + " editPositions = ArrayList (\n" + + " [231:5]\n" + + " )\n" + + " kind = \"TEXT\"\n" + + " ]\n" + + " )\n" + + "]"; assertContentAssistResult(model, expectedResult); } From f99bc933eca7da2634c6686d2327e86c01c60a76 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sat, 6 Apr 2024 19:09:06 +0200 Subject: [PATCH 06/26] maven-plugin-plugin 3.12.0 otherwise the descriptor goals fails analyzing class files compiled with Java 21 --- org.eclipse.xtend.maven.parent/pom.xml | 2 +- org.eclipse.xtext.maven.parent/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.xtend.maven.parent/pom.xml b/org.eclipse.xtend.maven.parent/pom.xml index 346b6356d12..cf5b15eca3e 100644 --- a/org.eclipse.xtend.maven.parent/pom.xml +++ b/org.eclipse.xtend.maven.parent/pom.xml @@ -106,7 +106,7 @@ maven-plugin-plugin - 3.7.1 + 3.12.0 maven-resources-plugin diff --git a/org.eclipse.xtext.maven.parent/pom.xml b/org.eclipse.xtext.maven.parent/pom.xml index b7afdbfa3dd..4fd84d6a692 100644 --- a/org.eclipse.xtext.maven.parent/pom.xml +++ b/org.eclipse.xtext.maven.parent/pom.xml @@ -83,7 +83,7 @@ maven-plugin-plugin - 3.7.1 + 3.12.0 maven-source-plugin From a64804a14babda7275da76915e2a4ae4d83c205d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sat, 6 Apr 2024 19:53:37 +0200 Subject: [PATCH 07/26] use StubbedList not dependent on Java AbstractList API --- org.eclipse.xtext.xbase.tests/.classpath | 5 +++ .../build.properties | 1 + .../AbstractXbaseImportedNamesTest.java | 18 ++++------- ...dXbaseResourceDescriptionStrategyTest.java | 32 +++++++++++++++---- ...ectionResourceDescriptionStrategyTest.java | 21 ++++++++++-- .../testdata/testdata/stubs/StubbedList.java | 22 +++++++++++++ 6 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 org.eclipse.xtext.xbase.tests/testdata/testdata/stubs/StubbedList.java diff --git a/org.eclipse.xtext.xbase.tests/.classpath b/org.eclipse.xtext.xbase.tests/.classpath index 208e191b577..5d2e0905506 100644 --- a/org.eclipse.xtext.xbase.tests/.classpath +++ b/org.eclipse.xtext.xbase.tests/.classpath @@ -10,6 +10,11 @@ + + + + + diff --git a/org.eclipse.xtext.xbase.tests/build.properties b/org.eclipse.xtext.xbase.tests/build.properties index 261772d1e82..3f258112bdc 100644 --- a/org.eclipse.xtext.xbase.tests/build.properties +++ b/org.eclipse.xtext.xbase.tests/build.properties @@ -4,6 +4,7 @@ bin.includes = META-INF/,\ somelib/sample.jar src.includes = about.html source.. = src,\ + testdata,\ suites,\ smoke-suites,\ longrunning/src diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/AbstractXbaseImportedNamesTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/AbstractXbaseImportedNamesTest.java index 57e40078c49..d2946798bf9 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/AbstractXbaseImportedNamesTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/AbstractXbaseImportedNamesTest.java @@ -30,19 +30,19 @@ public abstract class AbstractXbaseImportedNamesTest extends AbstractXbaseTestCa @Test public void testImportedNamesForConstructors() throws Exception { - XExpression expression = expression("new java.util.ArrayList"); + XExpression expression = expression("new testdata.stubs.StubbedList"); assertImportedNames(expression); } @Test public void testImportedNamesForTypesInCasts() throws Exception { - XExpression expression = expression("null as java.util.ArrayList"); + XExpression expression = expression("null as testdata.stubs.StubbedList"); assertImportedNames(expression); } @Test public void testImportedNamesForTypesInVars() throws Exception { - XExpression expression = expression("{ var java.util.ArrayList x = null }"); + XExpression expression = expression("{ var testdata.stubs.StubbedList x = null }"); assertImportedNames(expression); } @@ -64,17 +64,11 @@ protected List importedNames(Resource resource) { protected void addExpectatedImportedNames(Resource resource, List expectation) { Collections.addAll(expectation, "java.io.serializable", - "java.lang.cloneable", "java.lang.iterable", - "java.lang.java$util$arraylist", + "java.lang.testdata$stubs$stubbedlist", "java.lang.object", - "java.util.abstractcollection", - "java.util.abstractlist", - "java.util.arraylist", - "java.util.collection", - "java.util.list", - "java.util.randomaccess", - "org.eclipse.xtext.xbase.lib.java$util$arraylist"); + "testdata.stubs.stubbedlist", + "org.eclipse.xtext.xbase.lib.testdata$stubs$stubbedlist"); } } diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java index aeabe26a413..7e4bac65034 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java @@ -16,6 +16,7 @@ import org.eclipse.xtext.testing.util.ParseHelper; import org.eclipse.xtext.testing.validation.ValidationTestHelper; import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.testlanguages.ContentAssistFragmentTestLangRuntimeModule; import org.eclipse.xtext.xbase.testlanguages.contentAssistFragmentTestLang.ContentAssistFragmentTestLanguageRoot; import org.eclipse.xtext.xbase.testlanguages.tests.ContentAssistFragmentTestLangInjectorProvider; import org.junit.Assert; @@ -23,13 +24,30 @@ import com.google.inject.Inject; -@InjectWith(ContentAssistFragmentTestLangInjectorProvider.class) +@InjectWith(ExtendedXbaseResourceDescriptionStrategyTest.ContentAssistFragmentTestLangInjectorProviderCustom.class) public class ExtendedXbaseResourceDescriptionStrategyTest extends AbstractXbaseImportedNamesTest { + @Inject private ParseHelper parseHelper; @Inject private ValidationTestHelper validationHelper; - + + public static class ContentAssistFragmentTestLangInjectorProviderCustom extends ContentAssistFragmentTestLangInjectorProvider { + @Override + protected ContentAssistFragmentTestLangRuntimeModule createRuntimeModule() { + // make it work also with Maven/Tycho and OSGI + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672 + // to access the testdata.stubs.StubbedList in this bundle + return new ContentAssistFragmentTestLangRuntimeModule() { + @Override + public ClassLoader bindClassLoaderToInstance() { + return ContentAssistFragmentTestLangInjectorProviderCustom.class + .getClassLoader(); + } + }; + } + } + @Test public void testImportedNamesFromModelReferences() throws Exception { ContentAssistFragmentTestLanguageRoot model = parseHelper.parse("{} entity x extends an.Entity"); @@ -54,9 +72,9 @@ protected XExpression expression(CharSequence string, boolean resolve) throws Ex } @Override - protected void addExpectatedImportedNames(Resource resource, List expectation) { - super.addExpectatedImportedNames(resource, expectation); - expectation.add("my.test." + resource.getURI().trimFileExtension().lastSegment().toLowerCase()); - expectation.add("my.test.java$util$arraylist"); - } + protected void addExpectatedImportedNames(Resource resource, List expectation) { + super.addExpectatedImportedNames(resource, expectation); + expectation.add("my.test." + resource.getURI().trimFileExtension().lastSegment().toLowerCase()); + expectation.add("my.test.testdata$stubs$stubbedlist"); + } } diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java index 47648e92613..b613726167c 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java @@ -16,6 +16,7 @@ import org.eclipse.xtext.testing.util.ParseHelper; import org.eclipse.xtext.testing.validation.ValidationTestHelper; import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.testlanguages.XImportSectionTestLangRuntimeModule; import org.eclipse.xtext.xbase.testlanguages.tests.XImportSectionTestLangInjectorProvider; import org.eclipse.xtext.xbase.testlanguages.xImportSectionTestLang.ImportSectionTestLanguageRoot; import org.junit.Assert; @@ -23,13 +24,29 @@ import com.google.inject.Inject; -@InjectWith(XImportSectionTestLangInjectorProvider.class) +@InjectWith(XImportSectionResourceDescriptionStrategyTest.XImportSectionTestLangInjectorProviderCustom.class) public class XImportSectionResourceDescriptionStrategyTest extends AbstractXbaseImportedNamesTest { @Inject private ParseHelper parseHelper; @Inject private ValidationTestHelper validationHelper; + public static class XImportSectionTestLangInjectorProviderCustom extends XImportSectionTestLangInjectorProvider { + @Override + protected XImportSectionTestLangRuntimeModule createRuntimeModule() { + // make it work also with Maven/Tycho and OSGI + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672 + // to access the testdata.stubs.StubbedList in this bundle + return new XImportSectionTestLangRuntimeModule() { + @Override + public ClassLoader bindClassLoaderToInstance() { + return XImportSectionTestLangInjectorProviderCustom.class + .getClassLoader(); + } + }; + } + } + @Override protected XExpression expression(CharSequence string) throws Exception { return super.expression("some token import java.lang.Object " + string); @@ -70,6 +87,6 @@ protected XExpression expression(CharSequence string, boolean resolve) throws Ex protected void addExpectatedImportedNames(Resource resource, List expectation) { super.addExpectatedImportedNames(resource, expectation); expectation.add("my.test." + resource.getURI().trimFileExtension().lastSegment().toLowerCase()); - expectation.add("my.test.java$util$arraylist"); + expectation.add("my.test.testdata$stubs$stubbedlist"); } } diff --git a/org.eclipse.xtext.xbase.tests/testdata/testdata/stubs/StubbedList.java b/org.eclipse.xtext.xbase.tests/testdata/testdata/stubs/StubbedList.java new file mode 100644 index 00000000000..0d25eceef19 --- /dev/null +++ b/org.eclipse.xtext.xbase.tests/testdata/testdata/stubs/StubbedList.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2024 Lorenzo Bettini and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package testdata.stubs; + +import java.io.Serializable; + +/** + * A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see, + * e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html). + * + * @author Lorenzo Bettini - Initial contribution and API + */ +@SuppressWarnings("serial") +public abstract class StubbedList implements Iterable, Serializable { + +} From f5a59f0cb31b2a70b945724c2c04aaf9c677f536 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sat, 6 Apr 2024 21:17:58 +0200 Subject: [PATCH 08/26] don't use last as extension method because in Java 21 getLast() has been introduced, throwing NoSuchElementException instead of returning null --- .../org/eclipse/xtext/xbase/formatting2/XbaseFormatter.xtend | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/formatting2/XbaseFormatter.xtend b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/formatting2/XbaseFormatter.xtend index 4d6a315de7c..4810aba4272 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/formatting2/XbaseFormatter.xtend +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/formatting2/XbaseFormatter.xtend @@ -170,6 +170,9 @@ class XbaseFormatter extends XtypeFormatter { } def protected XClosure builder(List params) { + // don't use last (now deprecated) because in Java 21 + // getLast() has been introduced, throwing NoSuchElementException + // instead of returning null if (params.lastOrNull !== null) { val grammarElement = params.lastOrNull.grammarElement if (grammarElement == XMemberFeatureCallAccess.memberCallArgumentsXClosureParserRuleCall_1_1_4_0 || From 354642527941c4f0ade1fa18f90845597d265fd2 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 7 Apr 2024 12:16:09 +0200 Subject: [PATCH 09/26] stubbed list in AbstractTypeArgumentTest To avoid interefence with the new Java 21 method getLast --- .../typesystem/AbstractTypeArgumentTest.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractTypeArgumentTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractTypeArgumentTest.java index 0f542b11991..bead4b16c30 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractTypeArgumentTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractTypeArgumentTest.java @@ -1892,106 +1892,106 @@ public void testBug_391758() throws Exception { @Test public void testBounds_07() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List list = null list.last }", "Integer")); + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList list = null list.last }", "Integer")); } @Test public void testBounds_08() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List list = null list.last }", "? extends Integer")); + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList list = null list.last }", "? extends Integer")); } @Test public void testBounds_09() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List list = null list.last }", "? super Integer")); + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList list = null list.last }", "? super Integer")); } @Test public void testBounds_10() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List> list = null list.last }", "Iterable")); + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last }", "Iterable")); } @Test public void testBounds_11() throws Exception { done(and( - bindTypeArgumentsTo("{ var java.util.List> list = null list.last.last }", "Iterable"), + bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last.last }", "Iterable"), "Integer")); } @Test public void testBounds_12() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List> list = null list.last }", + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last }", "? extends Iterable")); } @Test public void testBounds_13() throws Exception { - done(and(bindTypeArgumentsTo("{ var java.util.List> list = null list.last.last }", + done(and(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last.last }", "? extends Iterable"), "Integer")); } @Test public void testBounds_14() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List> list = null list.last }", + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last }", "Iterable")); } @Test public void testBounds_15() throws Exception { - done(and(bindTypeArgumentsTo("{ var java.util.List> list = null list.last.last }", + done(and(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last.last }", "Iterable"), "? extends Integer")); } @Test public void testBounds_16() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List> list = null list.last }", + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last }", "? extends Iterable")); } @Test public void testBounds_17() throws Exception { done(this - .and(bindTypeArgumentsTo("{ var java.util.List> list = null list.last.last }", + .and(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last.last }", "? extends Iterable"), "? extends Integer")); } @Test public void testBounds_18() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List> list = null list.last }", + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last }", "Iterable")); } @Test public void testBounds_19() throws Exception { - done(and(bindTypeArgumentsTo("{ var java.util.List> list = null list.last.last }", + done(and(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last.last }", "Iterable"), "? super Integer")); } @Test public void testBounds_20() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List> list = null list.last }", + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last }", "? extends Iterable")); } @Test public void testBounds_21() throws Exception { done( - and(bindTypeArgumentsTo("{ var java.util.List> list = null list.last.last }", + and(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList> list = null list.last.last }", "? extends Iterable"), "? super Integer")); } @Test public void testImplicitReceiverBounds_07() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List it = null last }", "Integer")); + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList it = null last }", "Integer")); } @Test public void testImplicitReceiverBounds_08() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List it = null last }", "? extends Integer")); + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList it = null last }", "? extends Integer")); } @Test public void testImplicitReceiverBounds_09() throws Exception { - done(bindTypeArgumentsTo("{ var java.util.List it = null last }", "? super Integer")); + done(bindTypeArgumentsTo("{ var testdata.stubs.StubbedList it = null last }", "? super Integer")); } @Test From 27f2cf3fb832e879daeda6aea5ff00131e686002 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 7 Apr 2024 12:47:45 +0200 Subject: [PATCH 10/26] discard the new wait0 private method in Object or the test will fail in Java 21 --- .../typesystem/ResolvedFeaturesTest.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/ResolvedFeaturesTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/ResolvedFeaturesTest.java index 783747c153f..3845bb3fa9a 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/ResolvedFeaturesTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/ResolvedFeaturesTest.java @@ -14,6 +14,7 @@ import java.util.List; import org.eclipse.xtext.common.types.JvmDeclaredType; +import org.eclipse.xtext.common.types.JvmVisibility; import org.eclipse.xtext.xbase.XCastedExpression; import org.eclipse.xtext.xbase.XTypeLiteral; import org.eclipse.xtext.xbase.tests.AbstractXbaseTestCase; @@ -143,12 +144,20 @@ public void testUnmodifiableIterator() throws Exception { ResolvedFeatures resolvedOperations = toResolvedOperations(UnmodifiableIterator.class); List all = resolvedOperations.getAllOperations(); Assert.assertFalse(all.isEmpty()); - Assert.assertEquals(all.toString(), 2, - Iterables.size(Iterables.filter(all, (IResolvedOperation it) -> it.getDeclaration().isAbstract()))); - Assert.assertEquals(all.toString(), (1 + 6), - Iterables.size(Iterables.filter(all, (IResolvedOperation it) -> it.getDeclaration().isFinal()))); + var abstractOperations = Iterables.filter(all, + it -> it.getDeclaration().isAbstract()); + Assert.assertEquals(abstractOperations.toString(), 2, + Iterables.size(abstractOperations)); + // avoid the new wait0 private method + // or the test will break with Java 21 + // https://github.com/openjdk/jdk/commit/9583e3657e43cc1c6f2101a64534564db2a9bd84 + var finalNonFinalOperations = Iterables.filter(all, + it -> it.getDeclaration().isFinal() && + it.getDeclaration().getVisibility() != JvmVisibility.PRIVATE); + Assert.assertEquals(finalNonFinalOperations.toString(), (1 + 6), + Iterables.size(finalNonFinalOperations)); List declared = resolvedOperations.getDeclaredOperations(); - Assert.assertEquals(1, declared.size()); + Assert.assertEquals(declared.toString(), 1, declared.size()); } @Test @@ -156,10 +165,14 @@ public void testAbstractList() throws Exception { ResolvedFeatures resolvedOperations = toResolvedOperations(AbstractList.class); List all = resolvedOperations.getAllOperations(); Assert.assertFalse(all.isEmpty()); - Assert.assertEquals(all.toString(), 1 + 1, - Iterables.size(Iterables.filter(all, (IResolvedOperation it) -> it.getDeclaration().isAbstract()))); + // the new method getLast added in Java 21 will not disturb this test + // that only considers abstract declarations + var abstractOperations = Iterables.filter(all, + it -> it.getDeclaration().isAbstract()); + Assert.assertEquals(abstractOperations.toString(), 1 + 1, + Iterables.size(abstractOperations)); List declared = resolvedOperations.getDeclaredOperations(); - Assert.assertEquals(1, Iterables.size(Iterables.filter(declared, (IResolvedOperation it) -> it.getDeclaration().isAbstract()))); + Assert.assertEquals(declared.toString(), 1, Iterables.size(Iterables.filter(declared, (IResolvedOperation it) -> it.getDeclaration().isAbstract()))); } @Test From 57e8d52665c873f8aaaa388735c3ed60ce57ca5e Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 7 Apr 2024 14:10:44 +0200 Subject: [PATCH 11/26] deal with List changes in Java 21 and fixed bug in publicNativeMethod The test publicNativeMethod was indeed testing "publicStrictFpMethod": copy and paste error? --- .../access/impl/AbstractTypeProviderTest.java | 14 +++++++---- .../testdata/testdata/MyStubbedList.java | 23 +++++++++++++++++++ .../access/impl/AbstractTypeProviderTest.java | 10 ++++---- .../access/impl/AbstractTypeProviderTest.java | 9 ++++---- .../xtext/java/tests/MyStubbedList.java | 23 +++++++++++++++++++ 5 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 org.eclipse.xtext.common.types.tests/testdata/testdata/MyStubbedList.java create mode 100644 org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/MyStubbedList.java diff --git a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index 3bffd5202b9..5a2fa512d9e 100644 --- a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -476,7 +476,13 @@ public void testFindTypeByName_javaUtilList_07() { assertEquals(1, type.getSuperTypes().size()); JvmParameterizedTypeReference superType = (JvmParameterizedTypeReference) type.getSuperTypes().get(0); assertFalse(superType.getType().eIsProxy()); - assertEquals("java.util.Collection", superType.getIdentifier()); + // in Java 21 List extends SequencedCollection + // but this test relies on sources so we cannot use stubbed classes + // like in xtext.java.tests or common.types.tests + // so we remove "Sequenced" from the super type + // Lorenzo: that's the best and simplest solution I could find + assertEquals("java.util.Collection", + superType.getIdentifier().replace("Sequenced", "")); assertEquals(1, type.getTypeParameters().size()); JvmType rawType = superType.getType(); assertFalse(rawType.eIsProxy()); @@ -2016,14 +2022,14 @@ public void testMethods_publicStrictFpMethod_01() { public void publicNativeMethod() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); - JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); + JvmOperation method = getMethodFromType(type, Methods.class, "publicNativeMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); - assertTrue(method.isStrictFloatingPoint()); - assertFalse(method.isNative()); + assertFalse(method.isStrictFloatingPoint()); + assertTrue(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); diff --git a/org.eclipse.xtext.common.types.tests/testdata/testdata/MyStubbedList.java b/org.eclipse.xtext.common.types.tests/testdata/testdata/MyStubbedList.java new file mode 100644 index 00000000000..a263cc72db2 --- /dev/null +++ b/org.eclipse.xtext.common.types.tests/testdata/testdata/MyStubbedList.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2024 Lorenzo Bettini and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package testdata; + +import java.util.Collection; +import java.util.List; + +/** + * To avoid breaking our tests with new Java API (e.g., in Java 21, + * {@link List} extends SequencedCollection instead of Collection. + * + * @author Lorenzo Bettini + * + */ +public interface MyStubbedList extends Collection { + +} diff --git a/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index 45b2f6d43e3..d8c2f86a06a 100644 --- a/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -122,6 +122,8 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import testdata.MyStubbedList; + /** * @author Sebastian Zarnekow - Initial contribution and API */ @@ -471,7 +473,7 @@ public void testFindTypeByName_javaUtilList_06() { @Test public void testFindTypeByName_javaUtilList_07() { - String typeName = List.class.getName(); + String typeName = MyStubbedList.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertEquals(1, type.getSuperTypes().size()); JvmParameterizedTypeReference superType = (JvmParameterizedTypeReference) type.getSuperTypes().get(0); @@ -2038,14 +2040,14 @@ public void testMethods_publicStrictFpMethod_01() { public void publicNativeMethod() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); - JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); + JvmOperation method = getMethodFromType(type, Methods.class, "publicNativeMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); - assertTrue(method.isStrictFloatingPoint()); - assertFalse(method.isNative()); + assertFalse(method.isStrictFloatingPoint()); + assertTrue(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); diff --git a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index 8ad7a51985c..4a09cf23ea1 100644 --- a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -110,6 +110,7 @@ import org.eclipse.xtext.common.types.testSetups.TestEnum; import org.eclipse.xtext.common.types.testSetups.TypeWithInnerAnnotation; import org.eclipse.xtext.common.types.testSetups.TypeWithInnerEnum; +import org.eclipse.xtext.java.tests.MyStubbedList; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -472,7 +473,7 @@ public void testFindTypeByName_javaUtilList_06() { @Test public void testFindTypeByName_javaUtilList_07() { - String typeName = List.class.getName(); + String typeName = MyStubbedList.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertEquals(1, type.getSuperTypes().size()); JvmParameterizedTypeReference superType = (JvmParameterizedTypeReference) type.getSuperTypes().get(0); @@ -2039,14 +2040,14 @@ public void testMethods_publicStrictFpMethod_01() { public void publicNativeMethod() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); - JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); + JvmOperation method = getMethodFromType(type, Methods.class, "publicNativeMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); - assertTrue(method.isStrictFloatingPoint()); - assertFalse(method.isNative()); + assertFalse(method.isStrictFloatingPoint()); + assertTrue(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); diff --git a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/MyStubbedList.java b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/MyStubbedList.java new file mode 100644 index 00000000000..bacf083567c --- /dev/null +++ b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/MyStubbedList.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2024 Lorenzo Bettini and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.xtext.java.tests; + +import java.util.Collection; +import java.util.List; + +/** + * To avoid breaking our tests with new Java API (e.g., in Java 21, + * {@link List} extends SequencedCollection instead of Collection. + * + * @author Lorenzo Bettini + * + */ +public interface MyStubbedList extends Collection { + +} From 7d58ba6563a94fc429aa2d4eac62759db2bb003e Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 7 Apr 2024 14:35:51 +0200 Subject: [PATCH 12/26] skip strictfp tests for Java 18 and later strictfp has no effect since Java 17 https://openjdk.org/jeps/306 and it doesn't seem to be present at runtime in 17+ see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=545510#c6 for sure, it fails with Java 21 --- .../types/access/impl/AbstractTypeProviderTest.java | 11 ++++++++--- .../types/access/impl/AbstractTypeProviderTest.java | 11 ++++++++--- .../types/access/impl/AbstractTypeProviderTest.java | 9 ++++++++- .../org/eclipse/xtext/util/JavaRuntimeVersion.java | 4 ++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index 5a2fa512d9e..d7b89cf7ba1 100644 --- a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -104,6 +104,7 @@ import org.eclipse.xtext.common.types.testSetups.StaticNestedTypes; import org.eclipse.xtext.common.types.testSetups.TestAnnotation; import org.eclipse.xtext.common.types.testSetups.TestAnnotation.Annotated; +import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.common.types.testSetups.TestAnnotationWithDefaults; import org.eclipse.xtext.common.types.testSetups.TestAnnotationWithStringDefault; import org.eclipse.xtext.common.types.testSetups.TestConstants; @@ -111,6 +112,7 @@ import org.eclipse.xtext.common.types.testSetups.TypeWithInnerAnnotation; import org.eclipse.xtext.common.types.testSetups.TypeWithInnerEnum; import org.junit.Assert; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; @@ -2003,6 +2005,11 @@ public void testStrictFpType() { @Test public void testMethods_publicStrictFpMethod_01() { + // strictfp has no effect since Java 17 https://openjdk.org/jeps/306 + // and it doesn't seem to be present at runtime in 17+ + // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=545510#c6 + // for sure, it fails with Java 21 + Assume.assumeFalse("Ignored on Java 18 and later", JavaRuntimeVersion.isJava18OrLater()); String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); @@ -2011,9 +2018,7 @@ public void testMethods_publicStrictFpMethod_01() { assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); - assertTrue(method.isStrictFloatingPoint()); - assertFalse(method.isNative()); - assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); + assertTrue(method.isStrictFloatingPoint()); // it fails with Java 21 JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); } diff --git a/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index d8c2f86a06a..3c8c0e3ee7c 100644 --- a/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -104,6 +104,7 @@ import org.eclipse.xtext.common.types.testSetups.StaticNestedTypes; import org.eclipse.xtext.common.types.testSetups.TestAnnotation; import org.eclipse.xtext.common.types.testSetups.TestAnnotation.Annotated; +import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.common.types.testSetups.TestAnnotationWithDefaults; import org.eclipse.xtext.common.types.testSetups.TestAnnotationWithStringDefault; import org.eclipse.xtext.common.types.testSetups.TestConstants; @@ -111,6 +112,7 @@ import org.eclipse.xtext.common.types.testSetups.TypeWithInnerAnnotation; import org.eclipse.xtext.common.types.testSetups.TypeWithInnerEnum; import org.junit.Assert; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; @@ -2021,6 +2023,11 @@ public void testStrictFpType() { @Test public void testMethods_publicStrictFpMethod_01() { + // strictfp has no effect since Java 17 https://openjdk.org/jeps/306 + // and it doesn't seem to be present at runtime in 17+ + // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=545510#c6 + // for sure, it fails with Java 21 + Assume.assumeFalse("Ignored on Java 18 and later", JavaRuntimeVersion.isJava18OrLater()); String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); @@ -2029,9 +2036,7 @@ public void testMethods_publicStrictFpMethod_01() { assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); - assertTrue(method.isStrictFloatingPoint()); - assertFalse(method.isNative()); - assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); + assertTrue(method.isStrictFloatingPoint()); // it fails with Java 21 JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); } diff --git a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index 4a09cf23ea1..d8be48f6707 100644 --- a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -111,7 +111,9 @@ import org.eclipse.xtext.common.types.testSetups.TypeWithInnerAnnotation; import org.eclipse.xtext.common.types.testSetups.TypeWithInnerEnum; import org.eclipse.xtext.java.tests.MyStubbedList; +import org.eclipse.xtext.util.JavaRuntimeVersion; import org.junit.Assert; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; @@ -2021,6 +2023,11 @@ public void testStrictFpType() { @Test public void testMethods_publicStrictFpMethod_01() { + // strictfp has no effect since Java 17 https://openjdk.org/jeps/306 + // and it doesn't seem to be present at runtime in 17+ + // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=545510#c6 + // for sure, it fails with Java 21 + Assume.assumeFalse("Ignored on Java 18 and later", JavaRuntimeVersion.isJava18OrLater()); String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); @@ -2029,7 +2036,7 @@ public void testMethods_publicStrictFpMethod_01() { assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); - assertTrue(method.isStrictFloatingPoint()); + assertTrue(method.isStrictFloatingPoint()); // it fails with Java 21 assertFalse(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java index 7290a2b1ec5..7d1c59e97f0 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java @@ -54,6 +54,10 @@ public static boolean isJava17OrLater() { return JAVA_VERSION >= 17; } + public static boolean isJava18OrLater() { + return JAVA_VERSION >= 18; + } + private static int determineJavaVersion() { String javaVersion = System.getProperty("java.version"); if (javaVersion == null) { From 9057ca6345472c10122fcc9e3df2fe0dd54f1f94 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 7 Apr 2024 15:35:19 +0200 Subject: [PATCH 13/26] don't use last as extension method in Xtend formatter because in Java 21 getLast() has been introduced, throwing NoSuchElementException instead of returning null --- .../org/eclipse/xtend/core/formatting2/XtendFormatter.xtend | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/formatting2/XtendFormatter.xtend b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/formatting2/XtendFormatter.xtend index 3429d331337..99ef238423d 100644 --- a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/formatting2/XtendFormatter.xtend +++ b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/formatting2/XtendFormatter.xtend @@ -335,6 +335,9 @@ class XtendFormatter extends XbaseWithAnnotationsFormatter { } override protected builder(List params) { + // don't use last (now deprecated) because in Java 21 + // getLast() has been introduced, throwing NoSuchElementException + // instead of returning null if (params.lastOrNull !== null) { val grammarElement = params.lastOrNull.grammarElement if (grammarElement == XMemberFeatureCallAccess.memberCallArgumentsXClosureParserRuleCall_1_1_4_0 || From f168b21b9766db66c61d8e5baf786317c53988c2 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 12:48:46 +0200 Subject: [PATCH 14/26] fixed a few Xtend type tests using Stubbed types --- .../tests/resource/ImportedNamesTest.xtend | 55 +++++++------- .../tests/typesystem/SuperTypeTests.xtend | 18 ++--- .../testdata/stubs/StubbedAbstractList.java | 21 ++++++ .../testdata/stubs/StubbedArrayList.java | 34 +++++++++ .../testdata/testdata/stubs/StubbedList.java | 21 ++++++ .../tests/resource/ImportedNamesTest.java | 75 ++++++++++++------- .../tests/typesystem/AllSuperTypesTest.java | 12 +-- .../core/tests/typesystem/SuperTypesTest.java | 6 +- 8 files changed, 169 insertions(+), 73 deletions(-) create mode 100644 org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedAbstractList.java create mode 100644 org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedArrayList.java create mode 100644 org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedList.java diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend index 19b74578ac5..299573c6c62 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend @@ -9,12 +9,11 @@ package org.eclipse.xtend.core.tests.resource import com.google.inject.Inject +import java.util.Comparator import org.eclipse.xtend.core.tests.AbstractXtendTestCase import org.eclipse.xtext.resource.IResourceDescription -import org.junit.Test import org.junit.Assert -import java.util.Arrays -import java.util.Comparator +import org.junit.Test class ImportedNamesTest extends AbstractXtendTestCase { @Inject @@ -138,37 +137,37 @@ class ImportedNamesTest extends AbstractXtendTestCase { import java.util.AbstractMap.*; class C { - val list = new java.util.ArrayList + val list = new testdata.stubs.StubbedArrayList val entry = new SimpleEntry(null, null) val int i = 0 } ''', true) val description = resourceDescriptionManager.getResourceDescription(file.eResource) val importedNames = description.importedNames - Assert.assertEquals(Arrays.asList( - "java.io.serializable", - "java.lang.cloneable", - "java.lang.iterable", - "java.lang.java$util$arraylist", - "java.lang.object", - "java.util.abstractcollection", - "java.util.abstractlist", - "java.util.abstractmap", - "java.util.abstractmap.java$util$arraylist", - "java.util.abstractmap.simpleentry", - "java.util.abstractmap$java$util$arraylist", - "java.util.abstractmap$simpleentry", - "java.util.arraylist", - "java.util.collection", - "java.util.list", - "java.util.map", - "java.util.map$entry", - "java.util.randomaccess", - "java.util$abstractmap$java$util$arraylist", - "java$util$abstractmap$java$util$arraylist", - "my.pack.c", - "my.pack.java$util$arraylist", - "org.eclipse.xtext.xbase.lib.java$util$arraylist").join("\n"), + Assert.assertEquals(''' + java.io.serializable + java.lang.cloneable + java.lang.iterable + java.lang.object + java.lang.testdata$stubs$stubbedarraylist + java.util.abstractcollection + java.util.abstractmap + java.util.abstractmap.simpleentry + java.util.abstractmap.testdata$stubs$stubbedarraylist + java.util.abstractmap$simpleentry + java.util.abstractmap$testdata$stubs$stubbedarraylist + java.util.collection + java.util.map + java.util.map$entry + java.util.randomaccess + java.util$abstractmap$testdata$stubs$stubbedarraylist + java$util$abstractmap$testdata$stubs$stubbedarraylist + my.pack.c + my.pack.testdata$stubs$stubbedarraylist + org.eclipse.xtext.xbase.lib.testdata$stubs$stubbedarraylist + testdata.stubs.stubbedabstractlist + testdata.stubs.stubbedarraylist + testdata.stubs.stubbedlist'''.toString.replace("\r", ""), importedNames.toList.sortWith(Comparator.naturalOrder).join("\n")); } } \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/typesystem/SuperTypeTests.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/typesystem/SuperTypeTests.xtend index 67730b9bc73..94ac41bef45 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/typesystem/SuperTypeTests.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/typesystem/SuperTypeTests.xtend @@ -12,12 +12,12 @@ import com.google.inject.Inject import java.io.Serializable import java.util.Collection import java.util.Collections -import java.util.List import org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations +import org.eclipse.xtext.util.JavaRuntimeVersion import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference import org.junit.Ignore import org.junit.Test -import org.eclipse.xtext.util.JavaRuntimeVersion +import testdata.stubs.StubbedList /** * @author Sebastian Zarnekow @@ -167,12 +167,12 @@ class SuperTypesTest extends AbstractSuperTypesTest { @Test override void testRawList() { - typeof(List).assertSuperTypes("Collection") + typeof(StubbedList).assertSuperTypes("Collection") } @Test override void testStringList() { - "java.util.List".assertSuperTypes("Collection") + "testdata.stubs.StubbedList".assertSuperTypes("Collection") } @Test @@ -277,23 +277,23 @@ class AllSuperTypesTest extends AbstractSuperTypesTest { @Test override void testRawList() { - typeof(List).assertSuperTypes("Collection", "Iterable", "Object") + typeof(StubbedList).assertSuperTypes("Collection", "Iterable", "Object") } @Test override void testStringList() { - "java.util.List".assertSuperTypes("Collection", "Iterable", "Object") + "testdata.stubs.StubbedList".assertSuperTypes("Collection", "Iterable", "Object") } @Test override void testStringArrayArrayList() { - "java.util.ArrayList".assertSuperTypes( - "AbstractList", + "testdata.stubs.StubbedArrayList".assertSuperTypes( + "StubbedAbstractList", "RandomAccess", "Cloneable", "Serializable", "AbstractCollection", - "List", + "StubbedList", "Collection", "Iterable", "Object") diff --git a/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedAbstractList.java b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedAbstractList.java new file mode 100644 index 00000000000..ae8f3a91ec2 --- /dev/null +++ b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedAbstractList.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2024 Lorenzo Bettini and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package testdata.stubs; + +import java.util.AbstractCollection; + +/** + * A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see, + * e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html). + * + * @author Lorenzo Bettini - Initial contribution and API + */ +public abstract class StubbedAbstractList extends AbstractCollection implements StubbedList { + +} diff --git a/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedArrayList.java b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedArrayList.java new file mode 100644 index 00000000000..34a55a771d5 --- /dev/null +++ b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedArrayList.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2024 Lorenzo Bettini and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package testdata.stubs; + +import java.util.Iterator; +import java.util.RandomAccess; + +/** + * A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see, + * e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html). + * + * @author Lorenzo Bettini - Initial contribution and API + */ +@SuppressWarnings("serial") +public class StubbedArrayList extends StubbedAbstractList + implements RandomAccess, Cloneable, java.io.Serializable { + + @Override + public Iterator iterator() { + return null; + } + + @Override + public int size() { + return 0; + } + +} diff --git a/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedList.java b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedList.java new file mode 100644 index 00000000000..0911fd466ea --- /dev/null +++ b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedList.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2024 Lorenzo Bettini and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package testdata.stubs; + +import java.util.Collection; + +/** + * A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see, + * e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html). + * + * @author Lorenzo Bettini - Initial contribution and API + */ +public interface StubbedList extends Collection { + +} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java index 2146651ad67..1df9f504c95 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java @@ -9,7 +9,6 @@ package org.eclipse.xtend.core.tests.resource; import com.google.inject.Inject; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -267,7 +266,7 @@ public void testExhaustiveList() { _builder.append("class C {"); _builder.newLine(); _builder.append("\t"); - _builder.append("val list = new java.util.ArrayList"); + _builder.append("val list = new testdata.stubs.StubbedArrayList"); _builder.newLine(); _builder.append("\t"); _builder.append("val entry = new SimpleEntry(null, null)"); @@ -280,31 +279,53 @@ public void testExhaustiveList() { final XtendFile file = this.file(_builder.toString(), true); final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource()); final Iterable importedNames = description.getImportedNames(); - Assert.assertEquals( - IterableExtensions.join(Arrays.asList( - "java.io.serializable", - "java.lang.cloneable", - "java.lang.iterable", - "java.lang.java$util$arraylist", - "java.lang.object", - "java.util.abstractcollection", - "java.util.abstractlist", - "java.util.abstractmap", - "java.util.abstractmap.java$util$arraylist", - "java.util.abstractmap.simpleentry", - "java.util.abstractmap$java$util$arraylist", - "java.util.abstractmap$simpleentry", - "java.util.arraylist", - "java.util.collection", - "java.util.list", - "java.util.map", - "java.util.map$entry", - "java.util.randomaccess", - "java.util$abstractmap$java$util$arraylist", - "java$util$abstractmap$java$util$arraylist", - "my.pack.c", - "my.pack.java$util$arraylist", - "org.eclipse.xtext.xbase.lib.java$util$arraylist"), "\n"), + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("java.io.serializable"); + _builder_1.newLine(); + _builder_1.append("java.lang.cloneable"); + _builder_1.newLine(); + _builder_1.append("java.lang.iterable"); + _builder_1.newLine(); + _builder_1.append("java.lang.object"); + _builder_1.newLine(); + _builder_1.append("java.lang.testdata$stubs$stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("java.util.abstractcollection"); + _builder_1.newLine(); + _builder_1.append("java.util.abstractmap"); + _builder_1.newLine(); + _builder_1.append("java.util.abstractmap.simpleentry"); + _builder_1.newLine(); + _builder_1.append("java.util.abstractmap.testdata$stubs$stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("java.util.abstractmap$simpleentry"); + _builder_1.newLine(); + _builder_1.append("java.util.abstractmap$testdata$stubs$stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("java.util.collection"); + _builder_1.newLine(); + _builder_1.append("java.util.map"); + _builder_1.newLine(); + _builder_1.append("java.util.map$entry"); + _builder_1.newLine(); + _builder_1.append("java.util.randomaccess"); + _builder_1.newLine(); + _builder_1.append("java.util$abstractmap$testdata$stubs$stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("java$util$abstractmap$testdata$stubs$stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("my.pack.c"); + _builder_1.newLine(); + _builder_1.append("my.pack.testdata$stubs$stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("org.eclipse.xtext.xbase.lib.testdata$stubs$stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("testdata.stubs.stubbedabstractlist"); + _builder_1.newLine(); + _builder_1.append("testdata.stubs.stubbedarraylist"); + _builder_1.newLine(); + _builder_1.append("testdata.stubs.stubbedlist"); + Assert.assertEquals(_builder_1.toString().replace("\r", ""), IterableExtensions.join(IterableExtensions.sortWith(IterableExtensions.toList(importedNames), Comparator.naturalOrder()), "\n")); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/AllSuperTypesTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/AllSuperTypesTest.java index dd009cf9b22..a91dfe8579e 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/AllSuperTypesTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/AllSuperTypesTest.java @@ -9,12 +9,12 @@ package org.eclipse.xtend.core.tests.typesystem; import java.util.Collection; -import java.util.List; import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; import org.junit.Ignore; import org.junit.Test; +import testdata.stubs.StubbedList; /** * @author Sebastian Zarnekow @@ -75,25 +75,25 @@ public void testPrimitiveArray() { @Test @Override public void testRawList() { - this.assertSuperTypes(List.class, "Collection", "Iterable", "Object"); + this.assertSuperTypes(StubbedList.class, "Collection", "Iterable", "Object"); } @Test @Override public void testStringList() { - this.assertSuperTypes("java.util.List", "Collection", "Iterable", "Object"); + this.assertSuperTypes("testdata.stubs.StubbedList", "Collection", "Iterable", "Object"); } @Test @Override public void testStringArrayArrayList() { - this.assertSuperTypes("java.util.ArrayList", - "AbstractList", + this.assertSuperTypes("testdata.stubs.StubbedArrayList", + "StubbedAbstractList", "RandomAccess", "Cloneable", "Serializable", "AbstractCollection", - "List", + "StubbedList", "Collection", "Iterable", "Object"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/SuperTypesTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/SuperTypesTest.java index 2c5d5dca8ab..4891cb704ba 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/SuperTypesTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/typesystem/SuperTypesTest.java @@ -9,12 +9,12 @@ package org.eclipse.xtend.core.tests.typesystem; import java.util.Collection; -import java.util.List; import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; import org.junit.Ignore; import org.junit.Test; +import testdata.stubs.StubbedList; /** * @author Sebastian Zarnekow @@ -75,13 +75,13 @@ public void testPrimitiveArray() { @Test @Override public void testRawList() { - this.assertSuperTypes(List.class, "Collection"); + this.assertSuperTypes(StubbedList.class, "Collection"); } @Test @Override public void testStringList() { - this.assertSuperTypes("java.util.List", "Collection"); + this.assertSuperTypes("testdata.stubs.StubbedList", "Collection"); } @Test From 7736942bd82636f8b51dbdf41935b2815319c4d6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 14:02:15 +0200 Subject: [PATCH 15/26] added some information for assertEquals --- .../core/tests/macro/declaration/DeclarationsTest.xtend | 4 +++- .../core/tests/macro/declaration/DeclarationsTest.java | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend index b1258576f85..22b7e7659bf 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend @@ -47,7 +47,9 @@ class DeclarationsTest extends AbstractXtendTestCase { assertEquals('java.lang.SuppressWarnings', supressWarningsDeclaration.qualifiedName) assertEquals('unused', suppressWarning.getStringArrayValue('value').get(0)) - assertEquals(2, supressWarningsDeclaration.annotations.size) + val annotations = supressWarningsDeclaration.annotations + assertEquals(annotations.map[it.annotationTypeDeclaration].toString, + 2, annotations.size) val valueProperty = supressWarningsDeclaration.declaredMembers.filter(typeof(AnnotationTypeElementDeclaration)).head assertEquals("String[]", valueProperty.type.toString) diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java index 846821172e7..e6d773edd34 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java @@ -45,6 +45,7 @@ import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Functions.Function1; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; import org.junit.Assert; @@ -79,7 +80,12 @@ public void testAnnotation() { final AnnotationTypeDeclaration supressWarningsDeclaration = suppressWarning.getAnnotationTypeDeclaration(); Assert.assertEquals("java.lang.SuppressWarnings", supressWarningsDeclaration.getQualifiedName()); Assert.assertEquals("unused", suppressWarning.getStringArrayValue("value")[0]); - Assert.assertEquals(2, IterableExtensions.size(supressWarningsDeclaration.getAnnotations())); + final Iterable annotations = supressWarningsDeclaration.getAnnotations(); + final Function1 _function_1 = (AnnotationReference it_1) -> { + return it_1.getAnnotationTypeDeclaration(); + }; + Assert.assertEquals(IterableExtensions.map(annotations, _function_1).toString(), + 2, IterableExtensions.size(annotations)); final AnnotationTypeElementDeclaration valueProperty = IterableExtensions.head(Iterables.filter(supressWarningsDeclaration.getDeclaredMembers(), AnnotationTypeElementDeclaration.class)); Assert.assertEquals("String[]", valueProperty.getType().toString()); Assert.assertEquals("value", valueProperty.getSimpleName()); From 6ba2ac849a2e0c8b0062577713fa2b7d0bf06aaa Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 17:52:20 +0200 Subject: [PATCH 16/26] StubbedSuppressWarnings A stub type to use instead of relying on Java API, which, in Java 21 has lost the java.lang.annotation.Target} specification. --- .../macro/declaration/DeclarationsTest.xtend | 4 +-- .../stubs/StubbedSuppressWarnings.java | 27 +++++++++++++++++++ .../macro/declaration/DeclarationsTest.java | 4 +-- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedSuppressWarnings.java diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend index 22b7e7659bf..1e47c530faf 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.xtend @@ -34,7 +34,7 @@ class DeclarationsTest extends AbstractXtendTestCase { @Test def testAnnotation() { validFile(''' - @SuppressWarnings("unused") + @testdata.stubs.StubbedSuppressWarnings("unused") class MyClass { @com.google.inject.Inject(optional=true) MyClass foo } @@ -44,7 +44,7 @@ class DeclarationsTest extends AbstractXtendTestCase { assertEquals('MyClass', clazz.qualifiedName) val suppressWarning = clazz.annotations.head val supressWarningsDeclaration = suppressWarning.annotationTypeDeclaration - assertEquals('java.lang.SuppressWarnings', supressWarningsDeclaration.qualifiedName) + assertEquals('testdata.stubs.StubbedSuppressWarnings', supressWarningsDeclaration.qualifiedName) assertEquals('unused', suppressWarning.getStringArrayValue('value').get(0)) val annotations = supressWarningsDeclaration.annotations diff --git a/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedSuppressWarnings.java b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedSuppressWarnings.java new file mode 100644 index 00000000000..077b633d610 --- /dev/null +++ b/org.eclipse.xtend.core.tests/testdata/testdata/stubs/StubbedSuppressWarnings.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2024 Lorenzo Bettini and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package testdata.stubs; + +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A stub type to use instead of relying on Java API {@link SuppressWarnings}, which, in Java 21 has lost the + * {@link java.lang.annotation.Target} specification. + * + * @author Lorenzo Bettini - Initial contribution and API + */ +@Target({ TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, MODULE }) +@Retention(RetentionPolicy.SOURCE) +public @interface StubbedSuppressWarnings { + String[] value(); +} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java index e6d773edd34..5f2f638c0ce 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/declaration/DeclarationsTest.java @@ -62,7 +62,7 @@ public class DeclarationsTest extends AbstractXtendTestCase { @Test public void testAnnotation() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("@SuppressWarnings(\"unused\")"); + _builder.append("@testdata.stubs.StubbedSuppressWarnings(\"unused\")"); _builder.newLine(); _builder.append("class MyClass {"); _builder.newLine(); @@ -78,7 +78,7 @@ public void testAnnotation() { Assert.assertEquals("MyClass", clazz.getQualifiedName()); final AnnotationReference suppressWarning = IterableExtensions.head(clazz.getAnnotations()); final AnnotationTypeDeclaration supressWarningsDeclaration = suppressWarning.getAnnotationTypeDeclaration(); - Assert.assertEquals("java.lang.SuppressWarnings", supressWarningsDeclaration.getQualifiedName()); + Assert.assertEquals("testdata.stubs.StubbedSuppressWarnings", supressWarningsDeclaration.getQualifiedName()); Assert.assertEquals("unused", suppressWarning.getStringArrayValue("value")[0]); final Iterable annotations = supressWarningsDeclaration.getAnnotations(); final Function1 _function_1 = (AnnotationReference it_1) -> { From 4d84366cb1743ebd6c5aa1b6009bbafc20dcce14 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 18:06:44 +0200 Subject: [PATCH 17/26] updated compiler tests to use lastOrNull or they would fail due to Java 21 getLast method --- .../core/tests/compiler/CompilerBug427637Test.xtend | 10 +++++----- .../tests/java8/compiler/CompilerBug427637Test.xtend | 10 +++++----- .../core/tests/compiler/CompilerBug427637Test.java | 8 ++++---- .../tests/java8/compiler/CompilerBug427637Test.java | 8 ++++---- .../xtext/xbase/compiler/JvmModelGenerator.java | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend index cc667570aa6..6958394df34 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend @@ -1014,7 +1014,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { result += new WhitespaceData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), if (leaf.offset == 0) "" else if(leafs.containsComment) null else " ") else - if(equalIndentationChange && leafs.leafs.last != leaf) + if(equalIndentationChange && leafs.leafs.lastOrNull != leaf) result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines) else result += new NewLineData(leaf.offset, leaf.length, if(equalIndentationChange) 0 else increaseIndentationChange, if(equalIndentationChange) 0 else decreaseIndentationChange, if (trace) new RuntimeException(), newLines) @@ -1023,7 +1023,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { var newLines = 1 if (leaf.leadingComment?.endsWithNewLine) newLines = newLines - 1 - if(equalIndentationChange && leafs.leafs.last != leaf) + if(equalIndentationChange && leafs.leafs.lastOrNull != leaf) result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines) else result += new NewLineData(leaf.offset, leaf.length, 0, 0, if (trace) new RuntimeException(), newLines) @@ -1472,7 +1472,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { WhitespaceData _whitespaceData_1 = new WhitespaceData(_offset_2, _length_1, increaseIndentationChange, decreaseIndentationChange, _xifexpression_3, _xifexpression_4); result.add(_whitespaceData_1); } else { - if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) { + if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) { int _offset_4 = ((WhitespaceInfo)leaf).getOffset(); int _length_2 = ((WhitespaceInfo)leaf).getLength(); RuntimeException _xifexpression_6 = null; @@ -1515,7 +1515,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { if (_endsWithNewLine_2) { newLines_1 = (newLines_1 - 1); } - if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) { + if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) { int _offset_6 = ((WhitespaceInfo)leaf).getOffset(); int _length_4 = ((WhitespaceInfo)leaf).getLength(); RuntimeException _xifexpression_10 = null; @@ -1672,5 +1672,5 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } } ''') - } + } } \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.xtend index f3fca4d69e3..7892da9a2df 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.xtend @@ -968,7 +968,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil result += new WhitespaceData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), if (leaf.offset == 0) "" else if(leafs.containsComment) null else " ") else - if(equalIndentationChange && leafs.leafs.last != leaf) + if(equalIndentationChange && leafs.leafs.lastOrNull != leaf) result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines) else result += new NewLineData(leaf.offset, leaf.length, if(equalIndentationChange) 0 else increaseIndentationChange, if(equalIndentationChange) 0 else decreaseIndentationChange, if (trace) new RuntimeException(), newLines) @@ -977,7 +977,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil var newLines = 1 if (leaf.leadingComment?.endsWithNewLine) newLines = newLines - 1 - if(equalIndentationChange && leafs.leafs.last != leaf) + if(equalIndentationChange && leafs.leafs.lastOrNull != leaf) result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines) else result += new NewLineData(leaf.offset, leaf.length, 0, 0, if (trace) new RuntimeException(), newLines) @@ -1417,7 +1417,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil WhitespaceData _whitespaceData_1 = new WhitespaceData(_offset_2, _length_1, increaseIndentationChange, decreaseIndentationChange, _xifexpression_3, _xifexpression_4); result.add(_whitespaceData_1); } else { - if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) { + if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) { int _offset_4 = ((WhitespaceInfo)leaf).getOffset(); int _length_2 = ((WhitespaceInfo)leaf).getLength(); RuntimeException _xifexpression_6 = null; @@ -1460,7 +1460,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil if (_endsWithNewLine_2) { newLines_1 = (newLines_1 - 1); } - if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) { + if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) { int _offset_6 = ((WhitespaceInfo)leaf).getOffset(); int _length_4 = ((WhitespaceInfo)leaf).getLength(); RuntimeException _xifexpression_10 = null; @@ -1613,5 +1613,5 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil } } ''') - } + } } \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java index 1bb5f0636e9..a006d18ecf2 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java @@ -2361,7 +2361,7 @@ public void testBug_427637_15() { _builder.append("else"); _builder.newLine(); _builder.append("\t\t\t\t\t\t\t"); - _builder.append("if(equalIndentationChange && leafs.leafs.last != leaf)"); + _builder.append("if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)"); _builder.newLine(); _builder.append("\t\t\t\t\t\t\t\t"); _builder.append("result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)"); @@ -2388,7 +2388,7 @@ public void testBug_427637_15() { _builder.append("newLines = newLines - 1"); _builder.newLine(); _builder.append("\t\t\t\t\t\t"); - _builder.append("if(equalIndentationChange && leafs.leafs.last != leaf)"); + _builder.append("if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)"); _builder.newLine(); _builder.append("\t\t\t\t\t\t\t"); _builder.append("result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)"); @@ -3653,7 +3653,7 @@ public void testBug_427637_15() { _builder_1.append("} else {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) {"); + _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("int _offset_4 = ((WhitespaceInfo)leaf).getOffset();"); @@ -3782,7 +3782,7 @@ public void testBug_427637_15() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) {"); + _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("int _offset_6 = ((WhitespaceInfo)leaf).getOffset();"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.java index 024413636b6..09de561505b 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.java @@ -2240,7 +2240,7 @@ public void testBug_427637_15() { _builder.append("else"); _builder.newLine(); _builder.append("\t\t\t\t\t\t\t"); - _builder.append("if(equalIndentationChange && leafs.leafs.last != leaf)"); + _builder.append("if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)"); _builder.newLine(); _builder.append("\t\t\t\t\t\t\t\t"); _builder.append("result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)"); @@ -2267,7 +2267,7 @@ public void testBug_427637_15() { _builder.append("newLines = newLines - 1"); _builder.newLine(); _builder.append("\t\t\t\t\t\t"); - _builder.append("if(equalIndentationChange && leafs.leafs.last != leaf)"); + _builder.append("if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)"); _builder.newLine(); _builder.append("\t\t\t\t\t\t\t"); _builder.append("result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)"); @@ -3505,7 +3505,7 @@ public void testBug_427637_15() { _builder_1.append("} else {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) {"); + _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("int _offset_4 = ((WhitespaceInfo)leaf).getOffset();"); @@ -3634,7 +3634,7 @@ public void testBug_427637_15() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.last(leafs.getLeafs()), leaf)))) {"); + _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("int _offset_6 = ((WhitespaceInfo)leaf).getOffset();"); diff --git a/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java b/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java index 1897e1df081..01d459c6219 100644 --- a/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java +++ b/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java @@ -1363,13 +1363,13 @@ protected void _toJavaLiteral(final JvmDoubleAnnotationValue it, final ITreeAppe _switchResult = "Double.NaN"; } if (!_matched) { - if (Objects.equals(it_1, Double.POSITIVE_INFINITY)) { + if (com.google.common.base.Objects.equal(it_1, Double.POSITIVE_INFINITY)) { _matched=true; _switchResult = "Double.POSITIVE_INFINITY"; } } if (!_matched) { - if (Objects.equals(it_1, Double.NEGATIVE_INFINITY)) { + if (com.google.common.base.Objects.equal(it_1, Double.NEGATIVE_INFINITY)) { _matched=true; _switchResult = "Double.NEGATIVE_INFINITY"; } @@ -1393,13 +1393,13 @@ protected void _toJavaLiteral(final JvmFloatAnnotationValue it, final ITreeAppen _switchResult = "Float.NaN"; } if (!_matched) { - if (Objects.equals(it_1, Float.POSITIVE_INFINITY)) { + if (com.google.common.base.Objects.equal(it_1, Float.POSITIVE_INFINITY)) { _matched=true; _switchResult = "Float.POSITIVE_INFINITY"; } } if (!_matched) { - if (Objects.equals(it_1, Float.NEGATIVE_INFINITY)) { + if (com.google.common.base.Objects.equal(it_1, Float.NEGATIVE_INFINITY)) { _matched=true; _switchResult = "Float.NEGATIVE_INFINITY"; } From 144e179599d5370bb502051b4461f71a3b2c6a77 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 18:41:20 +0200 Subject: [PATCH 18/26] fixed Xtend outline tests for new members in Java 21 --- .../tests/outline/JvmQuickOutlineTests.java | 24 +++++++++++++++++-- .../ide/tests/outline/QuickOutlineTests.java | 15 ++++++++++++ .../xtext/util/JavaRuntimeVersion.java | 4 ++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/JvmQuickOutlineTests.java b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/JvmQuickOutlineTests.java index 62c2a4c5812..a49e9291027 100644 --- a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/JvmQuickOutlineTests.java +++ b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/JvmQuickOutlineTests.java @@ -46,9 +46,17 @@ public void testFieldsFromSuper() throws Exception { setShowInherited(true); assertBuilder = newAssertBuilder(model).numChildren(3); - sub = assertBuilder.child(1, "Foo - test").numChildren(JavaRuntimeVersion.isJava14OrLater() ? 14 : 15); + int numChildren = 15; + if (JavaRuntimeVersion.isJava14OrLater()) { + numChildren = 14; + } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 15; // wait0 + } + + sub = assertBuilder.child(1, "Foo - test").numChildren(numChildren); checkExtendedMethods(sub, "Foo"); - sub2 = assertBuilder.child(2, "Foo2 - test").numChildren(JavaRuntimeVersion.isJava14OrLater() ? 14 : 15); + sub2 = assertBuilder.child(2, "Foo2 - test").numChildren(numChildren); checkExtendedMethods(sub2, "Foo2"); } @@ -65,6 +73,9 @@ public void testEnum() throws Exception { } else if (JavaRuntimeVersion.isJava13OrLater()) { numChildren = 33; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 34; // wait0, hash : int + } AssertBuilder interfaze = assertBuilder.numChildren(1).child(0, "Foo - (default package)").numChildren(numChildren); interfaze.child(0, "BAR - Foo").numChildren(0); interfaze.child(1, "BAZ - Foo").numChildren(0); @@ -72,6 +83,9 @@ public void testEnum() throws Exception { interfaze.nextChild("EnumDesc> - Enum").hasTextRegion(false); } interfaze.nextChild("valueOf(Class, String) > : T - Enum").hasTextRegion(false); + if (JavaRuntimeVersion.isJava21OrLater()) { + interfaze.nextChild("hash : int - Enum").hasTextRegion(false); + } interfaze.nextChild("name : String - Enum").hasTextRegion(false); interfaze.nextChild("ordinal : int - Enum").hasTextRegion(false); interfaze.nextChild("new(String, int) - Enum").hasTextRegion(false); @@ -153,6 +167,9 @@ public void testMethodsFromSuper() throws Exception { if (JavaRuntimeVersion.isJava14OrLater()) { numChildren = 15; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 16; // wait0 + } sub = assertBuilder.child(1, "Foo - test").numChildren(numChildren); sub.child(0, "baz() : Number - Foo").numChildren(0).hasTextRegion(true); sub.nextChild("toString() : String - Foo").numChildren(0).hasTextRegion(true); @@ -193,6 +210,9 @@ public void testMixedDispatch_0() throws Exception { if (JavaRuntimeVersion.isJava14OrLater()) { numChildren = 14; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 15; // wait0 + } sub = assertBuilder.child(1, "Foo - test").numChildren(numChildren).hasTextRegion(true); sub.nextChild("_foo(Number) : void - Foo").hasTextRegion(true); sub.nextChild("foo(Serializable) : void - Foo"); diff --git a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/QuickOutlineTests.java b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/QuickOutlineTests.java index a488ce3d4db..dfb711061c8 100644 --- a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/QuickOutlineTests.java +++ b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/outline/QuickOutlineTests.java @@ -82,6 +82,9 @@ public void testFieldsFromSuper() throws Exception { if (JavaRuntimeVersion.isJava14OrLater()) { numChildren = 15; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 16; // wait0 + } sub = assertBuilder.child(1, "Foo - test").numChildren(numChildren); int counter = 0; sub.child(counter++, "baz : Number - Foo").numChildren(0).hasTextRegion(true); @@ -123,6 +126,9 @@ public void testMethodsFromSuper() throws Exception { if (JavaRuntimeVersion.isJava14OrLater()) { numChildren = 14; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 15; // wait0 + } sub = assertBuilder.child(1, "Foo - test").numChildren(numChildren); int counter = 0; sub.child(counter++, "baz() : Number - Foo").numChildren(0).hasTextRegion(true); @@ -158,6 +164,9 @@ public void testMethodsFromSuper_02() throws Exception { if (JavaRuntimeVersion.isJava14OrLater()) { numChildren = 12; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 13; // wait0 + } sub = assertBuilder.child(1, "C - pack.name").numChildren(numChildren); int counter = 0; sub.child(counter++, "E - C").hasTextRegion(true); @@ -195,6 +204,9 @@ public void testMixedDispatch_0() throws Exception { if (JavaRuntimeVersion.isJava14OrLater()) { numChildren = 12; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 13; // wait0 + } sub = assertBuilder.child(1, "Foo - test").numChildren(numChildren).hasTextRegion(true); AssertBuilder foo = sub.child(0, "foo(Serializable) : void - Foo").numChildren(2).hasTextRegion(true); int counter = 0; @@ -246,6 +258,9 @@ public void testResolvedSignatures() throws Exception { if (JavaRuntimeVersion.isJava14OrLater()) { numChildren = 17; } + if (JavaRuntimeVersion.isJava21OrLater()) { + numChildren = 18; // wait0 + } sub = assertBuilder.child(1, "Foo - test").numChildren(numChildren).hasTextRegion(true); int i = 0; sub.child(i++, "new() - Foo").hasTextRegion(true); diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java index 7d1c59e97f0..a2a6e896eda 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java @@ -58,6 +58,10 @@ public static boolean isJava18OrLater() { return JAVA_VERSION >= 18; } + public static boolean isJava21OrLater() { + return JAVA_VERSION >= 21; + } + private static int determineJavaVersion() { String javaVersion = System.getProperty("java.version"); if (javaVersion == null) { From 5e4c16ded74ef4800f687837da3cc6ffe8a76243 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 18:44:00 +0200 Subject: [PATCH 19/26] fixed Xtend content assist tests for new members in Java 21 --- .../eclipse/xtend/ide/tests/contentassist/Bug427440Test.xtend | 3 +++ .../eclipse/xtend/ide/tests/contentassist/Bug427440Test.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.xtend b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.xtend index 6493a8799d0..883c1edfc57 100644 --- a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.xtend +++ b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.xtend @@ -34,6 +34,9 @@ class Bug427440Test extends AbstractXtendContentAssistBugTest { } ''').computeCompletionProposals('|').iterator proposals.next.assertContains("augument") + if (JavaRuntimeVersion.isJava21OrLater) { + proposals.next.assertContains("accessFlags") + } proposals.next.assertContains("annotatedInterfaces") proposals.next.assertContains("annotatedSuperclass") proposals.next.assertContains("annotation") diff --git a/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.java b/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.java index a73c3f24613..5c0382c0b0b 100644 --- a/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.java +++ b/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/contentassist/Bug427440Test.java @@ -54,6 +54,10 @@ public void testStaticMemberPriority() throws Exception { _builder.newLine(); final Iterator proposals = ((List)Conversions.doWrapArray(_newBuilder.append(_builder.toString()).computeCompletionProposals("|"))).iterator(); this.assertContains(proposals.next(), "augument"); + boolean _isJava21OrLater = JavaRuntimeVersion.isJava21OrLater(); + if (_isJava21OrLater) { + this.assertContains(proposals.next(), "accessFlags"); + } this.assertContains(proposals.next(), "annotatedInterfaces"); this.assertContains(proposals.next(), "annotatedSuperclass"); this.assertContains(proposals.next(), "annotation"); From fc2847dd664375f81969feac9b9d704c266a9d42 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 19:24:50 +0200 Subject: [PATCH 20/26] build matrix with Java 21 (Linux only) --- .github/workflows/maven.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index bb7c3ee57e4..2fa387bd941 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -15,6 +15,10 @@ jobs: strategy: matrix: # 'macos-14' is arm64 os: ['ubuntu-22.04', 'macos-14', 'windows-2022'] + java: [ 17 ] + include: + - os: ubuntu-22.04 + java: 21 fail-fast: false runs-on: ${{ matrix.os }} @@ -22,10 +26,10 @@ jobs: - name: 'Check out repository' uses: actions/checkout@v4 - - name: 'Set up Java' + - name: 'Set up Java ${{ matrix.java }}' uses: actions/setup-java@v4 with: - java-version: 21 + java-version: ${{ matrix.java }} distribution: 'temurin' - name: 'Cache Maven packages' @@ -72,7 +76,7 @@ jobs: - name: 'Set up Java' uses: actions/setup-java@v4 with: - java-version: 21 + java-version: 17 distribution: 'temurin' - name: 'Cache Maven packages' From ada1b3d23ad6b8349af41636e89c970fc2828bea Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 20:34:34 +0200 Subject: [PATCH 21/26] different cache based on Java version --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2fa387bd941..ea730e22828 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -36,8 +36,8 @@ jobs: uses: actions/cache@v4 with: path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml', '**/*.target') }} - restore-keys: ${{ runner.os }}-m2 + key: ${{ runner.os }}-m2-${{ matrix.java }}-${{ hashFiles('**/pom.xml', '**/*.target') }} + restore-keys: ${{ runner.os }}-m2-${{ matrix.java }} - name: Set Maven Home environment variable run: echo "MAVEN_WRAPPER_HOME=$(./mvnw --version | grep "Maven home:" | cut -c 13-)" >> "$GITHUB_ENV" From 69ec75decaef398ffed4c2f102485233056f3ab2 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 20:36:33 +0200 Subject: [PATCH 22/26] removed isJava18OrLater and use isJava21OrLater --- .../common/types/access/impl/AbstractTypeProviderTest.java | 2 +- .../common/types/access/impl/AbstractTypeProviderTest.java | 2 +- .../common/types/access/impl/AbstractTypeProviderTest.java | 2 +- .../src/org/eclipse/xtext/util/JavaRuntimeVersion.java | 4 ---- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index d7b89cf7ba1..4ae5c0c6592 100644 --- a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -2009,7 +2009,7 @@ public void testMethods_publicStrictFpMethod_01() { // and it doesn't seem to be present at runtime in 17+ // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=545510#c6 // for sure, it fails with Java 21 - Assume.assumeFalse("Ignored on Java 18 and later", JavaRuntimeVersion.isJava18OrLater()); + Assume.assumeFalse("Ignored on Java 21 and later", JavaRuntimeVersion.isJava21OrLater()); String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); diff --git a/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index 3c8c0e3ee7c..98e882848d3 100644 --- a/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -2027,7 +2027,7 @@ public void testMethods_publicStrictFpMethod_01() { // and it doesn't seem to be present at runtime in 17+ // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=545510#c6 // for sure, it fails with Java 21 - Assume.assumeFalse("Ignored on Java 18 and later", JavaRuntimeVersion.isJava18OrLater()); + Assume.assumeFalse("Ignored on Java 21 and later", JavaRuntimeVersion.isJava21OrLater()); String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); diff --git a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java index d8be48f6707..e8e83554c34 100644 --- a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java +++ b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/common/types/access/impl/AbstractTypeProviderTest.java @@ -2027,7 +2027,7 @@ public void testMethods_publicStrictFpMethod_01() { // and it doesn't seem to be present at runtime in 17+ // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=545510#c6 // for sure, it fails with Java 21 - Assume.assumeFalse("Ignored on Java 18 and later", JavaRuntimeVersion.isJava18OrLater()); + Assume.assumeFalse("Ignored on Java 21 and later", JavaRuntimeVersion.isJava21OrLater()); String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java index a2a6e896eda..e80af13dd32 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaRuntimeVersion.java @@ -54,10 +54,6 @@ public static boolean isJava17OrLater() { return JAVA_VERSION >= 17; } - public static boolean isJava18OrLater() { - return JAVA_VERSION >= 18; - } - public static boolean isJava21OrLater() { return JAVA_VERSION >= 21; } From 6bf27b614b33cd9f89a60d638b533dbd1e3f4664 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 9 Apr 2024 20:58:55 +0200 Subject: [PATCH 23/26] JAVA_HOME_21_X64 in Jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 1d22baca4d1..64d2ace5e9d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,6 +58,7 @@ pipeline { MAVEN_OPTS = "-Xmx1500m" JAVA_HOME_11_X64 = tool(type:'jdk', name:'temurin-jdk11-latest') JAVA_HOME_17_X64 = tool(type:'jdk', name:'temurin-jdk17-latest') + JAVA_HOME_21_X64 = tool(type:'jdk', name:'temurin-jdk21-latest') } steps { xvnc(useXauthority: true) { From 762b1e6f2cd2188c55f4c558d552e0279e38698d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sat, 20 Apr 2024 13:56:55 +0200 Subject: [PATCH 24/26] simplified the custom injector provider --- .../ExtendedXbaseResourceDescriptionStrategyTest.java | 6 +----- .../XImportSectionResourceDescriptionStrategyTest.java | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java index 7e4bac65034..a018a5943a5 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/ExtendedXbaseResourceDescriptionStrategyTest.java @@ -38,12 +38,8 @@ protected ContentAssistFragmentTestLangRuntimeModule createRuntimeModule() { // make it work also with Maven/Tycho and OSGI // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672 // to access the testdata.stubs.StubbedList in this bundle + // allows for bindClassLoaderToInstance to get the class loader of this bundle return new ContentAssistFragmentTestLangRuntimeModule() { - @Override - public ClassLoader bindClassLoaderToInstance() { - return ContentAssistFragmentTestLangInjectorProviderCustom.class - .getClassLoader(); - } }; } } diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java index b613726167c..d8b1e87fda7 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/resources/XImportSectionResourceDescriptionStrategyTest.java @@ -37,12 +37,8 @@ protected XImportSectionTestLangRuntimeModule createRuntimeModule() { // make it work also with Maven/Tycho and OSGI // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672 // to access the testdata.stubs.StubbedList in this bundle + // allows for bindClassLoaderToInstance to get the class loader of this bundle return new XImportSectionTestLangRuntimeModule() { - @Override - public ClassLoader bindClassLoaderToInstance() { - return XImportSectionTestLangInjectorProviderCustom.class - .getClassLoader(); - } }; } } From 6cc978f4b05cd3cff653beee3ea356b621dc8435 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 25 Apr 2024 08:43:09 +0200 Subject: [PATCH 25/26] use toolchains.xml generated by setup-java --- .github/workflows/maven.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ea730e22828..b3aa0c0ab5c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -32,6 +32,9 @@ jobs: java-version: ${{ matrix.java }} distribution: 'temurin' + - name: Copy toolchains.xml + run: cat ~/.m2/toolchains.xml | tee toolchains.xml + - name: 'Cache Maven packages' uses: actions/cache@v4 with: @@ -50,7 +53,7 @@ jobs: - name: Build and test uses: coactions/setup-xvfb@v1.0.1 with: - run: ./mvnw --toolchains releng/toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.full.releng + run: ./mvnw --toolchains toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.full.releng - name: Archive Test Results uses: actions/upload-artifact@v4 @@ -79,6 +82,9 @@ jobs: java-version: 17 distribution: 'temurin' + - name: Copy toolchains.xml + run: cat ~/.m2/toolchains.xml | tee toolchains.xml + - name: 'Cache Maven packages' uses: actions/cache@v4 with: @@ -90,7 +96,7 @@ jobs: run: echo "MAVEN_WRAPPER_HOME=$(./mvnw --version | grep "Maven home:" | cut -c 13-)" >> "$GITHUB_ENV" - name: Build Maven artifacts - run: ./mvnw --toolchains releng/toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.maven.releng + run: ./mvnw --toolchains toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.maven.releng - name: Archive Test Results uses: actions/upload-artifact@v4 From d3c35d7af2dcfe656b9c0b7cff135a3ad5d6221e Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 30 Apr 2024 11:54:49 +0200 Subject: [PATCH 26/26] updated xtend gen file --- .../eclipse/xtext/xbase/compiler/JvmModelGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java b/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java index 01d459c6219..1897e1df081 100644 --- a/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java +++ b/org.eclipse.xtext.xbase/xtend-gen/org/eclipse/xtext/xbase/compiler/JvmModelGenerator.java @@ -1363,13 +1363,13 @@ protected void _toJavaLiteral(final JvmDoubleAnnotationValue it, final ITreeAppe _switchResult = "Double.NaN"; } if (!_matched) { - if (com.google.common.base.Objects.equal(it_1, Double.POSITIVE_INFINITY)) { + if (Objects.equals(it_1, Double.POSITIVE_INFINITY)) { _matched=true; _switchResult = "Double.POSITIVE_INFINITY"; } } if (!_matched) { - if (com.google.common.base.Objects.equal(it_1, Double.NEGATIVE_INFINITY)) { + if (Objects.equals(it_1, Double.NEGATIVE_INFINITY)) { _matched=true; _switchResult = "Double.NEGATIVE_INFINITY"; } @@ -1393,13 +1393,13 @@ protected void _toJavaLiteral(final JvmFloatAnnotationValue it, final ITreeAppen _switchResult = "Float.NaN"; } if (!_matched) { - if (com.google.common.base.Objects.equal(it_1, Float.POSITIVE_INFINITY)) { + if (Objects.equals(it_1, Float.POSITIVE_INFINITY)) { _matched=true; _switchResult = "Float.POSITIVE_INFINITY"; } } if (!_matched) { - if (com.google.common.base.Objects.equal(it_1, Float.NEGATIVE_INFINITY)) { + if (Objects.equals(it_1, Float.NEGATIVE_INFINITY)) { _matched=true; _switchResult = "Float.NEGATIVE_INFINITY"; }