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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java (-1 / +27 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 / +147 lines)
Lines 267-276 Link Here
267
267
268
	public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0];
268
	public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0];
269
269
270
	// Preferences
270
	// Options
271
	private final static int UNKNOWN_OPTION = 0;
272
	private final static int DEPRECATED_OPTION = 1;
273
	private final static int VALID_OPTION = 2;
271
	HashSet optionNames = new HashSet(20);
274
	HashSet optionNames = new HashSet(20);
275
	Map deprecatedOptions = new HashMap();
272
	Hashtable optionsCache;
276
	Hashtable optionsCache;
273
277
278
	// Preferences
274
	public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
279
	public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
275
	static final int PREF_INSTANCE = 0;
280
	static final int PREF_INSTANCE = 0;
276
	static final int PREF_DEFAULT = 1;
281
	static final int PREF_DEFAULT = 1;
Lines 2038-2052 Link Here
2038
		if (isDeprecatedOption(optionName)) {
2043
		if (isDeprecatedOption(optionName)) {
2039
			return JavaCore.ERROR;
2044
			return JavaCore.ERROR;
2040
		}
2045
		}
2041
		String propertyName = optionName;
2046
		int optionLevel = getOptionLevel(optionName);
2042
		if (this.optionNames.contains(propertyName)){
2047
		if (optionLevel != UNKNOWN_OPTION){
2043
			IPreferencesService service = Platform.getPreferencesService();
2048
			IPreferencesService service = Platform.getPreferencesService();
2044
			String value =  service.get(optionName, null, this.preferencesLookup);
2049
			String value = service.get(optionName, null, this.preferencesLookup);
2050
			if (value == null && optionLevel == DEPRECATED_OPTION) {
2051
				// May be a deprecated option, retrieve the new value in compatible options
2052
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
2053
				value = service.get(compatibleOptions[0], null, this.preferencesLookup);
2054
			}
2045
			return value==null ? null : value.trim();
2055
			return value==null ? null : value.trim();
2046
		}
2056
		}
2047
		return null;
2057
		return null;
2048
	}
2058
	}
2049
2059
2060
	/**
2061
	 * Returns the value of the given option for the given Eclipse preferences.
2062
	 * If no value was already set, then inherits from the global options if specified.
2063
	 *
2064
	 * @param optionName The name of the option
2065
	 * @param inheritJavaCoreOptions Tells whether the value can be inherited from global JavaCore options
2066
	 * @param projectPreferences The eclipse preferences from which to get the value
2067
	 * @return The value of the option. May be <code>null</code>
2068
	 */
2069
	public String getOption(String optionName, boolean inheritJavaCoreOptions, IEclipsePreferences projectPreferences) {
2070
		// Return the option value depending on its level
2071
		switch (getOptionLevel(optionName)) {
2072
			case VALID_OPTION:
2073
				// Valid option, return the preference value
2074
				String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null;
2075
				if (projectPreferences == null) return javaCoreDefault;
2076
				String value = projectPreferences.get(optionName, javaCoreDefault);
2077
				return value == null ? null : value.trim();
2078
			case DEPRECATED_OPTION:
2079
				// Return the deprecated option value if it was already set
2080
				String oldValue = projectPreferences.get(optionName, null);
2081
				if (oldValue != null) {
2082
					return oldValue.trim();
2083
				}
2084
				// Get the new compatible value
2085
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
2086
				String newDefault = inheritJavaCoreOptions ? JavaCore.getOption(compatibleOptions[0]) : null;
2087
				String newValue = projectPreferences.get(compatibleOptions[0], newDefault);
2088
				return newValue == null ? null : newValue.trim();
2089
		}
2090
		return null;
2091
	}
2092
2093
	/**
2094
	 * Returns whether an option name is known or not.
2095
	 * 
2096
	 * @param optionName The name of the option
2097
	 * @return <code>true</code> when the option name is either
2098
	 * {@link #VALID_OPTION valid} or {@link #DEPRECATED_OPTION deprecated},
2099
	 * <code>false</code> otherwise.
2100
	 */
2101
	public boolean knowsOption(String optionName) {
2102
		boolean knownOption = this.optionNames.contains(optionName);
2103
		if (!knownOption) {
2104
			knownOption = this.deprecatedOptions.get(optionName) != null;
2105
		}
2106
		return knownOption;
2107
	}
2108
2109
	/**
2110
	 * Returns the level of the given option.
2111
	 * 
2112
	 * @param optionName The name of the option
2113
	 * @return The level of the option as an int which may have the following
2114
	 * values:
2115
	 * <ul>
2116
	 * <li>{@link #UNKNOWN_OPTION}: the given option is unknown</li>
2117
	 * <li>{@link #DEPRECATED_OPTION}: the given option is deprecated</li>
2118
	 * <li>{@link #VALID_OPTION}: the given option is valid</li>
2119
	 * </ul>
2120
	 */
