Skip to content

Commit

Permalink
Deal with unsupported target options in compiler preferences
Browse files Browse the repository at this point in the history
After we dropped support of Java < 1.8 compliance level, we still have
to deal with projects that have these setting stored in preferences.

- Make sure we don't allow use unsupported compliance from JRE < 1.8
- Make sure we update value of compliance/source and target to first
supported version

See eclipse-jdt#1465
  • Loading branch information
iloveeclipse committed Aug 7, 2024
1 parent c48f110 commit 5b71a86
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,27 @@ private IStatus validateCompliance() {
String source= getValue(PREF_SOURCE_COMPATIBILITY);
String target= getValue(PREF_CODEGEN_TARGET_PLATFORM);

String firstSupported = JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first();

// compliance must be supported
if (JavaModelUtil.isVersionLessThan(compliance, firstSupported)) {
String warning = Messages.format(PreferencesMessages.ComplianceConfigurationBlock_unsupported_compliance, new String[] { firstSupported });
setValue(PREF_COMPLIANCE, firstSupported);
status.setWarning(warning);
}
// source must be supported
if (JavaModelUtil.isVersionLessThan(source, firstSupported)) {
String warning = Messages.format(PreferencesMessages.ComplianceConfigurationBlock_unsupported_source, new String[] { firstSupported });
setValue(PREF_SOURCE_COMPATIBILITY, firstSupported);
status.setWarning(warning);
}
// target must be supported
if (JavaModelUtil.isVersionLessThan(target, firstSupported)) {
String warning = Messages.format(PreferencesMessages.ComplianceConfigurationBlock_unsupported_target, new String[] { firstSupported });
setValue(PREF_CODEGEN_TARGET_PLATFORM, firstSupported);
status.setWarning(warning);
}

// compliance must not be smaller than source or target
if (JavaModelUtil.isVersionLessThan(compliance, source)) {
status.setError(PreferencesMessages.ComplianceConfigurationBlock_src_greater_compliance);
Expand Down Expand Up @@ -1158,7 +1179,9 @@ private String getComplianceFollowsEE(IExecutionEnvironment ee) {
if (options == null)
return DISABLED;
String complianceOption= options.get(JavaCore.COMPILER_COMPLIANCE);
if (JavaCore.compareJavaVersions(complianceOption, JavaCore.VERSION_10) > 0) {
if (JavaCore.compareJavaVersions(complianceOption, JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first()) < 0) {
return DISABLED;
} else if (JavaCore.compareJavaVersions(complianceOption, JavaCore.VERSION_10) > 0) {
return checkDefaults(PREFS_COMPLIANCE_11_OR_HIGHER, options);
} else {
return checkDefaults(PREFS_COMPLIANCE, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ private PreferencesMessages() {
public static String ComplianceConfigurationBlock_compliance_follows_EE_with_EE_label;
public static String ComplianceConfigurationBlock_compliance_group_label;
public static String ComplianceConfigurationBlock_classfiles_group_label;
public static String ComplianceConfigurationBlock_unsupported_compliance;
public static String ComplianceConfigurationBlock_unsupported_source;
public static String ComplianceConfigurationBlock_unsupported_target;
public static String CodeStylePreferencePage_title;
public static String CodeTemplatesPreferencePage_title;
public static String NameConventionConfigurationBlock_field_label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ ComplianceConfigurationBlock_compliance_group_label=JDK Compliance
ComplianceConfigurationBlock_classfiles_group_label=Classfile Generation
ComplianceConfigurationBlock_classfile_greater_compliance=Classfile compatibility must be equal or less than compliance level.
ComplianceConfigurationBlock_classfile_greater_source=Classfile compatibility must be equal or greater than source compatibility.
ComplianceConfigurationBlock_unsupported_compliance=Compliance level was changed to minimal supported {0}.
ComplianceConfigurationBlock_unsupported_source=Source level was changed to minimal supported {0}.
ComplianceConfigurationBlock_unsupported_target=Target level was changed to minimal supported {0}.

ComplianceConfigurationBlock_jrecompliance_info=When selecting {0} compliance, make sure to have a compatible JRE installed and activated (currently {1}). <a href="1" >Configure...</a>
ComplianceConfigurationBlock_jrecompliance_info_project=When selecting {0} compliance, make sure to have a compatible JRE installed and activated (currently {1}). Configure the <a href="1" >''Installed JREs''</a> and <a href="2" >''Execution Environments''</a>, or change the JRE on the <a href="3" >''Java Build Path''</a>.
Expand Down

0 comments on commit 5b71a86

Please sign in to comment.