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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-2 / +6 lines)
Lines 10-15 Link Here
10
 *     Theodora Yeung (tyeung@bea.com) - ensure that JarPackageFragmentRoot make it into cache
10
 *     Theodora Yeung (tyeung@bea.com) - ensure that JarPackageFragmentRoot make it into cache
11
 *                                                           before its contents
11
 *                                                           before its contents
12
 *                                                           (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422)
12
 *                                                           (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422)
13
 *     Stephan Herrmann - Contribution for Bug 346010 - [model] strange initialization dependency in OptionTests
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.internal.core;
15
package org.eclipse.jdt.internal.core;
15
16
Lines 4788-4797 Link Here
4788
	 * @param optionValue The value of the option. If <code>null</code>, then
4789
	 * @param optionValue The value of the option. If <code>null</code>, then
4789
	 * 	the option will be removed from the preferences instead.
4790
	 * 	the option will be removed from the preferences instead.
4790
	 * @param eclipsePreferences The eclipse preferences to be updated
4791
	 * @param eclipsePreferences The eclipse preferences to be updated
4792
	 * @param otherOptions more options being stored, used to avoid conflict between deprecated option and its compatible
4791
	 * @return <code>true</code> if the preferences have been changed,
4793
	 * @return <code>true</code> if the preferences have been changed,
4792
	 * 	<code>false</code> otherwise.
4794
	 * 	<code>false</code> otherwise.
4793
	 */
4795
	 */