2121
	public int getOptionLevel(String optionName) {
2122
		if (this.optionNames.contains(optionName)) {
2123
			return VALID_OPTION;
2124
		}
2125
		if (this.deprecatedOptions.get(optionName) != null) {
2126
			return DEPRECATED_OPTION;
2127
		}
2128
		return UNKNOWN_OPTION;
2129
	}
2130
2050
	public Hashtable getOptions() {
2131
	public Hashtable getOptions() {
2051
2132
2052
		// return cached options if already computed
2133
		// return cached options if already computed
Lines 2070-2090 Link Here
2070
			}
2151
			}
2071
		}
2152
		}
2072
2153
2154
		// set deprecated options using preferences service lookup
2155
		Iterator deprecatedEntries = this.deprecatedOptions.entrySet().iterator();
2156
		while (deprecatedEntries.hasNext()) {
2157
			Entry entry = (Entry) deprecatedEntries.next();
2158
			String propertyName = (String) entry.getKey();
2159
			String propertyValue = service.get(propertyName, null, this.preferencesLookup);
2160
			if (propertyValue != null) {
2161
				options.put(propertyName, propertyValue);
2162
				String[] compatibleOptions = (String[]) entry.getValue();
2163
				for (int co=0, length=compatibleOptions.length; co < length; co++) {
2164
					options.put(compatibleOptions[co], propertyValue);
2165
				}
2166
			}
2167
		}
2168
2073
		// get encoding through resource plugin
2169
		// get encoding through resource plugin
2074
		options.put(JavaCore.CORE_ENCODING, JavaCore.getEncoding());
2170
		options.put(JavaCore.CORE_ENCODING, JavaCore.getEncoding());
2075
2171
2076
		// backward compatibility
2172
		// backward compatibility
2077
		addDeprecatedOptions(options);
2173
		addDeprecatedOptions(options);
2078
		try {
2079
			final IEclipsePreferences eclipsePreferences = this.preferencesLookup[PREF_INSTANCE];
2080
			String[] instanceKeys = eclipsePreferences.keys();
2081
			for (int i=0, length=instanceKeys.length; i<length; i++) {
2082
				String optionName = instanceKeys[i];
2083
				migrateObsoleteOption(options, optionName, eclipsePreferences.get(optionName, null));
2084
			}
2085
		} catch (BackingStoreException e) {
2086
			// skip
2087
		}
2088
2174
2089
		Util.fixTaskTags(options);
2175
		Util.fixTaskTags(options);
2090
		// store built map in cache
2176
		// store built map in cache
Lines 2094-2156 Link Here
2094
		return options;
2180
		return options;
2095
	}
2181
	}
2096
2182
2097
	/**
2098
	 * Migrates an old option value to its new corresponding option name(s)
2099
	 * when necessary.
2100
	 * <p>
2101
	 * Nothing is done if the given option is not obsolete or if no migration has been
2102
	 * specified for it.
2103
	 * </p><p>
2104
	 * Currently, migration is only done for formatter options.
2105
	 * </p>
2106
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=308000"
2107
	 * 
2108
	 * @param options The options map to update
2109
	 * @param optionName The old option name to update
2110
	 * @param optionValue The value of the old option name
2111
	 */
2112
	public void migrateObsoleteOption(Map options, String optionName, String optionValue) {
2113
2114
		// Migrate formatter options
2115
		String[] compatibleConstants = getFormatterCompatibleConstants(optionName);
2116
		if (compatibleConstants != null) {
2117
			for (int i=0, length=compatibleConstants.length; i < length; i++) {
2118
				options.put(compatibleConstants[i], optionValue);
2119
			}
2120
			return;
2121
		}
2122
	}
2123
2124
	/**
2125
	 * Return an array of compatible constants for an obsolete constant.
2126
	 * 
2127
	 * @param name The name of the obsolete constant
2128
	 * @return The list as a non-empty array of the compatible constants or
2129
	 * <code>null</code> if the constant is <b>not</b> obsolete.
2130
	 * @deprecated As using deprecated formatter constants
2131
	 */
2132
	private static String[] getFormatterCompatibleConstants(String name) {
2133
		if (DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER.equals(name)) {
2134
			return new String[] {
2135
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
2136
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
2137
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
2138
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE
2139
			};
2140
		}
2141
		if (DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION.equals(name)) {
2142
			return new String[] {
2143
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
2144
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
2145
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
2146
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE,
2147
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE,
2148
				DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER
2149
			};
2150
		}
2151
		return null;
2152
	}
2153
2154
	// Do not modify without modifying getDefaultOptions()
2183
	// Do not modify without modifying getDefaultOptions()
