diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeMap.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeMap.java index 447fb9c0bce..1e01bad6560 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeMap.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeMap.java @@ -13,9 +13,9 @@ package org.eclipse.cdt.internal.ui.refactoring.includes; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -34,11 +34,12 @@ public class IncludeMap { private static final String TAG_VALUE = "value"; //$NON-NLS-1$ private final boolean unconditionalSubstitution; // Not serialized when saving to a memento. - private final Map> map; + // The order is not crucial but can make a difference when calculating transitive closure. + private final LinkedHashMap> map; public IncludeMap(boolean unconditionalSubstitution) { this.unconditionalSubstitution = unconditionalSubstitution; - this.map = new HashMap>(); + this.map = new LinkedHashMap>(); } /** @@ -50,7 +51,7 @@ public class IncludeMap { if (keysAndValues.length % 2 != 0) throw new IllegalArgumentException("More keys than values"); //$NON-NLS-1$ this.unconditionalSubstitution = unconditionalSubstitution; - this.map = new HashMap>(keysAndValues.length / 2); + this.map = new LinkedHashMap>(keysAndValues.length / 2); for (int i = 0; i < keysAndValues.length;) { String key = keysAndValues[i++]; addMapping(key, keysAndValues[i++]); @@ -59,7 +60,7 @@ public class IncludeMap { public IncludeMap(IncludeMap other) { this.unconditionalSubstitution = other.unconditionalSubstitution; - this.map = new HashMap>(other.map.size()); + this.map = new LinkedHashMap>(other.map.size()); addAllMappings(other); } @@ -157,11 +158,12 @@ public class IncludeMap { * Writes the map to a memento. The {@link #isUnconditionalSubstitution()} flag is not written. */ public void saveToMemento(IMemento memento) { - for (Entry> entry : map.entrySet()) { - String key = entry.getKey().toString(); - for (IncludeInfo value : entry.getValue()) { + List keys = new ArrayList(map.keySet()); + Collections.sort(keys); + for (IncludeInfo key : keys) { + for (IncludeInfo value : map.get(key)) { IMemento mapping = memento.createChild(TAG_MAPPING); - mapping.putString(TAG_KEY, key); + mapping.putString(TAG_KEY, key.toString()); mapping.putString(TAG_VALUE, value.toString()); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/SymbolExportMap.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/SymbolExportMap.java index b098ee433b0..6c9695590f1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/SymbolExportMap.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/SymbolExportMap.java @@ -26,6 +26,8 @@ import org.eclipse.ui.IMemento; import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.XMLMemento; +import com.ibm.icu.text.Collator; + import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.corext.codemanipulation.IncludeInfo; @@ -39,6 +41,7 @@ public class SymbolExportMap { private static final String TAG_MAPPING = "mapping"; //$NON-NLS-1$ private static final String TAG_KEY = "key"; //$NON-NLS-1$ private static final String TAG_VALUE = "value"; //$NON-NLS-1$ + private static final Collator COLLATOR = Collator.getInstance(); private final Map> map; @@ -124,9 +127,12 @@ public class SymbolExportMap { * Writes the map to a memento. */ public void saveToMemento(IMemento memento) { - for (Entry> entry : map.entrySet()) { - String key = entry.getKey().toString(); - for (IncludeInfo value : entry.getValue()) { + List keys = new ArrayList(map.keySet()); + Collections.sort(keys, COLLATOR); + for (String key : keys) { + List values = new ArrayList(map.get(key)); + Collections.sort(values); + for (IncludeInfo value : values) { IMemento mapping = memento.createChild(TAG_MAPPING); mapping.putString(TAG_KEY, key); mapping.putString(TAG_VALUE, value.toString());