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
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (-5 / +22 lines)
Lines 62-68 Link Here
62
	Map formatterOptions;
62
	Map formatterOptions;
63
63
64
	static {
64
	static {
65
//		TESTS_NUMBERS = new int[] { 738 };
65
//		TESTS_NUMBERS = new int[] { 558, 559, 575, 727, 728 };
66
//		TESTS_RANGE = new int[] { 734, -1 };
66
//		TESTS_RANGE = new int[] { 734, -1 };
67
	}
67
	}
68
	public static Test suite() {
68
	public static Test suite() {
Lines 8007-8013 Link Here
8007
	public void test558() {
8007
	public void test558() {
8008
		Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings();
8008
		Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings();
8009
8009
8010
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, null);
8010
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, null);
8011
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, null);
8012
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, null);
8013
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, null);
8011
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, null);
8014
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, null);
8012
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, null);
8015
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, null);
8013
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247: use deprecated option
8016
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247: use deprecated option
Lines 8044-8050 Link Here
8044
	 */
8047
	 */
8045
	public void test559() {
8048
	public void test559() {
8046
		Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings();
8049
		Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings();
8047
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, null);
8050
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, null);
8051
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, null);
8052
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, null);
8053
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, null);
8048
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, null);
8054
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, null);
8049
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, null);
8055
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, null);
8050
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247: use deprecated option
8056
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247: use deprecated option
Lines 8345-8351 Link Here
8345
8351
8346
	public void test575() {
8352
	public void test575() {
8347
		Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
8353
		Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
8348
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, null);
8354
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, null);
8355
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, null);
8356
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, null);
8357
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, null);
8349
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, null);
8358
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, null);
8350
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, null);
8359
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, null);
8351
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247: use deprecated option
8360
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247: use deprecated option
Lines 10831-10837 Link Here
10831
	this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
10840
	this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
10832
	this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
10841
	this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
10833
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, DefaultCodeFormatterConstants.TRUE);
10842
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, DefaultCodeFormatterConstants.TRUE);
10834
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, DefaultCodeFormatterConstants.FALSE);
10843
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, DefaultCodeFormatterConstants.FALSE);
10844
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, DefaultCodeFormatterConstants.FALSE);
10845
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, DefaultCodeFormatterConstants.FALSE);
10846
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, DefaultCodeFormatterConstants.FALSE);
10835
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, DefaultCodeFormatterConstants.FALSE);
10847
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, DefaultCodeFormatterConstants.FALSE);
10836
	String source =
10848
	String source =
10837
		"@Deprecated package pack;\n" + 
10849
		"@Deprecated package pack;\n" + 
Lines 10864-10873 Link Here
10864
 */
10876
 */
10865
public void test728() {
10877
public void test728() {
10866
	this.formatterPrefs = null;
10878
	this.formatterPrefs = null;
10879
	this.formatterOptions.remove(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD);
10880
	this.formatterOptions.remove(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD);
10881
	this.formatterOptions.remove(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE);
10882
	this.formatterOptions.remove(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE);
10867
	this.formatterOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6);
10883
	this.formatterOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6);
10868
	this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
10884
	this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
10869
	this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
10885
	this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
10870
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION, DefaultCodeFormatterConstants.FALSE);
10886
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION, DefaultCodeFormatterConstants.FALSE);
10887
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, JavaCore.DO_NOT_INSERT);
10871
	String source =
10888
	String source =
10872
		"@Deprecated package pack;\n" + 
10889
		"@Deprecated package pack;\n" + 
10873
		"public class Test {\n" + 
10890
		"public class Test {\n" + 
(-)src/org/eclipse/jdt/core/tests/model/OptionTests.java (+192 lines)
Lines 23-28 Link Here
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
24
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IJavaProject;
25
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.JavaCore;
26
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
26
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
27
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
27
import org.eclipse.jdt.internal.core.JavaModelManager;
28
import org.eclipse.jdt.internal.core.JavaModelManager;
28
import org.eclipse.jdt.internal.core.JavaProject;
29
import org.eclipse.jdt.internal.core.JavaProject;
Lines 701-704 Link Here
701
		JavaCore.setOptions(wkspOptions);
702
		JavaCore.setOptions(wkspOptions);
702
	}
703
	}
703
}
704
}
705
706
/**
707
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
708
 * @test Verify that a deprecated option is well preserved when a client use it
709
 * 		through the IJavaProject.setOption(String, String) API
710
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987"
711
 * @deprecated As using deprecated constants
712
 */
713
public void testBug324987_Project01() throws CoreException {
714
	try {
715
		// Set the obsolete option using the IJavaProject API
716
		JavaProject project = (JavaProject) createJavaProject("P");
717
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
718
		project.setOption(obsoleteOption, JavaCore.DO_NOT_INSERT);
719
		// Verify that obsolete preference is not stored
720
		assertNull(
721
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
722
				project.getEclipsePreferences().get(obsoleteOption, null));
723
		// Verify that project obsolete option is well retrieved
724
		assertEquals(
725
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
726
				JavaCore.DO_NOT_INSERT,
727
				project.getOption(obsoleteOption, true));
728
	} finally {
729
		deleteProject("P");
730
	}
731
}
732
/**
733
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
734
 * @test Verify that a new option beats the deprecated option when a client sets both
735
 * 		through the IJavaProject#setOptions(Map) API
736
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987"
737
 * @deprecated As using deprecated constants
738
 */
