### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v retrieving revision 1.110 diff -u -r1.110 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 20 Jan 2011 15:31:08 -0000 1.110 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 9 May 2011 12:09:36 -0000 @@ -2041,47 +2041,69 @@ this.comment_clear_blank_lines_in_block_comment = DefaultCodeFormatterConstants.TRUE.equals(commentClearBlankLinesInBlockCommentOption); } } + // New line after annotations final Object insertNewLineAfterAnnotationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION); - if (insertNewLineAfterAnnotationOption != null) { // check if deprecated 3.1 option was used - boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption); - this.insert_new_line_after_annotation_on_type = insert; - this.insert_new_line_after_annotation_on_field = insert; - this.insert_new_line_after_annotation_on_method = insert; - this.insert_new_line_after_annotation_on_package = insert; - this.insert_new_line_after_annotation_on_parameter = insert; - this.insert_new_line_after_annotation_on_local_variable = insert; - } else { - final Object insertNewLineAfterAnnotationOnMemberOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER); - if (insertNewLineAfterAnnotationOnMemberOption != null) { // check if deprecated 3.4 option was used + + final Object insertNewLineAfterAnnotationOnMemberOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER); + final Object insertNewLineAfterAnnotationOnTypeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE); + final Object insertNewLineAfterAnnotationOnFieldOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD); + final Object insertNewLineAfterAnnotationOnMethodOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD); + final Object insertNewLineAfterAnnotationOnPackageOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE); + + final Object insertNewLineAfterAnnotationOnParameterOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER); + final Object insertNewLineAfterAnnotationOnLocalVariableOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE); + + if (insertNewLineAfterAnnotationOnTypeOption == null + && insertNewLineAfterAnnotationOnFieldOption == null + && insertNewLineAfterAnnotationOnMethodOption == null + && insertNewLineAfterAnnotationOnPackageOption == null) { + // if none of the new 3.7 options is used, fall back to the deprecated 3.4 option + if (insertNewLineAfterAnnotationOnMemberOption != null) { boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMemberOption); this.insert_new_line_after_annotation_on_type = insert; this.insert_new_line_after_annotation_on_field = insert; this.insert_new_line_after_annotation_on_method = insert; this.insert_new_line_after_annotation_on_package = insert; - } else { // otherwise use new options - final Object insertNewLineAfterAnnotationOnTypeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE); - if (insertNewLineAfterAnnotationOnTypeOption != null) { - this.insert_new_line_after_annotation_on_type = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnTypeOption); - } - final Object insertNewLineAfterAnnotationOnFieldOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD); - if (insertNewLineAfterAnnotationOnFieldOption != null) { - this.insert_new_line_after_annotation_on_field = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnFieldOption); + + // and use the other 3.4 options if available + if (insertNewLineAfterAnnotationOnParameterOption != null) { + this.insert_new_line_after_annotation_on_parameter = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnParameterOption); } - final Object insertNewLineAfterAnnotationOnMethodOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD); - if (insertNewLineAfterAnnotationOnMethodOption != null) { - this.insert_new_line_after_annotation_on_method = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMethodOption); + if (insertNewLineAfterAnnotationOnLocalVariableOption != null) { + this.insert_new_line_after_annotation_on_local_variable = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnLocalVariableOption); } - final Object insertNewLineAfterAnnotationOnPackageOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE); - if (insertNewLineAfterAnnotationOnPackageOption != null) { - this.insert_new_line_after_annotation_on_package = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnPackageOption); + + } else if (insertNewLineAfterAnnotationOnParameterOption == null + && insertNewLineAfterAnnotationOnLocalVariableOption == null) { + // if none of the new 3.4 options is used, fall back to the deprecated 3.1 option + if (insertNewLineAfterAnnotationOption != null) { + boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption); + this.insert_new_line_after_annotation_on_type = insert; + this.insert_new_line_after_annotation_on_field = insert; + this.insert_new_line_after_annotation_on_method = insert; + this.insert_new_line_after_annotation_on_package = insert; + this.insert_new_line_after_annotation_on_parameter = insert; + this.insert_new_line_after_annotation_on_local_variable = insert; } } - final Object insertNewLineAfterAnnotationOnParameterOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER); + } else { // otherwise use new 3.7 options if available + if (insertNewLineAfterAnnotationOnTypeOption != null) { + this.insert_new_line_after_annotation_on_type = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnTypeOption); + } + if (insertNewLineAfterAnnotationOnFieldOption != null) { + this.insert_new_line_after_annotation_on_field = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnFieldOption); + } + if (insertNewLineAfterAnnotationOnMethodOption != null) { + this.insert_new_line_after_annotation_on_method = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMethodOption); + } + if (insertNewLineAfterAnnotationOnPackageOption != null) { + this.insert_new_line_after_annotation_on_package = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnPackageOption); + } + // and the other 3.4 options if available if (insertNewLineAfterAnnotationOnParameterOption != null) { this.insert_new_line_after_annotation_on_parameter = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnParameterOption); } - final Object insertNewLineAfterAnnotationOnLocalVariableOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE); if (insertNewLineAfterAnnotationOnLocalVariableOption != null) { this.insert_new_line_after_annotation_on_local_variable = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnLocalVariableOption); } Index: model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java,v retrieving revision 1.49 diff -u -r1.49 JavaCorePreferenceInitializer.java --- model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java 6 Jan 2011 13:43:57 -0000 1.49 +++ model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java 9 May 2011 12:09:36 -0000 @@ -101,5 +101,31 @@ defaultPreferences.put(optionName, (String)entry.getValue()); optionNames.add(optionName); } + + // Initialize deprecated options + initializeDeprecatedOptions(); + } + + /** + * @deprecated As using deprecated options + */ + private void initializeDeprecatedOptions() { + Map deprecatedOptions = JavaModelManager.getJavaModelManager().deprecatedOptions; + deprecatedOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, + new String[] { + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE + }); + deprecatedOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION, + new String[] { + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, + DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER + }); } } Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.466 diff -u -r1.466 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 3 Apr 2011 19:07:01 -0000 1.466 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 9 May 2011 12:09:36 -0000 @@ -270,10 +270,15 @@ public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0]; - // Preferences + // Options + private final static int UNKNOWN_OPTION = 0; + private final static int DEPRECATED_OPTION = 1; + private final static int VALID_OPTION = 2; HashSet optionNames = new HashSet(20); + Map deprecatedOptions = new HashMap(); Hashtable optionsCache; + // Preferences public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; static final int PREF_INSTANCE = 0; static final int PREF_DEFAULT = 1; @@ -2057,15 +2062,91 @@ if (isDeprecatedOption(optionName)) { return JavaCore.ERROR; } - String propertyName = optionName; - if (this.optionNames.contains(propertyName)){ + int optionLevel = getOptionLevel(optionName); + if (optionLevel != UNKNOWN_OPTION){ IPreferencesService service = Platform.getPreferencesService(); - String value = service.get(optionName, null, this.preferencesLookup); + String value = service.get(optionName, null, this.preferencesLookup); + if (value == null && optionLevel == DEPRECATED_OPTION) { + // May be a deprecated option, retrieve the new value in compatible options + String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName); + value = service.get(compatibleOptions[0], null, this.preferencesLookup); + } return value==null ? null : value.trim(); } return null; } + /** + * Returns the value of the given option for the given Eclipse preferences. + * If no value was already set, then inherits from the global options if specified. + * + * @param optionName The name of the option + * @param inheritJavaCoreOptions Tells whether the value can be inherited from global JavaCore options + * @param projectPreferences The eclipse preferences from which to get the value + * @return The value of the option. May be null + */ + public String getOption(String optionName, boolean inheritJavaCoreOptions, IEclipsePreferences projectPreferences) { + // Return the option value depending on its level + switch (getOptionLevel(optionName)) { + case VALID_OPTION: + // Valid option, return the preference value + String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null; + if (projectPreferences == null) return javaCoreDefault; + String value = projectPreferences.get(optionName, javaCoreDefault); + return value == null ? null : value.trim(); + case DEPRECATED_OPTION: + // Return the deprecated option value if it was already set + String oldValue = projectPreferences.get(optionName, null); + if (oldValue != null) { + return oldValue.trim(); + } + // Get the new compatible value + String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName); + String newDefault = inheritJavaCoreOptions ? JavaCore.getOption(compatibleOptions[0]) : null; + String newValue = projectPreferences.get(compatibleOptions[0], newDefault); + return newValue == null ? null : newValue.trim(); + } + return null; + } + + /** + * Returns whether an option name is known or not. + * + * @param optionName The name of the option + * @return true when the option name is either + * {@link #VALID_OPTION valid} or {@link #DEPRECATED_OPTION deprecated}, + * false otherwise. + */ + public boolean knowsOption(String optionName) { + boolean knownOption = this.optionNames.contains(optionName); + if (!knownOption) { + knownOption = this.deprecatedOptions.get(optionName) != null; + } + return knownOption; + } + + /** + * Returns the level of the given option. + * + * @param optionName The name of the option + * @return The level of the option as an int which may have the following + * values: + * + */ + public int getOptionLevel(String optionName) { + if (this.optionNames.contains(optionName)) { + return VALID_OPTION; + } + if (this.deprecatedOptions.get(optionName) != null) { + return DEPRECATED_OPTION; + } + return UNKNOWN_OPTION; + } + public Hashtable getOptions() { // return cached options if already computed @@ -2095,21 +2176,28 @@ } if (DEBUG_302850) checkTaskTags("Options initialized from preferences", options); //$NON-NLS-1$ + // set deprecated options using preferences service lookup + Iterator deprecatedEntries = this.deprecatedOptions.entrySet().iterator(); + while (deprecatedEntries.hasNext()) { + Entry entry = (Entry) deprecatedEntries.next(); + String propertyName = (String) entry.getKey(); + String propertyValue = service.get(propertyName, null, this.preferencesLookup); + if (propertyValue != null) { + options.put(propertyName, propertyValue); + String[] compatibleOptions = (String[]) entry.getValue(); + for (int co=0, length=compatibleOptions.length; co < length; co++) { + String compatibleOption = compatibleOptions[co]; + if (!options.containsKey(compatibleOption)) + options.put(compatibleOption, propertyValue); + } + } + } + // get encoding through resource plugin options.put(JavaCore.CORE_ENCODING, JavaCore.getEncoding()); // backward compatibility addDeprecatedOptions(options); - try { - final IEclipsePreferences eclipsePreferences = this.preferencesLookup[PREF_INSTANCE]; - String[] instanceKeys = eclipsePreferences.keys(); - for (int i=0, length=instanceKeys.length; i - * Nothing is done if the given option is not obsolete or if no migration has been - * specified for it. - *

