public ComplianceConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { super(context, project, getKeys(), container); fBlockEnableState= null; fComplianceControls= new ArrayList(); fComplianceStatus= new StatusInfo(); fRememberedUserCompliance= new String[] { // caution: order depends on IDX_* constants getValue(PREF_PB_ASSERT_AS_IDENTIFIER), getValue(PREF_PB_ENUM_AS_IDENTIFIER), getValue(PREF_SOURCE_COMPATIBILITY), getValue(PREF_CODEGEN_TARGET_PLATFORM), getValue(PREF_COMPLIANCE), getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE), }; }
public ComplianceConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { super(context, project, getKeys(project != null), container); setDefaultCompilerComplianceValues(); fBlockEnableState= null; fComplianceFollowsEEControls= new ArrayList<>(); fComplianceControls= new ArrayList<>(); fComplianceChildControls= new ArrayList<>(); fComplianceStatus= new StatusInfo(); fRememberedUserCompliance= new String[] { // caution: order depends on IDX_* constants getValue(PREF_PB_ASSERT_AS_IDENTIFIER), getValue(PREF_PB_ENUM_AS_IDENTIFIER), getValue(PREF_SOURCE_COMPATIBILITY), getValue(PREF_CODEGEN_TARGET_PLATFORM), getValue(PREF_COMPLIANCE), getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE), getValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR), getValue(PREF_RELEASE) }; }
private String getCurrentCompliance() { Object complianceLevel= getValue(PREF_COMPLIANCE); if ((VERSION_1_3.equals(complianceLevel) && IGNORE.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) && IGNORE.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) && VERSION_1_3.equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_1.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) || (VERSION_1_4.equals(complianceLevel) && WARNING.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) && WARNING.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) && VERSION_1_3.equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_2.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) || (VERSION_1_5.equals(complianceLevel) && ERROR.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) && ERROR.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) && VERSION_1_5.equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_5.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) || (VERSION_1_6.equals(complianceLevel) && ERROR.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) && ERROR.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) && VERSION_1_6.equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_6.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM)))) { return DEFAULT_CONF; } return USER_CONF; }
public ComplianceConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { super(context, project, getKeys(project != null), container); setDefaultCompilerComplianceValues(); fBlockEnableState= null; fComplianceFollowsEEControls= new ArrayList<>(); fComplianceControls= new ArrayList<>(); fComplianceChildControls= new ArrayList<>(); fComplianceStatus= new StatusInfo(); fRememberedUserCompliance= new String[] { // caution: order depends on IDX_* constants getValue(PREF_PB_ASSERT_AS_IDENTIFIER), getValue(PREF_PB_ENUM_AS_IDENTIFIER), getValue(PREF_SOURCE_COMPATIBILITY), getValue(PREF_CODEGEN_TARGET_PLATFORM), getValue(PREF_COMPLIANCE), getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE), getValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR) }; }
/** * Evaluate if the current compliance setting correspond to a default setting. * * @return {@link #DEFAULT_CONF} or {@link #USER_CONF} */ private String getCurrentCompliance() { String complianceLevel= getValue(PREF_COMPLIANCE); HashMap<String, String> defaultOptions= new HashMap<>(); JavaModelUtil.setComplianceOptions(defaultOptions, complianceLevel); if (complianceLevel.equals(defaultOptions.get(JavaCore.COMPILER_COMPLIANCE)) && getValue(PREF_SOURCE_COMPATIBILITY).equals(defaultOptions.get(JavaCore.COMPILER_SOURCE)) && getValue(PREF_CODEGEN_TARGET_PLATFORM).equals(defaultOptions.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM)) && getValue(PREF_PB_ASSERT_AS_IDENTIFIER).equals(defaultOptions.get(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER)) && getValue(PREF_PB_ENUM_AS_IDENTIFIER).equals(defaultOptions.get(JavaCore.COMPILER_PB_ENUM_IDENTIFIER))) { return DEFAULT_CONF; } return USER_CONF; }
private void updateAssertEnumAsIdentifierEnableState() { if (checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF)) { String compatibility= getValue(PREF_SOURCE_COMPATIBILITY); boolean isLessThan14= VERSION_1_3.equals(compatibility); updateRememberedComplianceOption(PREF_PB_ASSERT_AS_IDENTIFIER, IDX_ASSERT_AS_IDENTIFIER, isLessThan14); boolean isLessThan15= isLessThan14 || VERSION_1_4.equals(compatibility); updateRememberedComplianceOption(PREF_PB_ENUM_AS_IDENTIFIER, IDX_ENUM_AS_IDENTIFIER, isLessThan15); } }
private void updateAssertEnumAsIdentifierEnableState() { if (checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF)) { String compatibility= getValue(PREF_SOURCE_COMPATIBILITY); boolean isLessThan14= VERSION_1_3.equals(compatibility); updateRememberedComplianceOption(PREF_PB_ASSERT_AS_IDENTIFIER, IDX_ASSERT_AS_IDENTIFIER, isLessThan14); boolean isLessThan15= isLessThan14 || VERSION_1_4.equals(compatibility); updateRememberedComplianceOption(PREF_PB_ENUM_AS_IDENTIFIER, IDX_ENUM_AS_IDENTIFIER, isLessThan15); } }
private void updateAssertEnumAsIdentifierEnableState() { if (checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF)) { String compatibility= getValue(PREF_SOURCE_COMPATIBILITY); boolean isLessThan14= VERSION_1_3.equals(compatibility); updateRememberedComplianceOption(PREF_PB_ASSERT_AS_IDENTIFIER, IDX_ASSERT_AS_IDENTIFIER, isLessThan14); boolean isLessThan15= isLessThan14 || VERSION_1_4.equals(compatibility); updateRememberedComplianceOption(PREF_PB_ENUM_AS_IDENTIFIER, IDX_ENUM_AS_IDENTIFIER, isLessThan15); } }
private IStatus validateCompliance() { StatusInfo status= new StatusInfo(); String compliance= getValue(PREF_COMPLIANCE); String source= getValue(PREF_SOURCE_COMPATIBILITY); String target= getValue(PREF_CODEGEN_TARGET_PLATFORM); // compliance must not be smaller than source or target if (JavaModelUtil.isVersionLessThan(compliance, source)) { status.setError(PreferencesMessages.ComplianceConfigurationBlock_src_greater_compliance); return status; } if (JavaModelUtil.isVersionLessThan(compliance, target)) { status.setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_compliance); return status; } // target must not be smaller than source if (!VERSION_1_3.equals(source) && JavaModelUtil.isVersionLessThan(target, source)) { status.setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_source); return status; } return status; }
private void updateInlineJSREnableState() { String target= getValue(PREF_CODEGEN_TARGET_PLATFORM); boolean enabled= JavaModelUtil.isVersionLessThan(target, VERSION_1_5); Button checkBox= getCheckBox(PREF_CODEGEN_INLINE_JSR_BYTECODE); checkBox.setEnabled(enabled); if (!enabled) { String val= getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE); fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE]= val; if (!ENABLED.equals(val)) { setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, ENABLED); updateCheckBox(checkBox); } } else { String val= fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE]; if (!ENABLED.equals(val)) { setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, val); updateCheckBox(checkBox); } } }
private void updateComplianceEnableSourceTargetState() { boolean enableComplianceControls= true; if (fProject != null) { boolean hasProjectSpecificOptions= hasProjectSpecificOptions(fProject); String complianceFollowsEE= getValue(INTR_COMPLIANCE_FOLLOWS_EE); enableComplianceControls= hasProjectSpecificOptions && !DEFAULT_CONF.equals(complianceFollowsEE); // is disabled or user } boolean enableBasedOnRelease= !fComplierReleaseCheck.getSelection() || !JavaModelUtil.is16OrHigher(getValue(PREF_COMPLIANCE)); boolean enableComplianceChildren= enableComplianceControls && checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF) && enableBasedOnRelease; for (int i= fComplianceChildControls.size() - 1; i >= 0; i--) { Control curr= fComplianceChildControls.get(i); ControlData data= (ControlData) curr.getData(); if (data != null) { if (PREF_SOURCE_COMPATIBILITY.equals(data.getKey()) || PREF_CODEGEN_TARGET_PLATFORM.equals(data.getKey())) { Combo combo= getComboBox(data.getKey()); combo.setEnabled(enableComplianceChildren); } } } }
private void updateStoreMethodParamNamesEnableState() { String target= getValue(PREF_CODEGEN_TARGET_PLATFORM); boolean enabled= JavaModelUtil.is18OrHigher(target); Button checkBox= getCheckBox(PREF_CODEGEN_METHOD_PARAMETERS_ATTR); boolean wasCheckBoxEnabled= checkBox.isEnabled(); checkBox.setEnabled(enabled); if (enabled) { if (!wasCheckBoxEnabled) { String val= fRememberedUserCompliance[IDX_METHOD_PARAMETERS_ATTR]; if (GENERATE.equals(val)) { setValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR, val); updateCheckBox(checkBox); } } } else { String val= getValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR); if (wasCheckBoxEnabled) fRememberedUserCompliance[IDX_METHOD_PARAMETERS_ATTR]= val; if (GENERATE.equals(val)) { setValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR, DO_NOT_GENERATE); updateCheckBox(checkBox); } } }
private void updateInlineJSREnableState() { String target= getValue(PREF_CODEGEN_TARGET_PLATFORM); boolean enabled= JavaModelUtil.isVersionLessThan(target, VERSION_1_5); Button checkBox= getCheckBox(PREF_CODEGEN_INLINE_JSR_BYTECODE); boolean wasCheckBoxEnabled= checkBox.isEnabled(); checkBox.setEnabled(enabled); if (!enabled) { String val= getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE); if (wasCheckBoxEnabled) fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE]= val; if (!ENABLED.equals(val)) { setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, ENABLED); updateCheckBox(checkBox); } } else { if (!wasCheckBoxEnabled) { String val= fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE]; if (!ENABLED.equals(val)) { setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, val); updateCheckBox(checkBox); } } } }
private void updateStoreMethodParamNamesEnableState() { String target= getValue(PREF_CODEGEN_TARGET_PLATFORM); boolean enabled= JavaModelUtil.is18OrHigher(target); Button checkBox= getCheckBox(PREF_CODEGEN_METHOD_PARAMETERS_ATTR); boolean wasCheckBoxEnabled= checkBox.isEnabled(); checkBox.setEnabled(enabled); if (enabled) { if (!wasCheckBoxEnabled) { String val= fRememberedUserCompliance[IDX_METHOD_PARAMETERS_ATTR]; if (GENERATE.equals(val)) { setValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR, val); updateCheckBox(checkBox); } } } else { String val= getValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR); if (wasCheckBoxEnabled) fRememberedUserCompliance[IDX_METHOD_PARAMETERS_ATTR]= val; if (GENERATE.equals(val)) { setValue(PREF_CODEGEN_METHOD_PARAMETERS_ATTR, DO_NOT_GENERATE); updateCheckBox(checkBox); } } }
private void updateComplianceEnableState() { boolean enableComplianceControls= true; if (fProject != null) { boolean hasProjectSpecificOptions= hasProjectSpecificOptions(fProject); String complianceFollowsEE= getValue(INTR_COMPLIANCE_FOLLOWS_EE); updateCheckBox(getCheckBox(INTR_COMPLIANCE_FOLLOWS_EE)); boolean enableComplianceFollowsEE= hasProjectSpecificOptions && ! DISABLED.equals(complianceFollowsEE); // is default or user updateControlsEnableState(fComplianceFollowsEEControls, enableComplianceFollowsEE); enableComplianceControls= hasProjectSpecificOptions && ! DEFAULT_CONF.equals(complianceFollowsEE); // is disabled or user updateControlsEnableState(fComplianceControls, enableComplianceControls); } boolean enableComplianceChildren= enableComplianceControls && checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF); updateControlsEnableState(fComplianceChildControls, enableComplianceChildren); }
private void updateComplianceReleaseSettings() { String compliance= getValue(PREF_COMPLIANCE); boolean isRelease= checkValue(PREF_RELEASE, JavaCore.ENABLED) && JavaModelUtil.is16OrHigher(compliance); if (isRelease) { setValue(PREF_SOURCE_COMPATIBILITY, compliance); setValue(PREF_CODEGEN_TARGET_PLATFORM, compliance); } }
private void updateRememberedComplianceOption(Key prefKey, int idx, boolean enabled) { Combo combo= getComboBox(prefKey); combo.setEnabled(enabled); if (!enabled) { String val= getValue(prefKey); if (!ERROR.equals(val)) { setValue(prefKey, ERROR); updateCombo(combo); fRememberedUserCompliance[idx]= val; } } else { String val= fRememberedUserCompliance[idx]; if (!ERROR.equals(val)) { setValue(prefKey, val); updateCombo(combo); } } }
private void updateRememberedComplianceOption(Key prefKey, int idx, boolean enabled) { Combo combo= getComboBox(prefKey); combo.setEnabled(enabled); if (!enabled) { String val= getValue(prefKey); if (!ERROR.equals(val)) { setValue(prefKey, ERROR); updateCombo(combo); fRememberedUserCompliance[idx]= val; } } else { String val= fRememberedUserCompliance[idx]; if (!ERROR.equals(val)) { setValue(prefKey, val); updateCombo(combo); } } }
private void updateRememberedComplianceOption(Key prefKey, int idx, boolean enabled) { Combo combo= getComboBox(prefKey); combo.setEnabled(enabled); if (!enabled) { String val= getValue(prefKey); if (!ERROR.equals(val)) { setValue(prefKey, ERROR); updateCombo(combo); fRememberedUserCompliance[idx]= val; } } else { String val= fRememberedUserCompliance[idx]; if (!ERROR.equals(val)) { setValue(prefKey, val); updateCombo(combo); } } }
private void updateComplianceEnableState() { boolean enableComplianceControls= true; if (fProject != null) { boolean hasProjectSpecificOptions= hasProjectSpecificOptions(fProject); String complianceFollowsEE= getValue(INTR_COMPLIANCE_FOLLOWS_EE); updateCheckBox(getCheckBox(INTR_COMPLIANCE_FOLLOWS_EE)); boolean enableComplianceFollowsEE= hasProjectSpecificOptions && ! DISABLED.equals(complianceFollowsEE); // is default or user updateControlsEnableState(fComplianceFollowsEEControls, enableComplianceFollowsEE); enableComplianceControls= hasProjectSpecificOptions && ! DEFAULT_CONF.equals(complianceFollowsEE); // is disabled or user updateControlsEnableState(fComplianceControls, enableComplianceControls); } boolean enableComplianceChildren= enableComplianceControls && checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF); updateControlsEnableState(fComplianceChildControls, enableComplianceChildren); updateReleaseOptionStatus(); }