View | Details | Raw Unified | Return to bug 324987 | Differences between
and this patch

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (-27 / +49 lines)
Lines 2041-2087 Link Here
2041
				this.comment_clear_blank_lines_in_block_comment = DefaultCodeFormatterConstants.TRUE.equals(commentClearBlankLinesInBlockCommentOption);
2041
				this.comment_clear_blank_lines_in_block_comment = DefaultCodeFormatterConstants.TRUE.equals(commentClearBlankLinesInBlockCommentOption);
2042
			}
2042
			}
2043
		}
2043
		}
2044
		
2044
		// New line after annotations
2045
		// New line after annotations
2045
		final Object insertNewLineAfterAnnotationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION);
2046
		final Object insertNewLineAfterAnnotationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION);
2046
		if (insertNewLineAfterAnnotationOption != null) { // check if deprecated 3.1 option was used
2047
		
2047
			boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption);
2048
		final Object insertNewLineAfterAnnotationOnMemberOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER);
2048
			this.insert_new_line_after_annotation_on_type = insert;
2049
		final Object insertNewLineAfterAnnotationOnTypeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE);
2049
			this.insert_new_line_after_annotation_on_field = insert;
2050
		final Object insertNewLineAfterAnnotationOnFieldOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD);
2050
			this.insert_new_line_after_annotation_on_method = insert;
2051
		final Object insertNewLineAfterAnnotationOnMethodOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD);
2051
			this.insert_new_line_after_annotation_on_package = insert;
2052
		final Object insertNewLineAfterAnnotationOnPackageOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE);
2052
			this.insert_new_line_after_annotation_on_parameter = insert;
2053
		
2053
			this.insert_new_line_after_annotation_on_local_variable = insert;
2054
		final Object insertNewLineAfterAnnotationOnParameterOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER);
2054
		} else {
2055
		final Object insertNewLineAfterAnnotationOnLocalVariableOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE);
2055
			final Object insertNewLineAfterAnnotationOnMemberOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER);
2056
2056
			if (insertNewLineAfterAnnotationOnMemberOption != null) { // check if deprecated 3.4 option was used
2057
		if (insertNewLineAfterAnnotationOnTypeOption == null
2058
				&& insertNewLineAfterAnnotationOnFieldOption == null
2059
				&& insertNewLineAfterAnnotationOnMethodOption == null
2060
				&& insertNewLineAfterAnnotationOnPackageOption == null) {
2061
			// if none of the new 3.7 options is used, fall back to the deprecated 3.4 option
2062
			if (insertNewLineAfterAnnotationOnMemberOption != null) {
2057
				boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMemberOption);
2063
				boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMemberOption);
2058
				this.insert_new_line_after_annotation_on_type = insert;
2064
				this.insert_new_line_after_annotation_on_type = insert;
2059
				this.insert_new_line_after_annotation_on_field = insert;
2065
				this.insert_new_line_after_annotation_on_field = insert;
2060
				this.insert_new_line_after_annotation_on_method = insert;
2066
				this.insert_new_line_after_annotation_on_method = insert;
2061
				this.insert_new_line_after_annotation_on_package = insert;
2067
				this.insert_new_line_after_annotation_on_package = insert;
2062
			} else { // otherwise use new options
2068
				
2063
				final Object insertNewLineAfterAnnotationOnTypeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE);
2069
				// and use the other 3.4 options if available
2064
				if (insertNewLineAfterAnnotationOnTypeOption != null) {
2070
				if (insertNewLineAfterAnnotationOnParameterOption != null) {
2065
					this.insert_new_line_after_annotation_on_type = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnTypeOption);
2071
					this.insert_new_line_after_annotation_on_parameter = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnParameterOption);
2066
				}
2067
				final Object insertNewLineAfterAnnotationOnFieldOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD);
2068
				if (insertNewLineAfterAnnotationOnFieldOption != null) {
2069
					this.insert_new_line_after_annotation_on_field = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnFieldOption);
2070
				}
