diff --git a/org.eclipse.xtend.core.tests/META-INF/MANIFEST.MF b/org.eclipse.xtend.core.tests/META-INF/MANIFEST.MF index 897da505875..6d8701fc553 100644 --- a/org.eclipse.xtend.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.xtend.core.tests/META-INF/MANIFEST.MF @@ -22,8 +22,7 @@ Require-Bundle: org.eclipse.xtend.core;bundle-version="2.38.0", org.objectweb.asm;bundle-version="[9.7.1,9.8.0)", org.eclipse.jdt.core;bundle-version="3.37.0", org.eclipse.xtext.builder.standalone;bundle-version="2.38.0", - org.eclipse.xtext.java;bundle-version="2.38.0", - org.eclipse.draw2d + org.eclipse.xtext.java;bundle-version="2.38.0" Import-Package: jakarta.inject;version="2.0.1", org.apache.log4j;version="1.2.24", org.apache.log4j.spi;version="1.2.24", diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/OverrideValidationTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/OverrideValidationTest.java index 346eb690bda..4917d42a962 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/OverrideValidationTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/OverrideValidationTest.java @@ -18,9 +18,7 @@ import org.eclipse.xtend.core.xtend.XtendClass; import org.eclipse.xtend.core.xtend.XtendInterface; import org.eclipse.xtext.testing.validation.ValidationTestHelper; -import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.xbase.XbasePackage; -import org.junit.Assume; import org.junit.Test; import com.google.inject.Inject; @@ -1068,18 +1066,11 @@ public void testClassMustBeAbstract_06() throws Exception { helper.assertNoWarnings(xtendClass, XTEND_FUNCTION, MISSING_SYNCHRONIZED); } - /** - * Since there's no record in the JDK and adding a Java source with a record in this - * project would require Java 21 compilation level, I'm using a known record from - * draw2d, which is in our target platform. - */ @Test public void testOverrideJavaRecord() throws Exception { - Assume.assumeTrue("Active only on Java 21 and later", JavaRuntimeVersion.isJava21OrLater()); - var javaRecord = "org.eclipse.draw2d.geometry.Interval"; - var source = "class Foo extends " + javaRecord + " { }"; + var source = "class Foo extends test.SomeRecord { }"; XtendClass xtendClass = clazz(source); helper.assertError(xtendClass, XTEND_CLASS, OVERRIDDEN_FINAL, - source.indexOf(javaRecord), javaRecord.length(), + source.indexOf("test.SomeRecord"), "test.SomeRecord".length(), "override", "final"); } diff --git a/org.eclipse.xtend.core.tests/testdata/test/SomeRecord.java b/org.eclipse.xtend.core.tests/testdata/test/SomeRecord.java new file mode 100644 index 00000000000..9fd25392255 --- /dev/null +++ b/org.eclipse.xtend.core.tests/testdata/test/SomeRecord.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * 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 test; + +/** + * @author Lorenzo Bettini - Initial contribution and API + */ +public record SomeRecord() { + +} diff --git a/org.eclipse.xtend.maven.plugin/src/test/resources/it/compile/simple/src/main/java/test/JavaRecord.java b/org.eclipse.xtend.maven.plugin/src/test/resources/it/compile/simple/src/main/java/test/JavaRecord.java new file mode 100644 index 00000000000..1792c04fbf4 --- /dev/null +++ b/org.eclipse.xtend.maven.plugin/src/test/resources/it/compile/simple/src/main/java/test/JavaRecord.java @@ -0,0 +1,7 @@ +package test; + +public record JavaRecord(String name) { + public XtendA foo(XtendA test) { + return test; + } +} diff --git a/org.eclipse.xtend.maven.plugin/src/test/resources/it/compile/simple/src/main/java/test/XtendA.xtend b/org.eclipse.xtend.maven.plugin/src/test/resources/it/compile/simple/src/main/java/test/XtendA.xtend index 99a317b545f..e9e7af7244d 100644 --- a/org.eclipse.xtend.maven.plugin/src/test/resources/it/compile/simple/src/main/java/test/XtendA.xtend +++ b/org.eclipse.xtend.maven.plugin/src/test/resources/it/compile/simple/src/main/java/test/XtendA.xtend @@ -1,13 +1,16 @@ package test class XtendA extends JavaB { - + def JavaB test2(XtendC s) { return s.foo.newJavaB } - + def JavaB newJavaB() { return new JavaB() } - + + def JavaRecord newJavaRecord() { + return new JavaRecord("a test") + } } \ No newline at end of file diff --git a/org.eclipse.xtext.builder.standalone.tests/src/org/eclipse/xtext/builder/standalone/incremental/IncrementalStandaloneBuilderWithJava21Test.java b/org.eclipse.xtext.builder.standalone.tests/src/org/eclipse/xtext/builder/standalone/incremental/IncrementalStandaloneBuilderWithJava21Test.java index aa8ebf794a2..6f146c347d9 100644 --- a/org.eclipse.xtext.builder.standalone.tests/src/org/eclipse/xtext/builder/standalone/incremental/IncrementalStandaloneBuilderWithJava21Test.java +++ b/org.eclipse.xtext.builder.standalone.tests/src/org/eclipse/xtext/builder/standalone/incremental/IncrementalStandaloneBuilderWithJava21Test.java @@ -13,9 +13,7 @@ import java.io.File; -import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.util.JavaVersion; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; @@ -36,8 +34,7 @@ public void setUp() { } @Test - public void testCleanBuildAccessingJava21Record() { - Assume.assumeTrue("Active only on Java 21 and later", JavaRuntimeVersion.isJava21OrLater()); + public void testCleanBuildAccessingJavaRecord() { initBuilder(new ContentAssistFragmentTestLangConfiguration()); assertTrue(testBuilder.launch()); diff --git a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/JavaSourceLanguageTest.java b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/JavaSourceLanguageTest.java index 3df5bf1b39e..520f40345f9 100644 --- a/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/JavaSourceLanguageTest.java +++ b/org.eclipse.xtext.java.tests/src/org/eclipse/xtext/java/tests/JavaSourceLanguageTest.java @@ -37,12 +37,10 @@ import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.XtextRunner; import org.eclipse.xtext.testing.util.InMemoryURIHandler; -import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.util.JavaVersion; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.junit.Assert; -import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; @@ -186,8 +184,7 @@ public void testClassShadowing() { } @Test - public void testJava21Record() { - Assume.assumeTrue("Active only on Java 21 and later", JavaRuntimeVersion.isJava21OrLater()); + public void testJavaRecord() { ImmutableMap files = ImmutableMap.builder() .put("example/MyRecord.java", "package example;\n" diff --git a/org.eclipse.xtext.maven.plugin/src/test/java/org/eclipse/xtext/maven/plugin/XtextGeneratorIT.java b/org.eclipse.xtext.maven.plugin/src/test/java/org/eclipse/xtext/maven/plugin/XtextGeneratorIT.java index 17d7d9405b0..7276e0a7c4d 100644 --- a/org.eclipse.xtext.maven.plugin/src/test/java/org/eclipse/xtext/maven/plugin/XtextGeneratorIT.java +++ b/org.eclipse.xtext.maven.plugin/src/test/java/org/eclipse/xtext/maven/plugin/XtextGeneratorIT.java @@ -237,6 +237,7 @@ public void javaLangBiRef() throws Exception { verifier.verifyFilePresent(verifier.getBasedir() + "/src-gen/XbaseReferToJava.java"); verifier.verifyFilePresent(verifier.getBasedir() + "/target/xtext-temp/stub-classes/XbaseReferToJava.class"); verifier.verifyFilePresent(verifier.getBasedir() + "/target/xtext-temp/stub-classes/JavaClazz.class"); + verifier.verifyFilePresent(verifier.getBasedir() + "/target/xtext-temp/stub-classes/JavaRecord.class"); } @Test diff --git a/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/java-lang-bi-ref/src/JavaRecord.java b/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/java-lang-bi-ref/src/JavaRecord.java new file mode 100644 index 00000000000..044b51be9e9 --- /dev/null +++ b/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/java-lang-bi-ref/src/JavaRecord.java @@ -0,0 +1,5 @@ +public record JavaRecord(String name) { + public void useXbaseType(XbaseReferToJava xbaseType) throws Throwable { + xbaseType.myMethod(); + } +} diff --git a/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/java-lang-bi-ref/src/XbaseReferToJava.xbase b/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/java-lang-bi-ref/src/XbaseReferToJava.xbase index 23d98f7cfb6..b35c73b9212 100644 --- a/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/java-lang-bi-ref/src/XbaseReferToJava.xbase +++ b/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/java-lang-bi-ref/src/XbaseReferToJava.xbase @@ -1,2 +1,4 @@ val JavaClazz jc = null +val JavaRecord jr = new JavaRecord("test") +val name = jr.name() jc.useXbaseType(this) diff --git a/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF b/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF index 2074a3617f8..842f34f2931 100644 --- a/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF @@ -16,8 +16,7 @@ Require-Bundle: org.eclipse.xtext.xbase;bundle-version="2.38.0", org.eclipse.core.runtime;bundle-version="3.31.0", org.eclipse.xtext.xbase.testdata;bundle-version="2.38.0", org.eclipse.xtext.xbase.ide;bundle-version="2.38.0", - org.junit;bundle-version="4.13.2", - org.eclipse.draw2d + org.junit;bundle-version="4.13.2" Bundle-Vendor: Eclipse Xtext Export-Package: org.eclipse.xtext.xbase.tests;version="2.38.0", org.eclipse.xtext.xbase.tests.interpreter;version="2.38.0" diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Java21RecordCompilerTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Java21RecordCompilerTest.java index 7337c5a4869..f9963938f6b 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Java21RecordCompilerTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Java21RecordCompilerTest.java @@ -9,11 +9,9 @@ package org.eclipse.xtext.xbase.tests.compiler; import org.eclipse.xtext.testing.TemporaryFolder; -import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.util.Strings; import org.eclipse.xtext.xbase.testing.CompilationTestHelper; import org.eclipse.xtext.xbase.tests.jvmmodel.AbstractJvmModelTest; -import org.junit.Assume; import org.junit.Rule; import org.junit.Test; @@ -30,30 +28,24 @@ public class Java21RecordCompilerTest extends AbstractJvmModelTest { @Inject private CompilationTestHelper compilationTestHelper; - /** - * Since there's no record in the JDK and adding a Java source with a record in this - * project would require Java 21 compilation level, I'm using a known record from - * draw2d, which is in our target platform. - */ @Test public void testUseJavaRecord() throws Exception { - Assume.assumeTrue("Active only on Java 21 and later", JavaRuntimeVersion.isJava21OrLater()); String source = "{\n" - + " var interval = new org.eclipse.draw2d.geometry.Interval(0, 10);\n" + + " var interval = new test.RecordWithFields(0, 10);\n" + " var int begin = interval.begin\n" + " var end = interval.end()\n" + " interval.toString" + "}"; compilationTestHelper.compile(source, it -> { String expectation = - "import org.eclipse.draw2d.geometry.Interval;\n" + "import test.RecordWithFields;\n" + "\n" + "@SuppressWarnings(\"all\")\n" + "public class Test {\n" + " public String doStuff(final String s) {\n" + " String _xblockexpression = null;\n" + " {\n" - + " Interval interval = new Interval(0, 10);\n" + + " RecordWithFields interval = new RecordWithFields(0, 10);\n" + " int begin = interval.begin();\n" + " int end = interval.end();\n" + " _xblockexpression = interval.toString();\n" diff --git a/org.eclipse.xtext.xbase.tests/testdata/test/RecordWithFields.java b/org.eclipse.xtext.xbase.tests/testdata/test/RecordWithFields.java new file mode 100644 index 00000000000..60d2f16a422 --- /dev/null +++ b/org.eclipse.xtext.xbase.tests/testdata/test/RecordWithFields.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * 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 test; + +/** + * @author Lorenzo Bettini - Initial contribution and API + */ +public record RecordWithFields(int begin, int end) { + +}