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 |