From 07dfd879142cb084675db08fa4614f185133de4b Mon Sep 17 00:00:00 2001 From: Noopur Gupta Date: Mon, 14 Oct 2024 11:56:11 +0530 Subject: [PATCH] [24] Allow JDT to target Java 24 in compiler preferences Fixes https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1695 --- .../internal/corext/util/JavaModelUtil.java | 27 +++++++++++++++++-- .../ComplianceConfigurationBlock.java | 8 +++--- 2 files changed, 30 insertions(+), 5 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 fcd591f6f0e..c8eccf6ea08 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_23; // make sure it is not inlined + VERSION_LATEST= JavaCore.VERSION_24; // make sure it is not inlined } public static final int VALIDATE_EDIT_CHANGED_CONTENT= 10003; @@ -874,6 +878,10 @@ public static boolean is23OrHigher(String compliance) { return !isVersionLessThan(compliance, JavaCore.VERSION_23); } + public static boolean is24OrHigher(String compliance) { + return !isVersionLessThan(compliance, JavaCore.VERSION_24); + } + /** * Checks if the given project or workspace has source compliance 1.2 or greater. * @@ -1080,6 +1088,17 @@ public static boolean is23OrHigher(IJavaProject project) { return is23OrHigher(getSourceCompliance(project)); } + /** + * Checks if the given project or workspace has source compliance 24 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 24 or + * greater. + */ + public static boolean is24OrHigher(IJavaProject project) { + return is24OrHigher(getSourceCompliance(project)); + } + public static String getSourceCompliance(IJavaProject project) { return project != null ? project.getOption(JavaCore.COMPILER_SOURCE, true) : JavaCore.getOption(JavaCore.COMPILER_SOURCE); } @@ -1130,6 +1149,8 @@ public static String getCompilerCompliance(IVMInstall2 vMInstall, String default String version= vMInstall.getJavaVersion(); if (version == null) { return defaultCompliance; + } else if (version.startsWith(JavaCore.VERSION_24)) { + return JavaCore.VERSION_24; } else if (version.startsWith(JavaCore.VERSION_23)) { return JavaCore.VERSION_23; } else if (version.startsWith(JavaCore.VERSION_22)) { @@ -1180,7 +1201,9 @@ public static String getExecutionEnvironmentCompliance(IExecutionEnvironment exe // fallback: String desc= executionEnvironment.getId(); - if (desc.indexOf(JavaCore.VERSION_23) != -1) { + if (desc.indexOf(JavaCore.VERSION_24) != -1) { + return JavaCore.VERSION_24; + } else if (desc.indexOf(JavaCore.VERSION_23) != -1) { return JavaCore.VERSION_23; } else if (desc.indexOf(JavaCore.VERSION_22) != -1) { return JavaCore.VERSION_22; 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 a34d6b97d0f..1e8c7b04f61 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 @@ -701,10 +705,8 @@ private void validateComplianceStatus() { } } - @SuppressWarnings("unused") protected boolean isBetaVersion(String compliance) { - return false; -// return JavaCore.VERSION_23.equals(compliance); + return JavaCore.VERSION_24.equals(compliance); } private String addsExportToSystemModule() {