2072
				}
2071
				final Object insertNewLineAfterAnnotationOnMethodOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD);
2073
				if (insertNewLineAfterAnnotationOnLocalVariableOption != null) {
2072
				if (insertNewLineAfterAnnotationOnMethodOption != null) {
2074
					this.insert_new_line_after_annotation_on_local_variable = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnLocalVariableOption);
2073
					this.insert_new_line_after_annotation_on_method = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMethodOption);
2074
				}
2075
				}
2075
				final Object insertNewLineAfterAnnotationOnPackageOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE);
2076
				
2076
				if (insertNewLineAfterAnnotationOnPackageOption != null) {
2077
			} else if (insertNewLineAfterAnnotationOnParameterOption == null
2077
					this.insert_new_line_after_annotation_on_package = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnPackageOption);
2078
					&& insertNewLineAfterAnnotationOnLocalVariableOption == null) {
2079
				// if none of the new 3.4 options is used, fall back to the deprecated 3.1 option
2080
				if (insertNewLineAfterAnnotationOption != null) {
2081
					boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption);
2082
					this.insert_new_line_after_annotation_on_type = insert;
2083
					this.insert_new_line_after_annotation_on_field = insert;
2084
					this.insert_new_line_after_annotation_on_method = insert;
2085
					this.insert_new_line_after_annotation_on_package = insert;
2086
					this.insert_new_line_after_annotation_on_parameter = insert;
2087
					this.insert_new_line_after_annotation_on_local_variable = insert;
2078
				}
2088
				}
2079
			}
2089
			}
2080
			final Object insertNewLineAfterAnnotationOnParameterOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER);
2090
		} else { // otherwise use new 3.7 options if available
2091
			if (insertNewLineAfterAnnotationOnTypeOption != null) {
2092
				this.insert_new_line_after_annotation_on_type = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnTypeOption);
2093
			}
2094
			if (insertNewLineAfterAnnotationOnFieldOption != null) {
2095
				this.insert_new_line_after_annotation_on_field = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnFieldOption);
2096
			}
2097
			if (insertNewLineAfterAnnotationOnMethodOption != null) {
2098
				this.insert_new_line_after_annotation_on_method = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMethodOption);
2099
			}
2100
			if (insertNewLineAfterAnnotationOnPackageOption != null) {
2101
				this.insert_new_line_after_annotation_on_package = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnPackageOption);
2102
			}
2103
			// and the other 3.4 options if available
2081
			if (insertNewLineAfterAnnotationOnParameterOption != null) {
2104
			if (insertNewLineAfterAnnotationOnParameterOption != null) {
2082
				this.insert_new_line_after_annotation_on_parameter = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnParameterOption);
2105
				this.insert_new_line_after_annotation_on_parameter = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnParameterOption);
2083
			}
2106
			}
2084
			final Object insertNewLineAfterAnnotationOnLocalVariableOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE);
2085
			if (insertNewLineAfterAnnotationOnLocalVariableOption != null) {
2107
			if (insertNewLineAfterAnnotationOnLocalVariableOption != null) {
2086
				this.insert_new_line_after_annotation_on_local_variable = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnLocalVariableOption);
2108
				this.insert_new_line_after_annotation_on_local_variable = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnLocalVariableOption);
2087
			}
2109
			}
(-)model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java (+26 lines)
Lines 101-105 Link Here
101
			defaultPreferences.put(optionName, (String)entry.getValue());
101
			defaultPreferences.put(optionName, (String)entry.getValue());
102
			optionNames.add(optionName);
102
			optionNames.add(optionName);
103
		}
103
		}
104
105
		// Initialize deprecated options
106
		initializeDeprecatedOptions();
107
	}
108
109
	/**
110
	 * @deprecated As using deprecated options
111
	 */
112
	private void initializeDeprecatedOptions() {
113
		Map deprecatedOptions = JavaModelManager.getJavaModelManager().deprecatedOptions;
114
		deprecatedOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER,
115
			new String[] {
116
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
117
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
118
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
119
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE
120
			});