2155
	private Hashtable getDefaultOptionsNoInitialization() {
2184
	private Hashtable getDefaultOptionsNoInitialization() {
2156
		Map defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults
2185
		Map defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults
Lines 4692-4697 Link Here
4692
		}
4721
		}
4693
	}
4722
	}
4694
4723
4724
	/**
4725
	 * Store the preferences value for the given option name.
4726
	 *
4727
	 * @param optionName The name of the option
4728
	 * @param optionValue The value of the option. If <code>null</code>, then
4729
	 * 	the option will be removed from the preferences instead.
4730
	 * @param eclipsePreferences The eclipse preferences to be updated
4731
	 * @return <code>true</code> if the preferences have been changed,
4732
	 * 	<code>false</code> otherwise.
4733
	 */
4734
	public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences) {
4735
		int optionLevel = this.getOptionLevel(optionName);
4736
		if (optionLevel == UNKNOWN_OPTION) return false; // unrecognized option
4737
		
4738
		// Store option value
4739
		switch (optionLevel) {
4740
			case JavaModelManager.VALID_OPTION:
4741
				if (optionValue == null) {
4742
					eclipsePreferences.remove(optionName);
4743
				} else {
4744
					eclipsePreferences.put(optionName, optionValue);
4745
				}
4746
				break;
4747
			case JavaModelManager.DEPRECATED_OPTION:
4748
				// Try to migrate deprecated option
4749
				eclipsePreferences.remove(optionName); // get rid off old preference
4750
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
4751
				for (int co=0, length=compatibleOptions.length; co < length; co++) {
4752
					if (optionValue == null) {
4753
						eclipsePreferences.remove(compatibleOptions[co]);
4754
					} else {
4755
						eclipsePreferences.put(compatibleOptions[co], optionValue);
4756
					}
4757
				}
4758
				break;
4759
			default:
4760
				return false;
4761
		}
4762
		return true;
4763
	}
