Skip to content

Commit

Permalink
[24] Allow JDT to target Java 24 in compiler preferences
Browse files Browse the repository at this point in the history
Fixes #1695
  • Loading branch information
noopur2507 committed Oct 14, 2024
1 parent 102d06a commit 07dfd87
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, [email protected] - 89977 Make JDT .java agnostic
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 <code>null</code> to test the workspace settings
* @return <code>true</code> 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);
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 07dfd87

Please sign in to comment.