121
		deprecatedOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION,
122
			new String[] {
123
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
124
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
125
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
126
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE,
127
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE,
128
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER
129
			});
104
	}
130
	}
105
}
131
}
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-76 / +149 lines)
Lines 270-279 Link Here
270
270
271
	public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0];
271
	public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0];
272
272
273
	// Preferences
273
	// Options
274
	private final static int UNKNOWN_OPTION = 0;
275
	private final static int DEPRECATED_OPTION = 1;
276
	private final static int VALID_OPTION = 2;
274
	HashSet optionNames = new HashSet(20);
277
	HashSet optionNames = new HashSet(20);
278
	Map deprecatedOptions = new HashMap();
275
	Hashtable optionsCache;
279
	Hashtable optionsCache;
276
280
281
	// Preferences
277
	public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
282
	public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
278
	static final int PREF_INSTANCE = 0;
283
	static final int PREF_INSTANCE = 0;
279
	static final int PREF_DEFAULT = 1;
284
	static final int PREF_DEFAULT = 1;
Lines 2057-2071 Link Here
2057
		if (isDeprecatedOption(optionName)) {
2062
		if (isDeprecatedOption(optionName)) {
2058
			return JavaCore.ERROR;
2063
			return JavaCore.ERROR;
2059
		}
2064
		}
2060
		String propertyName = optionName;
2065
		int optionLevel = getOptionLevel(optionName);
2061
		if (this.optionNames.contains(propertyName)){
2066
		if (optionLevel != UNKNOWN_OPTION){
2062
			IPreferencesService service = Platform.getPreferencesService();
2067
			IPreferencesService service = Platform.getPreferencesService();
2063
			String value =  service.get(optionName, null, this.preferencesLookup);
2068
			String value = service.get(optionName, null, this.preferencesLookup);
2069
			if (value == null && optionLevel == DEPRECATED_OPTION) {
2070
				// May be a deprecated option, retrieve the new value in compatible options
2071
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
2072
				value = service.get(compatibleOptions[0], null, this.preferencesLookup);
2073
			}
2064
			return value==null ? null : value.trim();
2074
			return value==null ? null : value.trim();
2065
		}
2075
		}
2066
		return null;
2076
		return null;
2067
	}
2077
	}
2068
2078
2079
	/**
2080
	 * Returns the value of the given option for the given Eclipse preferences.
2081
	 * If no value was already set, then inherits from the global options if specified.
2082
	 *
2083
	 * @param optionName The name of the option
2084
	 * @param inheritJavaCoreOptions Tells whether the value can be inherited from global JavaCore options
2085
	 * @param projectPreferences The eclipse preferences from which to get the value
2086
	 * @return The value of the option. May be <code>null</code>
2087
	 */
2088
	public String getOption(String optionName, boolean inheritJavaCoreOptions, IEclipsePreferences projectPreferences) {
2089
		// Return the option value depending on its level
2090
		switch (getOptionLevel(optionName)) {
2091
			case VALID_OPTION:
2092
				// Valid option, return the preference value
2093
				String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null;
2094
				if (projectPreferences == null) return javaCoreDefault;
2095
				String value = projectPreferences.get(optionName, javaCoreDefault);
2096
				return value == null ? null : value.trim();
2097
			case DEPRECATED_OPTION:
2098
				// Return the deprecated option value if it was already set
2099
				String oldValue = projectPreferences.get(optionName, null);
2100
				if (oldValue != null) {
2101
					return oldValue.trim();
2102
				}
2103
				// Get the new compatible value
2104
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
2105
				String newDefault = inheritJavaCoreOptions ? JavaCore.getOption(compatibleOptions[0]) : null;
2106
				String newValue = projectPreferences.get(compatibleOptions[0], newDefault);
2107
				return newValue == null ? null : newValue.trim();
2108
		}
2109
		return null;
2110
	}