4764
4695
	public void setOptions(Hashtable newOptions) {
4765
	public void setOptions(Hashtable newOptions) {
4696
		
4766
		
4697
		if (DEBUG_302850) {
4767
		if (DEBUG_302850) {
Lines 4718-4737 Link Here
4718
				Enumeration keys = newOptions.keys();
4788
				Enumeration keys = newOptions.keys();
4719
				while (keys.hasMoreElements()){
4789
				while (keys.hasMoreElements()){
4720
					String key = (String)keys.nextElement();
4790
					String key = (String)keys.nextElement();
4721
					if (!this.optionNames.contains(key)) continue; // unrecognized option
4791
					int optionLevel = getOptionLevel(key);
4792
					if (optionLevel == UNKNOWN_OPTION) continue; // unrecognized option
4722
					if (key.equals(JavaCore.CORE_ENCODING)) {
4793
					if (key.equals(JavaCore.CORE_ENCODING)) {
4723
						if (cachedValue != null) {
4794
						if (cachedValue != null) {
4724
							cachedValue.put(key, JavaCore.getEncoding());
4795
							cachedValue.put(key, JavaCore.getEncoding());
4725
						}
4796
						}
4726
						continue; // skipped, contributed by resource prefs
4797
						continue; // skipped, contributed by resource prefs
4727
					}
4798
					}
4728
					String value = (String)newOptions.get(key);
4799
					String value = (String) newOptions.get(key);
4729
					String defaultValue = defaultPreferences.get(key, null);
4800
					String defaultValue = defaultPreferences.get(key, null);
4801
					// Store value in preferences
4730
					if (defaultValue != null && defaultValue.equals(value)) {
4802
					if (defaultValue != null && defaultValue.equals(value)) {
4731
						instancePreferences.remove(key);
4803
						value = null;
4732
					} else {
4733
						instancePreferences.put(key, value);
4734
					}
4804
					}
4805
					storePreference(key, value, instancePreferences);
4735
				}
4806
				}
4736
				try {
4807
				try {
4737
					// persist options
4808
					// persist options
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-29 / +26 lines)
Lines 1616-1629 Link Here
1616
	 * @see org.eclipse.jdt.core.IJavaProject#getOption(String, boolean)
1616
	 * @see org.eclipse.jdt.core.IJavaProject#getOption(String, boolean)
1617
	 */
1617
	 */
1618
	public String getOption(String optionName, boolean inheritJavaCoreOptions) {
1618
	public String getOption(String optionName, boolean inheritJavaCoreOptions) {
1619
		if (JavaModelManager.getJavaModelManager().optionNames.contains(optionName)){
1619
		return JavaModelManager.getJavaModelManager().getOption(optionName, inheritJavaCoreOptions, getEclipsePreferences());
1620
			IEclipsePreferences projectPreferences = getEclipsePreferences();
1621
			String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null;
1622
			if (projectPreferences == null) return javaCoreDefault;
1623
			String value = projectPreferences.get(optionName, javaCoreDefault);
1624
			return value == null ? null : value.trim();
1625
		}
1626
		return null;
1627
	}
1620
	}
1628
1621
1629
	/**
1622
	/**
Lines 1653-1663 Link Here
1653
					String propertyName = propertyNames[i];
1646
					String propertyName = propertyNames[i];
1654
					String value = projectPreferences.get(propertyName, null);
1647
					String value = projectPreferences.get(propertyName, null);
1655
					if (value != null) {
1648
					if (value != null) {
1656
						if (optionNames.contains(propertyName)){
1649
						value = value.trim();
1657
							projectOptions.put(propertyName, value.trim());
1650
						// Keep the option value, even if it's deprecated
1658
						} else {
1651
						// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987
1659
							// Maybe an obsolete preference, try to migrate it...
1652
						projectOptions.put(propertyName, value);
1660
							javaModelManager.migrateObsoleteOption(projectOptions, propertyName, value.trim());
1653
						if (!optionNames.contains(propertyName)) {
1654
							// try to migrate deprecated options
1655
							String[] compatibleOptions = (String[]) javaModelManager.deprecatedOptions.get(propertyName);
1656
							if (compatibleOptions != null) {
1657
								for (int co=0, length=compatibleOptions.length; co < length; co++) {
1658
									projectOptions.put(compatibleOptions[co], value);
1659
								}
1660
							}
1661
						}
1661
						}
1662
					}
1662
					}
1663
				}
1663
				}
Lines 1677-1683 Link Here
1677
				Map.Entry entry = (Map.Entry) propertyNames.next();
1677
				Map.Entry entry = (Map.Entry) propertyNames.next();
1678
				String propertyName = (String) entry.getKey();
1678
				String propertyName = (String) entry.getKey();
1679
				String propertyValue = (String) entry.getValue();
1679
				String propertyValue = (String) entry.getValue();
1680
				if (propertyValue != null && optionNames.contains(propertyName)){
1680
				if (propertyValue != null && javaModelManager.knowsOption(propertyName)){
1681
					options.put(propertyName, propertyValue.trim());
1681
					options.put(propertyName, propertyValue.trim());
1682
				}
1682
				}
1683
			}
1683
			}
Lines 2878-2897 Link Here
2878
	 * @see org.eclipse.jdt.core.IJavaProject#setOption(java.lang.String, java.lang.String)
2878
	 * @see org.eclipse.jdt.core.IJavaProject#setOption(java.lang.String, java.lang.String)
2879
	 */
2879
	 */
2880
	public void setOption(String optionName, String optionValue) {
2880
	public void setOption(String optionName, String optionValue) {
2881
		if (!JavaModelManager.getJavaModelManager().optionNames.contains(optionName)) return; // unrecognized option
2881
		// Store option value
2882
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2882
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2883
		if (optionValue == null) {
2883
		boolean modified = JavaModelManager.getJavaModelManager().storePreference(optionName, optionValue, projectPreferences);
2884
			// remove preference
2885
			projectPreferences.remove(optionName);
2886
		} else {
2887
			projectPreferences.put(optionName, optionValue);
2888
		}
2889
2884
2890
		// Dump changes
2885
		// Write changes
2891
		try {
2886
		if (modified) {
2892
			projectPreferences.flush();
2887
			try {
2893
		} catch (BackingStoreException e) {
2888
				projectPreferences.flush();
2894
			// problem with pref store - quietly ignore
2889
			} catch (BackingStoreException e) {
2890
				// problem with pref store - quietly ignore
2891
			}
2895
		}
2892
		}
2896
	}
2893
	}
2897
2894
Lines 2907-2918 Link Here
2907
				projectPreferences.clear();
2904
				projectPreferences.clear();
2908
			} else {
2905
			} else {
2909
				Iterator entries = newOptions.entrySet().iterator();
2906
				Iterator entries = newOptions.entrySet().iterator();
2907
				JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager();
2910
				while (entries.hasNext()){
2908
				while (entries.hasNext()){
2911
					Map.Entry entry = (Map.Entry) entries.next();
2909
					Map.Entry entry = (Map.Entry) entries.next();
2912
					String key = (String) entry.getKey();
2910
					String key = (String) entry.getKey();
2913
					if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option
2911
					String value = (String) entry.getValue();
2914
					// no filtering for encoding (custom encoding for project is allowed)
2912
					javaModelManager.storePreference(key, value, projectPreferences);
2915
					projectPreferences.put(key, (String) entry.getValue());
2916
				}
2913
				}
2917
2914
2918
				// reset to default all options not in new map
2915
				// reset to default all options not in new map
(-)src/org/eclipse/jdt/core/tests/model/OptionTests.java (-1 / +193 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 deprecated option is well preserved when a client use it
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.DO_NOT_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 deprecated option is well preserved when a client use it
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.DO_NOT_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