Skip to content

Commit

Permalink
Add Java 16 Support.
Browse files Browse the repository at this point in the history
- This reverts commit 958ec96.
- Use Eclipse 2021-06 M1 Release for the Java 16 support
- Update Tycho to 2.3.0 to avoid resolution issue

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
  • Loading branch information
rgrunber committed Apr 19, 2021
1 parent 82385b3 commit 3ef5826
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 24 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.xtend.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.xtext.sdk.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/releases/2021-03/202103171000/"/>
<repository location="https://download.eclipse.org/releases/2021-06/202104161000/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.jboss.tools.maven.apt.core" version="0.0.0"/>
Expand Down
Binary file added org.eclipse.jdt.ls.tests/fakejdk/16/rtstubs.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions org.eclipse.jdt.ls.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<version>0.0.0</version>
<type>eclipse-feature</type>
</dependency>
<dependency>
<artifactId>org.eclipse.jdt.java16patch</artifactId>
<version>0.0.0</version>
<type>eclipse-feature</type>
</dependency>
</dependencies>
</configuration>
</plugin>
Expand Down
10 changes: 10 additions & 0 deletions org.eclipse.jdt.ls.tests/projects/eclipse/java16/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
17 changes: 17 additions & 0 deletions org.eclipse.jdt.ls.tests/projects/eclipse/java16/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java16</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=16
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=16
org.eclipse.jdt.core.compiler.release=enabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package foo.bar;

/**
* It's a Foo class
*/
public sealed interface Foo
permits Bar {
}
record Bar(String name) implements Foo { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.sample;

public class Test {
}
27 changes: 27 additions & 0 deletions org.eclipse.jdt.ls.tests/projects/maven/salut-java16/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions org.eclipse.jdt.ls.tests/projects/maven/salut-java16/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>salut-java16</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
org.eclipse.jdt.core.compiler.compliance=16
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=16
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
26 changes: 26 additions & 0 deletions org.eclipse.jdt.ls.tests/projects/maven/salut-java16/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>salut-java16</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
<compilerArgument>--enable-preview</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sample;

/**
* This is Bar
*/
public class Bar {

public static void main(String[] args) {
Object foo = "x";
if (foo instanceof String str) {
System.out.println(str);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1211,11 +1211,11 @@ public void testClassExtendFinalClass() throws Exception {

@Test
public void testAddSealedMissingClassModifierProposal() throws Exception {
Map<String, String> options15 = new HashMap<>();
JavaModelUtil.setComplianceOptions(options15, JavaCore.VERSION_15);
options15.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
options15.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
fJProject.setOptions(options15);
Map<String, String> options16 = new HashMap<>();
JavaModelUtil.setComplianceOptions(options16, JavaCore.VERSION_16);
options16.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
options16.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
fJProject.setOptions(options16);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
assertNoErrors(fJProject.getResource());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,11 +1405,11 @@ public void testDontImportTestClassesInMainCode() throws Exception {

@Test
public void testTypeInSealedTypeDeclaration() throws Exception {
Map<String, String> options15 = new HashMap<>();
JavaModelUtil.setComplianceOptions(options15, JavaCore.VERSION_15);
options15.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
options15.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
fJProject1.setOptions(options15);
Map<String, String> options16 = new HashMap<>();
JavaModelUtil.setComplianceOptions(options16, JavaCore.VERSION_16);
options16.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
options16.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
fJProject1.setOptions(options16);

IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,9 @@ public void testCompletion_javadocCommentNoParam() throws JavaModelException {

@Test
public void testCompletion_javadocCommentRecord() throws Exception {
importProjects("eclipse/java14");
IProject proj = WorkspaceHelper.getProject("java14");
importProjects("eclipse/java16");
IProject proj = WorkspaceHelper.getProject("java16");
IJavaProject javaProject = JavaCore.create(proj);
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
ICompilationUnit unit = null;
try {
unit = (ICompilationUnit) javaProject.findElement(new Path("foo/bar/Foo.java"));
Expand Down Expand Up @@ -517,11 +515,9 @@ public void testCompletion_javadocCommentRecordNoSnippet() throws Exception {
ClientPreferences mockCapabilies = Mockito.mock(ClientPreferences.class);
Mockito.when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
Mockito.when(mockCapabilies.isCompletionSnippetsSupported()).thenReturn(false);
importProjects("eclipse/java14");
IProject proj = WorkspaceHelper.getProject("java14");
importProjects("eclipse/java16");
IProject proj = WorkspaceHelper.getProject("java16");
IJavaProject javaProject = JavaCore.create(proj);
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
ICompilationUnit unit = null;
try {
unit = (ICompilationUnit) javaProject.findElement(new Path("foo/bar/Foo.java"));
Expand Down Expand Up @@ -1475,7 +1471,7 @@ public void testSnippet_record() throws Exception {
assertFalse(items.isEmpty());
items.sort((i1, i2) -> (i1.getSortText().compareTo(i2.getSortText())));

CompletionItem item = items.get(11);
CompletionItem item = items.get(12);
assertEquals("record", item.getLabel());
String te = item.getInsertText();
assertEquals("package org.sample;\n\n/**\n * Test\n */\npublic record Test(${0}) {\n}", ResourceUtils.dos2Unix(te));
Expand All @@ -1497,7 +1493,7 @@ public void testSnippet_record_with_package() throws Exception {
assertFalse(items.isEmpty());
items.sort((i1, i2) -> (i1.getSortText().compareTo(i2.getSortText())));

CompletionItem item = items.get(10);
CompletionItem item = items.get(11);
assertEquals("record", item.getLabel());
String te = item.getInsertText();
assertEquals("/**\n * Test\n */\npublic record Test(${0}) {\n}", te);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private IProject mockProject(IWorkspaceRoot root, String name, boolean exists) {

@Test
public void testPreviewFeaturesDisabledByDefault() throws Exception {
String name = "java15";
String name = "java16";
importProjects("eclipse/" + name);
IProject project = getProject(name);
assertIsJavaProject(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void getPackageName() throws Exception {
public void testPreviewFeaturesEnabledByDefault() throws Exception {
String defaultJVM = JavaRuntime.getDefaultVMInstall().getId();
try {
TestVMType.setTestJREAsDefault("15");
TestVMType.setTestJREAsDefault("16");
IProject invisibleProject = copyAndImportFolder("singlefile/java14", "foo/bar/Foo.java");
assertTrue(invisibleProject.exists());
assertNoErrors(invisibleProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ public void testJava15Project() throws Exception {
IJavaProject javaProject = JavaCore.create(project);
assertEquals(JavaCore.ENABLED, javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, false));
assertEquals(JavaCore.IGNORE, javaProject.getOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, false));
assertHasErrors(project, "Preview features enabled at an invalid source release level");
}

@Test
public void testJava16Project() throws Exception {
IProject project = importMavenProject("salut-java16");
assertIsJavaProject(project);
assertEquals("16", getJavaSourceLevel(project));
IJavaProject javaProject = JavaCore.create(project);
assertEquals(JavaCore.ENABLED, javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, false));
assertEquals(JavaCore.IGNORE, javaProject.getOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, false));
assertNoErrors(project);
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<properties>
<base.name>JDT Language Server</base.name>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tycho-version>2.0.0</tycho-version>
<tycho-version>2.3.0</tycho-version>
<tycho-extras-version>${tycho-version}</tycho-extras-version>
<tycho.scmUrl>scm:git:https://github.com/eclipse/eclipse.jdt.ls.git</tycho.scmUrl>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
Expand Down

0 comments on commit 3ef5826

Please sign in to comment.