2111
2112
	/**
2113
	 * Returns whether an option name is known or not.
2114
	 * 
2115
	 * @param optionName The name of the option
2116
	 * @return <code>true</code> when the option name is either
2117
	 * {@link #VALID_OPTION valid} or {@link #DEPRECATED_OPTION deprecated},
2118
	 * <code>false</code> otherwise.
2119
	 */
2120
	public boolean knowsOption(String optionName) {
2121
		boolean knownOption = this.optionNames.contains(optionName);
2122
		if (!knownOption) {
2123
			knownOption = this.deprecatedOptions.get(optionName) != null;
2124
		}
2125
		return knownOption;
2126
	}
2127
2128
	/**
2129
	 * Returns the level of the given option.
2130
	 * 
2131
	 * @param optionName The name of the option
2132
	 * @return The level of the option as an int which may have the following
2133
	 * values:
2134
	 * <ul>
2135
	 * <li>{@link #UNKNOWN_OPTION}: the given option is unknown</li>
2136
	 * <li>{@link #DEPRECATED_OPTION}: the given option is deprecated</li>
2137
	 * <li>{@link #VALID_OPTION}: the given option is valid</li>
2138
	 * </ul>
2139
	 */
2140
	public int getOptionLevel(String optionName) {
2141
		if (this.optionNames.contains(optionName)) {
2142
			return VALID_OPTION;
2143
		}
2144
		if (this.deprecatedOptions.get(optionName) != null) {
2145
			return DEPRECATED_OPTION;
2146
		}
2147
		return UNKNOWN_OPTION;
2148
	}
2149
2069
	public Hashtable getOptions() {
2150
	public Hashtable getOptions() {
2070
2151
2071
		// return cached options if already computed
2152
		// return cached options if already computed
Lines 2095-2115 Link Here
2095
		}
2176
		}
2096
		if (DEBUG_302850) checkTaskTags("Options initialized from preferences", options); //$NON-NLS-1$
2177
		if (DEBUG_302850) checkTaskTags("Options initialized from preferences", options); //$NON-NLS-1$
2097
2178
2179
		// set deprecated options using preferences service lookup
2180
		Iterator deprecatedEntries = this.deprecatedOptions.entrySet().iterator();
2181
		while (deprecatedEntries.hasNext()) {
2182
			Entry entry = (Entry) deprecatedEntries.next();
2183
			String propertyName = (String) entry.getKey();
2184
			String propertyValue = service.get(propertyName, null, this.preferencesLookup);
2185
			if (propertyValue != null) {
2186
				options.put(propertyName, propertyValue);
2187
				String[] compatibleOptions = (String[]) entry.getValue();
2188
				for (int co=0, length=compatibleOptions.length; co < length; co++) {
2189
					String compatibleOption = compatibleOptions[co];
2190
					if (!options.containsKey(compatibleOption))
2191
						options.put(compatibleOption, propertyValue);
2192
				}
2193
			}
2194
		}
2195
2098
		// get encoding through resource plugin
2196
		// get encoding through resource plugin
2099
		options.put(JavaCore.CORE_ENCODING, JavaCore.getEncoding());
2197
		options.put(JavaCore.CORE_ENCODING, JavaCore.getEncoding());
2100
2198
2101
		// backward compatibility
2199
		// backward compatibility
2102
		addDeprecatedOptions(options);
2200
		addDeprecatedOptions(options);
2103
		try {
2104
			final IEclipsePreferences eclipsePreferences = this.preferencesLookup[PREF_INSTANCE];
2105
			String[] instanceKeys = eclipsePreferences.keys();
2106
			for (int i=0, length=instanceKeys.length; i<length; i++) {
2107
				String optionName = instanceKeys[i];
2108
				migrateObsoleteOption(options, optionName, eclipsePreferences.get(optionName, null));
2109
			}
2110
		} catch (BackingStoreException e) {
2111
			// skip
2112
		}
2113
2201
2114
		Util.fixTaskTags(options);
2202
		Util.fixTaskTags(options);
