Skip to content

Commit

Permalink
[23] Allow JDT to target Java 23 in compiler preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
noopur2507 authored and akurtakov committed Apr 30, 2024
1 parent 8f39c29 commit c061925
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 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, mpchapman@gmail.com - 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_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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 <code>null</code> to test the workspace settings
* @return <code>true</code> 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);
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
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 @@ -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$

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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))) {
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);
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
* John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class
Expand Down Expand Up @@ -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;
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
# John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c061925

Please sign in to comment.