739
public void testBug324987_Project02() throws CoreException {
740
	try {
741
		// Set the obsolete option using the IJavaProject API
742
		JavaProject project = (JavaProject) createJavaProject("P");
743
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
744
		Map testOptions = project.getOptions(true);
745
		testOptions.put(obsoleteOption, JavaCore.DO_NOT_INSERT);
746
		project.setOptions(testOptions);
747
		// Verify that obsolete preference is not stored
748
		assertNull(
749
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
750
				project.getEclipsePreferences().get(obsoleteOption, null));
751
		// Verify that project obsolete option is well retrieved
752
		assertEquals(
753
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
754
				JavaCore.INSERT,
755
				project.getOption(obsoleteOption, true));
756
	} finally {
757
		deleteProject("P");
758
	}
759
}
760
/**
761
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
762
 * @test Verify that a deprecated option is well preserved when read through
763
 * 		the IEclipsePreferences (i.e. simulate reading project preferences of a project
764
 * 		coming from an older workspace)
765
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987"
766
 * @deprecated As using deprecated constants
767
 */
768
public void testBug324987_Project03() throws CoreException {
769
	try {
770
		// Set the obsolete preference simulating a project coming from an older version workspace
771
		JavaProject project = (JavaProject) createJavaProject("P");
772
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
773
		project.getEclipsePreferences().put(obsoleteOption, JavaCore.DO_NOT_INSERT);
774
		// Verify that obsolete preference is stored
775
		assertEquals(
776
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
777
				JavaCore.DO_NOT_INSERT,
778
				project.getEclipsePreferences().get(obsoleteOption, null));
779
		// Verify that project obsolete option is well retrieved
780
		assertEquals(
781
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
782
				JavaCore.DO_NOT_INSERT,
783
				project.getOption(obsoleteOption, true));
784
	} finally {
785
		deleteProject("P");
786
	}
787
}
788
/**
789
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
790
 * @test Verify that a new option beats the deprecated option when a client sets both
791
 * 		through the JavaCore.setOptions(Hashtable) API
792
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987"
793
 * @deprecated As using deprecated constants
794
 */
795
public void testBug324987_Workspace01() throws CoreException {
796
	try {
797
		// Set the obsolete option using the JavaCore API
798
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
799
		Hashtable testOptions = JavaCore.getOptions();
800
		testOptions.put(obsoleteOption, JavaCore.DO_NOT_INSERT);
801
		JavaCore.setOptions(testOptions);
802
		// Verify that obsolete preference is not stored
803
		assertNull(
804
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
805
				JavaModelManager.getJavaModelManager().getInstancePreferences().get(obsoleteOption, null));
806
		// Verify that workspace obsolete option is well retrieved
807
		assertEquals(
808
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
809
				JavaCore.INSERT,
810
				JavaCore.getOption(obsoleteOption));
811
	} finally {
812
		JavaCore.setOptions(JavaCore.getDefaultOptions());
813
	}
814
}
815
/**
816
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
817
 * @test Verify that a deprecated option is well preserved when read through
818
 * 		the IEclipsePreferences (i.e. simulate reading an older workspace)
819
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987"
820
 * @deprecated As using deprecated constants
821
 */
822
public void testBug324987_Workspace02() throws CoreException {
823
	try {
824
		// Set the obsolete preference simulating an older version workspace
825
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
826
		IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences();
827
		instancePreferences.put(obsoleteOption, JavaCore.DO_NOT_INSERT);
828
		// Verify that obsolete preference is stored
829
		assertEquals(
830
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
831
				JavaCore.DO_NOT_INSERT,
832
				instancePreferences.get(obsoleteOption, null));
833
		// Verify that project obsolete option is well retrieved
834
		assertEquals(
835
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
836
				JavaCore.DO_NOT_INSERT,
837
				JavaCore.getOption(obsoleteOption));
838
	} finally {
839
		deleteProject("P");
840
	}
841
}
842
/**
843
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
844
 * @test Verify that a deprecated option is well preserved when a client use it
845
 * 		through the JavaCore.setOptions(Hashtable) API
846
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987"
847
 * @deprecated As using deprecated constants
848
 */
849
public void testBug324987_Workspace03() throws CoreException {
850
	try {
851
		// Set the obsolete option using the JavaCore API
852
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
853
		Hashtable testOptions = JavaCore.getOptions();
854
		testOptions.put(obsoleteOption, JavaCore.INSERT);
855
		JavaCore.setOptions(testOptions);
856
		// Verify that obsolete preference is not stored
857
		assertNull(
858
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
859
				JavaModelManager.getJavaModelManager().getInstancePreferences().get(obsoleteOption, null));
860
		// Verify that workspace obsolete option is well retrieved
861
		assertEquals(
862
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
863
				JavaCore.INSERT,
864
				JavaCore.getOption(obsoleteOption));
865
	} finally {
866
		JavaCore.setOptions(JavaCore.getDefaultOptions());
867
	}
868
}
869
/**
870
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
871
 * @test Verify that a deprecated option is well preserved when read through
872
 * 		the IEclipsePreferences (i.e. simulate reading an older workspace)
873
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987"
874
 * @deprecated As using deprecated constants
875
 */
876
public void testBug324987_Workspace04() throws CoreException {
877
	try {
878
		// Set the obsolete preference simulating an older version workspace
879
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
880
		IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences();
881
		instancePreferences.put(obsoleteOption, JavaCore.INSERT);
882
		// Verify that obsolete preference is stored
883
		assertEquals(
884
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
885
				JavaCore.INSERT,
886
				instancePreferences.get(obsoleteOption, null));
887
		// Verify that project obsolete option is well retrieved
888
		assertEquals(
889
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
890
				JavaCore.INSERT,
891
				JavaCore.getOption(obsoleteOption));
892
	} finally {
893
		deleteProject("P");
894
	}
895
}
704
}
896
}

Return to bug 324987