2115
		if (DEBUG_302850) checkTaskTags("Retrieved options from preferences", options); //$NON-NLS-1$
2203
		if (DEBUG_302850) checkTaskTags("Retrieved options from preferences", options); //$NON-NLS-1$
Lines 2136-2198 Link Here
2136
		}
2224
		}
2137
	}
2225
	}
2138
2226
2139
	/**
2140
	 * Migrates an old option value to its new corresponding option name(s)
2141
	 * when necessary.
2142
	 * <p>
2143
	 * Nothing is done if the given option is not obsolete or if no migration has been
2144
	 * specified for it.
2145
	 * </p><p>
2146
	 * Currently, migration is only done for formatter options.
2147
	 * </p>
2148
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=308000"
2149
	 * 
2150
	 * @param options The options map to update
2151
	 * @param optionName The old option name to update
2152
	 * @param optionValue The value of the old option name
2153
	 */
2154
	public void migrateObsoleteOption(Map options, String optionName, String optionValue) {
2155
2156
		// Migrate formatter options
2157
		String[] compatibleConstants = getFormatterCompatibleConstants(optionName);
2158
		if (compatibleConstants != null) {
2159
			for (int i=0, length=compatibleConstants.length; i < length; i++) {
2160
				options.put(compatibleConstants[i], optionValue);
2161
			}
2162
			return;
2163
		}
2164
	}
2165
2166
	/**
2167
	 * Return an array of compatible constants for an obsolete constant.
2168
	 * 
2169
	 * @param name The name of the obsolete constant
2170
	 * @return The list as a non-empty array of the compatible constants or
2171
	 * <code>null</code> if the constant is <b>not</b> obsolete.
2172
	 * @deprecated As using deprecated formatter constants
2173
	 */
2174
	private static String[] getFormatterCompatibleConstants(String name) {
2175
		if (DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER.equals(name)) {
2176
			return new String[] {
2177
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
2178
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
2179
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
2180
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE
2181
			};
2182
		}
2183
		if (DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION.equals(name)) {
2184
			return new String[] {
2185
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
2186
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
2187
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
2188
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE,
2189
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE,
2190
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER
2191
			};
2192
		}
2193
		return null;
2194
	}
2195
2196
	// Do not modify without modifying getDefaultOptions()
2227
	// Do not modify without modifying getDefaultOptions()
2197
	private Hashtable getDefaultOptionsNoInitialization() {
2228
	private Hashtable getDefaultOptionsNoInitialization() {
2198
		Map defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults
2229
		Map defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults
Lines 4750-4755 Link Here
4750
		}
4781
		}
4751
	}
4782
	}
4752
4783
4784
	/**
4785
	 * Store the preferences value for the given option name.
4786
	 *
4787
	 * @param optionName The name of the option
4788
	 * @param optionValue The value of the option. If <code>null</code>, then
4789
	 * 	the option will be removed from the preferences instead.
4790
	 * @param eclipsePreferences The eclipse preferences to be updated
4791
	 * @return <code>true</code> if the preferences have been changed,
4792
	 * 	<code>false</code> otherwise.
4793
	 */
4794
	public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences) {
4795
		int optionLevel = this.getOptionLevel(optionName);
4796
		if (optionLevel == UNKNOWN_OPTION) return false; // unrecognized option
4797
		
4798
		// Store option value
4799
		switch (optionLevel) {
4800
			case JavaModelManager.VALID_OPTION:
4801
				if (optionValue == null) {
4802
					eclipsePreferences.remove(optionName);
4803
				} else {
4804
					eclipsePreferences.put(optionName, optionValue);
4805
				}
4806
				break;
4807
			case JavaModelManager.DEPRECATED_OPTION:
4808
				// Try to migrate deprecated option
4809
				eclipsePreferences.remove(optionName); // get rid off old preference
4810
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
4811
				for (int co=0, length=compatibleOptions.length; co < length; co++) {
4812
					if (optionValue == null) {
4813
						eclipsePreferences.remove(compatibleOptions[co]);
4814
					} else {
4815
						eclipsePreferences.put(compatibleOptions[co], optionValue);
4816
					}
4817
				}
4818
				break;
4819
			default:
4820
				return false;
4821
		}
4822
		return true;
4823
	}
