From bef035c834dacefbb2a53d53b52ce86c5f7d6922 Mon Sep 17 00:00:00 2001 From: Noopur Gupta Date: Tue, 23 Apr 2024 11:41:49 +0530 Subject: [PATCH] [23] Allow JDT to target Java 23 in compiler preferences Fixes https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1349 --- .../internal/corext/util/JavaModelUtil.java | 27 +++++++++++++-- .../ComplianceConfigurationBlock.java | 34 ++++++++++++------- .../ui/preferences/PreferencesMessages.java | 5 +++ .../PreferencesMessages.properties | 5 +++ 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java index 7f4619e7bf9..95ebb893598 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation * Matt Chapman, mpchapman@gmail.com - 89977 Make JDT .java agnostic @@ -78,7 +82,7 @@ public final class JavaModelUtil { */ public static final String VERSION_LATEST; static { - VERSION_LATEST= JavaCore.VERSION_22; // make sure it is not inlined + VERSION_LATEST= JavaCore.VERSION_23; // make sure it is not inlined } public static final int VALIDATE_EDIT_CHANGED_CONTENT= 10003; @@ -868,6 +872,10 @@ public static boolean is22OrHigher(String compliance) { return !isVersionLessThan(compliance, JavaCore.VERSION_22); } + public static boolean is23OrHigher(String compliance) { + return !isVersionLessThan(compliance, JavaCore.VERSION_23); + } + /** * Checks if the given project or workspace has source compliance 1.2 or greater. * @@ -1063,6 +1071,17 @@ public static boolean is22OrHigher(IJavaProject project) { return is22OrHigher(getSourceCompliance(project)); } + /** + * Checks if the given project or workspace has source compliance 23 or greater. + * + * @param project the project to test or null to test the workspace settings + * @return true if the given project or workspace has source compliance 23 or + * greater. + */ + public static boolean is23OrHigher(IJavaProject project) { + return is23OrHigher(getSourceCompliance(project)); + } + public static String getSourceCompliance(IJavaProject project) { return project != null ? project.getOption(JavaCore.COMPILER_SOURCE, true) : JavaCore.getOption(JavaCore.COMPILER_SOURCE); } @@ -1113,6 +1132,8 @@ public static String getCompilerCompliance(IVMInstall2 vMInstall, String default String version= vMInstall.getJavaVersion(); if (version == null) { return defaultCompliance; + } else if (version.startsWith(JavaCore.VERSION_23)) { + return JavaCore.VERSION_23; } else if (version.startsWith(JavaCore.VERSION_22)) { return JavaCore.VERSION_22; } else if (version.startsWith(JavaCore.VERSION_21)) { @@ -1169,7 +1190,9 @@ public static String getExecutionEnvironmentCompliance(IExecutionEnvironment exe // fallback: String desc= executionEnvironment.getId(); - if (desc.indexOf(JavaCore.VERSION_22) != -1) { + if (desc.indexOf(JavaCore.VERSION_23) != -1) { + return JavaCore.VERSION_23; + } else if (desc.indexOf(JavaCore.VERSION_22) != -1) { return JavaCore.VERSION_22; } else if (desc.indexOf(JavaCore.VERSION_21) != -1) { return JavaCore.VERSION_21; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java index 062a3fd81be..be44640aeea 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation * Jesper S Møller - Bug 529432 - Allow JDT UI to target Java 10 @@ -157,6 +161,7 @@ public class ComplianceConfigurationBlock extends OptionsConfigurationBlock { private static final String VERSION_20 = JavaCore.VERSION_20; private static final String VERSION_21 = JavaCore.VERSION_21; private static final String VERSION_22 = JavaCore.VERSION_22; + private static final String VERSION_23 = JavaCore.VERSION_23; private static final String VERSION_LATEST = JavaCore.latestSupportedJavaVersion(); private static final String VERSION_JSR14= "jsr14"; //$NON-NLS-1$ @@ -314,7 +319,7 @@ public void enablePreferenceContent(boolean enable) { private Composite createComplianceTabContent(Composite folder) { final String[] complianceVersions= new String[] { VERSION_1_3, VERSION_1_4, - VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13, VERSION_14, VERSION_15, VERSION_16, VERSION_17, VERSION_18, VERSION_19, VERSION_20, VERSION_21, VERSION_22 }; + VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13, VERSION_14, VERSION_15, VERSION_16, VERSION_17, VERSION_18, VERSION_19, VERSION_20, VERSION_21, VERSION_22, VERSION_23 }; final String[] complianceLabels= new String[] { PreferencesMessages.ComplianceConfigurationBlock_version13, PreferencesMessages.ComplianceConfigurationBlock_version14, @@ -335,11 +340,12 @@ private Composite createComplianceTabContent(Composite folder) { PreferencesMessages.ComplianceConfigurationBlock_version_19, PreferencesMessages.ComplianceConfigurationBlock_version_20, PreferencesMessages.ComplianceConfigurationBlock_version_21, - PreferencesMessages.ComplianceConfigurationBlock_version_22 + PreferencesMessages.ComplianceConfigurationBlock_version_22, + PreferencesMessages.ComplianceConfigurationBlock_version_23 }; String[] targetVersions= new String[] { VERSION_CLDC_1_1, VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4, - VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13, VERSION_14, VERSION_15, VERSION_16, VERSION_17, VERSION_18, VERSION_19, VERSION_20, VERSION_21, VERSION_22 }; + VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13, VERSION_14, VERSION_15, VERSION_16, VERSION_17, VERSION_18, VERSION_19, VERSION_20, VERSION_21, VERSION_22, VERSION_23 }; String[] targetLabels= new String[] { PreferencesMessages.ComplianceConfigurationBlock_versionCLDC11, PreferencesMessages.ComplianceConfigurationBlock_version11, @@ -363,7 +369,8 @@ private Composite createComplianceTabContent(Composite folder) { PreferencesMessages.ComplianceConfigurationBlock_version_19, PreferencesMessages.ComplianceConfigurationBlock_version_20, PreferencesMessages.ComplianceConfigurationBlock_version_21, - PreferencesMessages.ComplianceConfigurationBlock_version_22 + PreferencesMessages.ComplianceConfigurationBlock_version_22, + PreferencesMessages.ComplianceConfigurationBlock_version_23 }; if (ComplianceConfigurationBlock.VERSION_JSR14.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) { @@ -372,7 +379,7 @@ private Composite createComplianceTabContent(Composite folder) { } String[] sourceVersions= new String[] { VERSION_1_3, VERSION_1_4, - VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13, VERSION_14, VERSION_15, VERSION_16, VERSION_17, VERSION_18, VERSION_19, VERSION_20, VERSION_21, VERSION_22 }; + VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13, VERSION_14, VERSION_15, VERSION_16, VERSION_17, VERSION_18, VERSION_19, VERSION_20, VERSION_21, VERSION_22, VERSION_23 }; String[] sourceLabels= new String[] { PreferencesMessages.ComplianceConfigurationBlock_version13, PreferencesMessages.ComplianceConfigurationBlock_version14, @@ -393,7 +400,8 @@ private Composite createComplianceTabContent(Composite folder) { PreferencesMessages.ComplianceConfigurationBlock_version_19, PreferencesMessages.ComplianceConfigurationBlock_version_20, PreferencesMessages.ComplianceConfigurationBlock_version_21, - PreferencesMessages.ComplianceConfigurationBlock_version_22 + PreferencesMessages.ComplianceConfigurationBlock_version_22, + PreferencesMessages.ComplianceConfigurationBlock_version_23 }; final ScrolledPageContent sc1 = new ScrolledPageContent(folder); @@ -853,13 +861,13 @@ private void validateComplianceStatus() { } } - //TODO: Comment once Java SE 22 has been shipped: -// String selectedCompliance= getValue(PREF_COMPLIANCE); -// if (VERSION_22.equals(selectedCompliance)) { -// fJRE50InfoText.setText( -// "This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP."); //$NON-NLS-1$ -// isVisible= true; -// } +// TODO: Comment once Java SE 23 has been shipped: + String selectedCompliance= getValue(PREF_COMPLIANCE); + if (VERSION_23.equals(selectedCompliance)) { + fJRE50InfoText.setText( + "This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP."); //$NON-NLS-1$ + isVisible= true; + } fJRE50InfoText.setVisible(isVisible); fJRE50InfoImage.setImage(isVisible ? image : null); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java index c8d1cfe0c78..2db60f385d8 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation * John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class @@ -865,6 +869,7 @@ private PreferencesMessages() { public static String ComplianceConfigurationBlock_version_20; public static String ComplianceConfigurationBlock_version_21; public static String ComplianceConfigurationBlock_version_22; + public static String ComplianceConfigurationBlock_version_23; public static String ComplianceConfigurationBlock_versionCLDC11; public static String ComplianceConfigurationBlock_src_greater_compliance; public static String ComplianceConfigurationBlock_classfile_greater_compliance; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties index 3ba3c5805cd..a8e0a7a900c 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties @@ -8,6 +8,10 @@ # # SPDX-License-Identifier: EPL-2.0 # +# This is an implementation of an early-draft specification developed under the Java +# Community Process (JCP) and is made available for testing and evaluation purposes +# only. The code is not compatible with any specification of the JCP. +# # Contributors: # IBM Corporation - initial API and implementation # John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class @@ -618,6 +622,7 @@ ComplianceConfigurationBlock_version_19=19 ComplianceConfigurationBlock_version_20=20 ComplianceConfigurationBlock_version_21=21 ComplianceConfigurationBlock_version_22=22 +ComplianceConfigurationBlock_version_23=23 (BETA) ComplianceConfigurationBlock_versionCLDC11=CLDC 1.1 ComplianceConfigurationBlock_needsbuild_title=Compiler Settings Changed