- * Currently, migration is only done for formatter options. - *

- * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=308000" - * - * @param options The options map to update - * @param optionName The old option name to update - * @param optionValue The value of the old option name - */ - public void migrateObsoleteOption(Map options, String optionName, String optionValue) { - - // Migrate formatter options - String[] compatibleConstants = getFormatterCompatibleConstants(optionName); - if (compatibleConstants != null) { - for (int i=0, length=compatibleConstants.length; i < length; i++) { - options.put(compatibleConstants[i], optionValue); - } - return; - } - } - - /** - * Return an array of compatible constants for an obsolete constant. - * - * @param name The name of the obsolete constant - * @return The list as a non-empty array of the compatible constants or - * null if the constant is not obsolete. - * @deprecated As using deprecated formatter constants - */ - private static String[] getFormatterCompatibleConstants(String name) { - if (DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER.equals(name)) { - return new String[] { - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE - }; - } - if (DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION.equals(name)) { - return new String[] { - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, - DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER - }; - } - return null; - } - // Do not modify without modifying getDefaultOptions() private Hashtable getDefaultOptionsNoInitialization() { Map defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults @@ -4750,6 +4781,47 @@ } } + /** + * Store the preferences value for the given option name. + * + * @param optionName The name of the option + * @param optionValue The value of the option. If null, then + * the option will be removed from the preferences instead. + * @param eclipsePreferences The eclipse preferences to be updated + * @return true if the preferences have been changed, + * false otherwise. + */ + public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences) { + int optionLevel = this.getOptionLevel(optionName); + if (optionLevel == UNKNOWN_OPTION) return false; // unrecognized option + + // Store option value + switch (optionLevel) { + case JavaModelManager.VALID_OPTION: + if (optionValue == null) { + eclipsePreferences.remove(optionName); + } else { + eclipsePreferences.put(optionName, optionValue); + } + break; + case JavaModelManager.DEPRECATED_OPTION: + // Try to migrate deprecated option + eclipsePreferences.remove(optionName); // get rid off old preference + String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName); + for (int co=0, length=compatibleOptions.length; co < length; co++) { + if (optionValue == null) { + eclipsePreferences.remove(compatibleOptions[co]); + } else { + eclipsePreferences.put(compatibleOptions[co], optionValue); + } + } + break; + default: + return false; + } + return true; + } + public void setOptions(Hashtable newOptions) { if (DEBUG_302850) { @@ -4776,20 +4848,21 @@ Enumeration keys = newOptions.keys(); while (keys.hasMoreElements()){ String key = (String)keys.nextElement(); - if (!this.optionNames.contains(key)) continue; // unrecognized option + int optionLevel = getOptionLevel(key); + if (optionLevel == UNKNOWN_OPTION) continue; // unrecognized option if (key.equals(JavaCore.CORE_ENCODING)) { if (cachedValue != null) { cachedValue.put(key, JavaCore.getEncoding()); } continue; // skipped, contributed by resource prefs } - String value = (String)newOptions.get(key); + String value = (String) newOptions.get(key); String defaultValue = defaultPreferences.get(key, null); + // Store value in preferences if (defaultValue != null && defaultValue.equals(value)) { - instancePreferences.remove(key); - } else { - instancePreferences.put(key, value); + value = null; } + storePreference(key, value, instancePreferences); } try { // persist options Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.446 diff -u -r1.446 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 4 May 2011 14:47:29 -0000 1.446 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 9 May 2011 12:09:37 -0000 @@ -1635,14 +1635,7 @@ * @see org.eclipse.jdt.core.IJavaProject#getOption(String, boolean) */ public String getOption(String optionName, boolean inheritJavaCoreOptions) { - if (JavaModelManager.getJavaModelManager().optionNames.contains(optionName)){ - IEclipsePreferences projectPreferences = getEclipsePreferences(); - String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null; - if (projectPreferences == null) return javaCoreDefault; - String value = projectPreferences.get(optionName, javaCoreDefault); - return value == null ? null : value.trim(); - } - return null; + return JavaModelManager.getJavaModelManager().getOption(optionName, inheritJavaCoreOptions, getEclipsePreferences()); } /** @@ -1672,11 +1665,20 @@ String propertyName = propertyNames[i]; String value = projectPreferences.get(propertyName, null); if (value != null) { - if (optionNames.contains(propertyName)){ - projectOptions.put(propertyName, value.trim()); - } else { - // Maybe an obsolete preference, try to migrate it... - javaModelManager.migrateObsoleteOption(projectOptions, propertyName, value.trim()); + value = value.trim(); + // Keep the option value, even if it's deprecated + // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987 + projectOptions.put(propertyName, value); + if (!optionNames.contains(propertyName)) { + // try to migrate deprecated options + String[] compatibleOptions = (String[]) javaModelManager.deprecatedOptions.get(propertyName); + if (compatibleOptions != null) { + for (int co=0, length=compatibleOptions.length; co < length; co++) { + String compatibleOption = compatibleOptions[co]; + if (!projectOptions.containsKey(compatibleOption)) + projectOptions.put(compatibleOption, value); + } + } } } } @@ -1696,7 +1698,7 @@ Map.Entry entry = (Map.Entry) propertyNames.next(); String propertyName = (String) entry.getKey(); String propertyValue = (String) entry.getValue(); - if (propertyValue != null && optionNames.contains(propertyName)){ + if (propertyValue != null && javaModelManager.knowsOption(propertyName)){ options.put(propertyName, propertyValue.trim()); } } @@ -2924,20 +2926,17 @@ * @see org.eclipse.jdt.core.IJavaProject#setOption(java.lang.String, java.lang.String) */ public void setOption(String optionName, String optionValue) { - if (!JavaModelManager.getJavaModelManager().optionNames.contains(optionName)) return; // unrecognized option + // Store option value IEclipsePreferences projectPreferences = getEclipsePreferences(); - if (optionValue == null) { - // remove preference - projectPreferences.remove(optionName); - } else { - projectPreferences.put(optionName, optionValue); - } + boolean modified = JavaModelManager.getJavaModelManager().storePreference(optionName, optionValue, projectPreferences); - // Dump changes - try { - projectPreferences.flush(); - } catch (BackingStoreException e) { - // problem with pref store - quietly ignore + // Write changes + if (modified) { + try { + projectPreferences.flush(); + } catch (BackingStoreException e) { + // problem with pref store - quietly ignore + } } } @@ -2953,12 +2952,12 @@ projectPreferences.clear(); } else { Iterator entries = newOptions.entrySet().iterator(); + JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager(); while (entries.hasNext()){ Map.Entry entry = (Map.Entry) entries.next(); String key = (String) entry.getKey(); - if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option - // no filtering for encoding (custom encoding for project is allowed) - projectPreferences.put(key, (String) entry.getValue()); + String value = (String) entry.getValue(); + javaModelManager.storePreference(key, value, projectPreferences); } // reset to default all options not in new map