4824
4753
	public void setOptions(Hashtable newOptions) {
4825
	public void setOptions(Hashtable newOptions) {
4754
		
4826
		
4755
		if (DEBUG_302850) {
4827
		if (DEBUG_302850) {
Lines 4776-4795 Link Here
4776
				Enumeration keys = newOptions.keys();
4848
				Enumeration keys = newOptions.keys();
4777
				while (keys.hasMoreElements()){
4849
				while (keys.hasMoreElements()){
4778
					String key = (String)keys.nextElement();
4850
					String key = (String)keys.nextElement();
4779
					if (!this.optionNames.contains(key)) continue; // unrecognized option
4851
					int optionLevel = getOptionLevel(key);
4852
					if (optionLevel == UNKNOWN_OPTION) continue; // unrecognized option
4780
					if (key.equals(JavaCore.CORE_ENCODING)) {
4853
					if (key.equals(JavaCore.CORE_ENCODING)) {
4781
						if (cachedValue != null) {
4854
						if (cachedValue != null) {
4782
							cachedValue.put(key, JavaCore.getEncoding());
4855
							cachedValue.put(key, JavaCore.getEncoding());
4783
						}
4856
						}
4784
						continue; // skipped, contributed by resource prefs
4857
						continue; // skipped, contributed by resource prefs
4785
					}
4858
					}
4786
					String value = (String)newOptions.get(key);
4859
					String value = (String) newOptions.get(key);
4787
					String defaultValue = defaultPreferences.get(key, null);
4860
					String defaultValue = defaultPreferences.get(key, null);
4861
					// Store value in preferences
4788
					if (defaultValue != null && defaultValue.equals(value)) {
4862
					if (defaultValue != null && defaultValue.equals(value)) {
4789
						instancePreferences.remove(key);
4863
						value = null;
4790
					} else {
4791
						instancePreferences.put(key, value);
4792
					}
4864
					}
4865
					storePreference(key, value, instancePreferences);
4793
				}
4866
				}
4794
				try {
4867
				try {
4795
					// persist options
4868
					// persist options
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-29 / +28 lines)
Lines 1635-1648 Link Here
1635
	 * @see org.eclipse.jdt.core.IJavaProject#getOption(String, boolean)
1635
	 * @see org.eclipse.jdt.core.IJavaProject#getOption(String, boolean)
1636
	 */
1636
	 */
1637
	public String getOption(String optionName, boolean inheritJavaCoreOptions) {
1637
	public String getOption(String optionName, boolean inheritJavaCoreOptions) {
1638
		if (JavaModelManager.getJavaModelManager().optionNames.contains(optionName)){
1638
		return JavaModelManager.getJavaModelManager().getOption(optionName, inheritJavaCoreOptions, getEclipsePreferences());
1639
			IEclipsePreferences projectPreferences = getEclipsePreferences();
1640
			String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null;
1641
			if (projectPreferences == null) return javaCoreDefault;
1642
			String value = projectPreferences.get(optionName, javaCoreDefault);
1643
			return value == null ? null : value.trim();
1644
		}
1645
		return null;
1646
	}
1639
	}
1647
1640
1648
	/**
1641
	/**
Lines 1672-1682 Link Here
1672
					String propertyName = propertyNames[i];
1665
					String propertyName = propertyNames[i];
1673
					String value = projectPreferences.get(propertyName, null);
1666
					String value = projectPreferences.get(propertyName, null);
1674
					if (value != null) {
1667
					if (value != null) {
1675
						if (optionNames.contains(propertyName)){
1668
						value = value.trim();
1676
							projectOptions.put(propertyName, value.trim());
1669
						// Keep the option value, even if it's deprecated
1677
						} else {
1670
						// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987
1678
							// Maybe an obsolete preference, try to migrate it...
1671
						projectOptions.put(propertyName, value);
1679
							javaModelManager.migrateObsoleteOption(projectOptions, propertyName, value.trim());
1672
						if (!optionNames.contains(propertyName)) {
1673
							// try to migrate deprecated options
1674
							String[] compatibleOptions = (String[]) javaModelManager.deprecatedOptions.get(propertyName);
1675
							if (compatibleOptions != null) {
1676
								for (int co=0, length=compatibleOptions.length; co < length; co++) {
1677
									String compatibleOption = compatibleOptions[co];
1678
									if (!projectOptions.containsKey(compatibleOption))
1679
										projectOptions.put(compatibleOption, value);
1680
								}
1681
							}
1680
						}
1682
						}
1681
					}
1683
					}
1682
				}
1684
				}
Lines 1696-1702 Link Here
1696
				Map.Entry entry = (Map.Entry) propertyNames.next();
1698
				Map.Entry entry = (Map.Entry) propertyNames.next();
1697
				String propertyName = (String) entry.getKey();
1699
				String propertyName = (String) entry.getKey();
1698
				String propertyValue = (String) entry.getValue();
1700
				String propertyValue = (String) entry.getValue();
1699
				if (propertyValue != null && optionNames.contains(propertyName)){
1701
				if (propertyValue != null && javaModelManager.knowsOption(propertyName)){
1700
					options.put(propertyName, propertyValue.trim());
1702
					options.put(propertyName, propertyValue.trim());
1701
				}
1703
				}
1702
			}
1704
			}
Lines 2924-2943 Link Here
2924
	 * @see org.eclipse.jdt.core.IJavaProject#setOption(java.lang.String, java.lang.String)
2926
	 * @see org.eclipse.jdt.core.IJavaProject#setOption(java.lang.String, java.lang.String)
2925
	 */
2927
	 */
2926
	public void setOption(String optionName, String optionValue) {
2928
	public void setOption(String optionName, String optionValue) {
2927
		if (!JavaModelManager.getJavaModelManager().optionNames.contains(optionName)) return; // unrecognized option
2929
		// Store option value
2928
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2930
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2929
		if (optionValue == null) {
2931
		boolean modified = JavaModelManager.getJavaModelManager().storePreference(optionName, optionValue, projectPreferences);
2930
			// remove preference
2931
			projectPreferences.remove(optionName);
2932
		} else {
2933
			projectPreferences.put(optionName, optionValue);
2934
		}
2935
2932
2936
		// Dump changes
2933
		// Write changes
2937
		try {
2934
		if (modified) {
2938
			projectPreferences.flush();
2935
			try {
2939
		} catch (BackingStoreException e) {
2936
				projectPreferences.flush();
2940
			// problem with pref store - quietly ignore
2937
			} catch (BackingStoreException e) {
2938
				// problem with pref store - quietly ignore
2939
			}
2941
		}
2940
		}
2942
	}
2941
	}
2943
2942
Lines 2953-2964 Link Here
2953
				projectPreferences.clear();
2952
				projectPreferences.clear();
2954
			} else {
2953
			} else {
2955
				Iterator entries = newOptions.entrySet().iterator();
2954
				Iterator entries = newOptions.entrySet().iterator();
2955
				JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager();
2956
				while (entries.hasNext()){
2956
				while (entries.hasNext()){
2957
					Map.Entry entry = (Map.Entry) entries.next();
2957
					Map.Entry entry = (Map.Entry) entries.next();
2958
					String key = (String) entry.getKey();
2958
					String key = (String) entry.getKey();
2959
					if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option
2959
					String value = (String) entry.getValue();
2960
					// no filtering for encoding (custom encoding for project is allowed)
2960
					javaModelManager.storePreference(key, value, projectPreferences);
2961
					projectPreferences.put(key, (String) entry.getValue());
2962
				}
2961
				}
2963
2962
2964
				// reset to default all options not in new map
2963
				// reset to default all options not in new map

Return to bug 324987