diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ReorgCorrectionsSubProcessor.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ReorgCorrectionsSubProcessor.java
index db29c9bbdd..c3d991e537 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ReorgCorrectionsSubProcessor.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ReorgCorrectionsSubProcessor.java
@@ -31,9 +31,7 @@
import org.eclipse.jdt.internal.corext.fix.UnusedCodeFixCore;
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange;
import org.eclipse.jdt.internal.corext.util.Messages;
-import org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUp;
-import org.eclipse.jdt.ui.text.java.IInvocationContext;
-import org.eclipse.jdt.ui.text.java.IProblemLocation;
+import org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUpCore;
import org.eclipse.jdt.internal.ui.text.correction.IProposalRelevance;
import org.eclipse.jdt.internal.ui.text.correction.ReorgCorrectionsBaseSubProcessor;
import org.eclipse.jdt.internal.ui.text.correction.UnresolvedElementsBaseSubProcessor;
@@ -43,6 +41,8 @@
import org.eclipse.jdt.ls.core.internal.corrections.CorrectionMessages;
import org.eclipse.jdt.ls.core.internal.corrections.ProposalKindWrapper;
import org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler;
+import org.eclipse.jdt.ui.text.java.IInvocationContext;
+import org.eclipse.jdt.ui.text.java.IProblemLocation;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
@@ -128,7 +128,7 @@ public void addRemoveImportStatementProposals(IInvocationContext context, IProbl
* @see org.eclipse.jdt.internal.ui.text.correction.ReorgCorrectionsBaseSubProcessor#createRemoveUnusedImportProposal(org.eclipse.jdt.internal.corext.fix.IProposableFix, org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUp, int, org.eclipse.jdt.ui.text.java.IInvocationContext)
*/
@Override
- protected ProposalKindWrapper createRemoveUnusedImportProposal(IProposableFix fix, UnusedCodeCleanUp unusedCodeCleanUp, int relevance, IInvocationContext context) {
+ protected ProposalKindWrapper createRemoveUnusedImportProposal(IProposableFix fix, UnusedCodeCleanUpCore unusedCodeCleanUp, int relevance, IInvocationContext context) {
if (fix != null) {
try {
CompilationUnitChange change = fix.createChange(null);
diff --git a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
index a5b8820ddb..1edbe0fd47 100644
--- a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
+++ b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
@@ -25,13 +25,13 @@
-
+
-
+
diff --git a/org.eclipse.jdt.ls.tests/fakejdk/22/rtstubs.jar b/org.eclipse.jdt.ls.tests/fakejdk/22/rtstubs.jar
new file mode 100644
index 0000000000..fb6cb93825
Binary files /dev/null and b/org.eclipse.jdt.ls.tests/fakejdk/22/rtstubs.jar differ
diff --git a/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.classpath b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.classpath
new file mode 100644
index 0000000000..85c4985e82
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.project b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.project
new file mode 100644
index 0000000000..6ff1922ca2
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.project
@@ -0,0 +1,17 @@
+
+
+ java22
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..e8812d9617
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,16 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=22
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=22
+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.enablePreviewFeatures=enabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=22
+
diff --git a/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/UnnamedWithString.java b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/UnnamedWithString.java
new file mode 100644
index 0000000000..8f14cf779f
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/UnnamedWithString.java
@@ -0,0 +1,7 @@
+String foo() {
+ return "foo";
+}
+
+void main() {
+ System.out.println(foo());
+}
diff --git a/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/foo/bar/Foo.java b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/foo/bar/Foo.java
new file mode 100644
index 0000000000..78e1dfd0e3
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/foo/bar/Foo.java
@@ -0,0 +1,9 @@
+package foo.bar;
+
+/**
+ * It's a Foo class
+ */
+public sealed interface Foo
+permits Bar {
+}
+record Bar(String name) implements Foo { }
diff --git a/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/org/sample/Test.java b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/org/sample/Test.java
new file mode 100644
index 0000000000..aca1a4ec7e
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/eclipse/java22/src/main/java/org/sample/Test.java
@@ -0,0 +1,4 @@
+package org.sample;
+
+public class Test {
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.classpath b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.classpath
new file mode 100644
index 0000000000..1d7640411c
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.classpath
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.project b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.project
new file mode 100644
index 0000000000..4305a9050e
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.project
@@ -0,0 +1,23 @@
+
+
+ salut-java22
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..091155e9e5
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,17 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=22
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=22
+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.enablePreviewFeatures=enabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=22
+
+
diff --git a/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.settings/org.eclipse.m2e.core.prefs b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000000..f897a7f1cb
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/pom.xml b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/pom.xml
new file mode 100644
index 0000000000..5f879e3c09
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/pom.xml
@@ -0,0 +1,26 @@
+
+ 4.0.0
+ foo.bar
+ salut-java22
+ 0.0.1-SNAPSHOT
+
+
+
+ maven-compiler-plugin
+ 3.8.1
+
+ 22
+ --enable-preview
+
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.5
+
+
+
diff --git a/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/src/main/java/org/sample/Bar.java b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/src/main/java/org/sample/Bar.java
new file mode 100644
index 0000000000..c8839a8886
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/projects/maven/salut-java22/src/main/java/org/sample/Bar.java
@@ -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);
+ }
+ }
+}
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/ModifierCorrectionsQuickFixTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/ModifierCorrectionsQuickFixTest.java
index ace9c2fdf1..cdbc15a37c 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/ModifierCorrectionsQuickFixTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/ModifierCorrectionsQuickFixTest.java
@@ -1203,11 +1203,11 @@ public void testClassExtendFinalClass() throws Exception {
@Test
public void testAddSealedMissingClassModifierProposal() throws Exception {
- Map options21 = new HashMap<>();
- JavaModelUtil.setComplianceOptions(options21, JavaCore.VERSION_21);
- options21.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- options21.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- fJProject.setOptions(options21);
+ Map options22 = new HashMap<>();
+ JavaModelUtil.setComplianceOptions(options22, JavaCore.VERSION_22);
+ options22.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ options22.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ fJProject.setOptions(options22);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
assertNoErrors(fJProject.getResource());
@@ -1250,11 +1250,11 @@ public void testAddSealedMissingClassModifierProposal() throws Exception {
@Test
public void testAddSealedAsDirectSuperClass() throws Exception {
- Map options21 = new HashMap<>();
- JavaModelUtil.setComplianceOptions(options21, JavaCore.VERSION_21);
- options21.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- options21.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- fJProject.setOptions(options21);
+ Map options22 = new HashMap<>();
+ JavaModelUtil.setComplianceOptions(options22, JavaCore.VERSION_22);
+ options22.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ options22.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ fJProject.setOptions(options22);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
assertNoErrors(fJProject.getResource());
@@ -1279,11 +1279,11 @@ public void testAddSealedAsDirectSuperClass() throws Exception {
@Test
public void testAddPermitsToDirectSuperClass() throws Exception {
- Map options21 = new HashMap<>();
- JavaModelUtil.setComplianceOptions(options21, JavaCore.VERSION_21);
- options21.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- options21.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- fJProject.setOptions(options21);
+ Map options22 = new HashMap<>();
+ JavaModelUtil.setComplianceOptions(options22, JavaCore.VERSION_22);
+ options22.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ options22.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ fJProject.setOptions(options22);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
assertNoErrors(fJProject.getResource());
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/UnresolvedTypesQuickFixTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/UnresolvedTypesQuickFixTest.java
index 58a62a516a..0a3f58051c 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/UnresolvedTypesQuickFixTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/UnresolvedTypesQuickFixTest.java
@@ -1492,11 +1492,11 @@ public void testDontImportTestClassesInMainCode() throws Exception {
@Test
public void testTypeInSealedTypeDeclaration() throws Exception {
- Map options21 = new HashMap<>();
- JavaModelUtil.setComplianceOptions(options21, JavaCore.VERSION_21);
- options21.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- options21.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- fJProject1.setOptions(options21);
+ Map options22 = new HashMap<>();
+ JavaModelUtil.setComplianceOptions(options22, JavaCore.VERSION_22);
+ options22.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ options22.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ fJProject1.setOptions(options22);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java
index 290f5ac620..d801822f27 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java
@@ -191,7 +191,7 @@ public void testPreviewFeatures16() throws Exception {
@Test
public void testPreviewFeaturesDisabledByDefault() throws Exception {
- String name = "java21";
+ String name = "java22";
importProjects("eclipse/" + name);
IProject project = getProject(name);
assertIsJavaProject(project);
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java
index 8afc281f28..f78784f26e 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java
@@ -204,7 +204,7 @@ public void getPackageName() throws Exception {
public void testPreviewFeaturesEnabledByDefault() throws Exception {
String defaultJVM = JavaRuntime.getDefaultVMInstall().getId();
try {
- TestVMType.setTestJREAsDefault("21");
+ TestVMType.setTestJREAsDefault("22");
IProject invisibleProject = copyAndImportFolder("singlefile/java14", "foo/bar/Foo.java");
assertTrue(invisibleProject.exists());
assertNoErrors(invisibleProject);
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java
index 5ddc1d6a71..9e2483046d 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java
@@ -359,6 +359,17 @@ public void testJava21Project() 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 testJava22Project() throws Exception {
+ IProject project = importMavenProject("salut-java22");
+ assertIsJavaProject(project);
+ assertEquals("22", 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);
}