Skip to content

Commit

Permalink
use source Java record in xbase.tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Nov 28, 2024
1 parent 5cf598e commit ba5287f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
3 changes: 1 addition & 2 deletions org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions org.eclipse.xtext.xbase.tests/testdata/test/RecordWithFields.java
Original file line number Diff line number Diff line change
@@ -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) {

}

0 comments on commit ba5287f

Please sign in to comment.