4794
	public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences) {
4796
	public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences, Map otherOptions) {
4795
		int optionLevel = this.getOptionLevel(optionName);
4797
		int optionLevel = this.getOptionLevel(optionName);
4796
		if (optionLevel == UNKNOWN_OPTION) return false; // unrecognized option
4798
		if (optionLevel == UNKNOWN_OPTION) return false; // unrecognized option
4797
		
4799
		
Lines 4809-4814 Link Here
4809
				eclipsePreferences.remove(optionName); // get rid off old preference
4811
				eclipsePreferences.remove(optionName); // get rid off old preference
4810
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
4812
				String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
4811
				for (int co=0, length=compatibleOptions.length; co < length; co++) {
4813
				for (int co=0, length=compatibleOptions.length; co < length; co++) {
4814
					if (otherOptions != null && otherOptions.containsKey(compatibleOptions[co]))
4815
						continue; // don't overwrite explicit value of otherOptions at compatibleOptions[co]
4812
					if (optionValue == null) {
4816
					if (optionValue == null) {
4813
						eclipsePreferences.remove(compatibleOptions[co]);
4817
						eclipsePreferences.remove(compatibleOptions[co]);
4814
					} else {
4818
					} else {
Lines 4862-4868 Link Here
4862
					if (defaultValue != null && defaultValue.equals(value)) {
4866
					if (defaultValue != null && defaultValue.equals(value)) {
4863
						value = null;
4867
						value = null;
4864
					}
4868
					}
4865
					storePreference(key, value, instancePreferences);
4869
					storePreference(key, value, instancePreferences, newOptions);
4866
				}
4870
				}
4867
				try {
4871
				try {
4868
					// persist options
4872
					// persist options
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-3 / +5 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - inconsistent initialization of classpath container backed by external class folder, see https://bugs.eclipse.org/320618
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for
11
 *     						Bug 320618 - inconsistent initialization of classpath container backed by external class folder
12
 *     						Bug 346010 - [model] strange initialization dependency in OptionTests
11
 *******************************************************************************/
13
 *******************************************************************************/
12
package org.eclipse.jdt.internal.core;
14
package org.eclipse.jdt.internal.core;
13
15
Lines 2928-2934 Link Here
2928
	public void setOption(String optionName, String optionValue) {
2930
	public void setOption(String optionName, String optionValue) {
2929
		// Store option value
2931
		// Store option value
2930
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2932
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2931
		boolean modified = JavaModelManager.getJavaModelManager().storePreference(optionName, optionValue, projectPreferences);
2933
		boolean modified = JavaModelManager.getJavaModelManager().storePreference(optionName, optionValue, projectPreferences, null);
2932
2934
2933
		// Write changes
2935
		// Write changes
2934
		if (modified) {
2936
		if (modified) {
Lines 2957-2963 Link Here
2957
					Map.Entry entry = (Map.Entry) entries.next();
2959
					Map.Entry entry = (Map.Entry) entries.next();
2958
					String key = (String) entry.getKey();
2960
					String key = (String) entry.getKey();
2959
					String value = (String) entry.getValue();
2961
					String value = (String) entry.getValue();
2960
					javaModelManager.storePreference(key, value, projectPreferences);
2962
					javaModelManager.storePreference(key, value, projectPreferences, newOptions);
2961
				}
2963
				}
2962
2964
2963
				// reset to default all options not in new map
2965
				// reset to default all options not in new map
(-)src/org/eclipse/jdt/core/tests/model/OptionTests.java (+62 lines)
Lines 7-17 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for Bug 346010 - [model] strange initialization dependency in OptionTests
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
12
package org.eclipse.jdt.core.tests.model;
12
13
14
import java.util.ArrayList;
15
import java.util.HashSet;
13
import java.util.Hashtable;
16
import java.util.Hashtable;
17
import java.util.Iterator;
18
import java.util.List;
14
import java.util.Map;
19
import java.util.Map;
20
import java.util.Set;
15
21
16
import junit.framework.Test;
22
import junit.framework.Test;
17
23
Lines 43-48 Link Here
43
	super(name);
49
	super(name);
44
}
50
}
45
static {
51
static {
52
//	TESTS_NAMES = new String[] {    "testBug346010" };
46
//		TESTS_NUMBERS = new int[] { 125360 };
53
//		TESTS_NUMBERS = new int[] { 125360 };
47
//		TESTS_RANGE = new int[] { 4, -1 };
54
//		TESTS_RANGE = new int[] { 4, -1 };
48
}
55
}
Lines 758-763 Link Here
758
	}
765
	}
759
}
766
}
760
/**
767
/**
768
 * @bug 346010 - [model] strange initialization dependency in OptionTests
769
 * @test Verify that unfortunate order of map entries doesn't spoil intended semantics.
770
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=346010"
771
 * @deprecated As using deprecated constants
772
 */
773
public void testBug346010() throws CoreException {
774
	class ForcedOrderMap extends Hashtable {
775
		private static final long serialVersionUID = 8012963985718522218L;
776
		Map original;
777
		Map.Entry additionalEntry;
778
		/* Force (additionalKey,additionalValue) to be served after all entries of original. */
779
		public ForcedOrderMap(Map original, String additionalKey, String additionalValue) {
780
			this.original = original;
781
			// convert additionalKey->additionalValue to a Map.Entry without inserting into original:
782
			Hashtable tmp = new Hashtable();
783
			tmp.put(additionalKey, additionalValue);
784
			this.additionalEntry = (Map.Entry) tmp.entrySet().iterator().next();
785
		}
786
		public Set entrySet() {
787
			return new HashSet() {
788
				private static final long serialVersionUID = 1L;
789
				public Iterator iterator() {
790
					List orderedEntries;
791
					orderedEntries = new ArrayList(ForcedOrderMap.this.original.entrySet());
792
					orderedEntries.add(ForcedOrderMap.this.additionalEntry);
793
					return orderedEntries.iterator();
794
				}
795
			};
796
		}
797
		public synchronized boolean containsKey(Object key) {
798
			return this.original.containsKey(key) || key.equals(this.additionalEntry.getKey());
799
		}
800
	}
801
	try {
802
		// Set the obsolete option using the IJavaProject API
803
		JavaProject project = (JavaProject) createJavaProject("P");
804
		final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER;
805
		Map testOptions = project.getOptions(true);
806
		Map orderedOptions = new ForcedOrderMap(testOptions, obsoleteOption, JavaCore.DO_NOT_INSERT);
807
		project.setOptions(orderedOptions);
808
		// Verify that obsolete preference is not stored
809
		assertNull(
810
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
811
				project.getEclipsePreferences().get(obsoleteOption, null));
812
		// Verify that project obsolete option is well retrieved
813
		assertEquals(
814
				"Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", 
815
				JavaCore.INSERT,
816
				project.getOption(obsoleteOption, true));
817
	} finally {
818
		deleteProject("P");
819
	}
820
}
821
822
/**
761
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
823
 * @bug 324987: [formatter] API compatibility problem with Annotation Newline options
762
 * @test Verify that a deprecated option is well preserved when read through
824
 * @test Verify that a deprecated option is well preserved when read through
763
 * 		the IEclipsePreferences (i.e. simulate reading project preferences of a project
825
 * 		the IEclipsePreferences (i.e. simulate reading project preferences of a project

Return to bug 346010