Skip to content

Commit 05d3333

Browse files
committed
Ensure consistent order of calculated use-clause
Currently the implementation for calculating uses uses a HashSet to collect all used packages. This leads to unstable behavior if the same cleanup is applied multiple times. This now uses a TreeSet instead to ensure lexicographic order is used.
1 parent 23a8400 commit 05d3333

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/CalculateUsesAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
package org.eclipse.pde.internal.ui.search.dependencies;
1515

1616
import java.lang.reflect.InvocationTargetException;
17-
import java.util.HashSet;
1817
import java.util.Map;
18+
import java.util.Set;
1919

2020
import org.eclipse.core.resources.IProject;
2121
import org.eclipse.core.resources.WorkspaceJob;
@@ -70,7 +70,7 @@ protected CalculateUsesOperation getOperation() {
7070
return new CalculateUsesOperation(fProject, fModel) {
7171

7272
@Override
73-
protected void handleSetUsesDirectives(final Map<String, HashSet<String>> pkgsAndUses) {
73+
protected void handleSetUsesDirectives(final Map<String, Set<String>> pkgsAndUses) {
7474
Display.getDefault().asyncExec(() -> {
7575
if (pkgsAndUses.isEmpty()) {
7676
return;

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/CalculateUsesOperation.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import java.util.Collection;
2020
import java.util.Collections;
2121
import java.util.HashMap;
22-
import java.util.HashSet;
2322
import java.util.Iterator;
2423
import java.util.Map;
2524
import java.util.Set;
25+
import java.util.TreeSet;
2626

2727
import org.eclipse.core.resources.IProject;
2828
import org.eclipse.core.runtime.CoreException;
@@ -66,7 +66,7 @@ protected void execute(IProgressMonitor monitor) throws CoreException, Invocatio
6666
if (packages.isEmpty()) {
6767
return;
6868
}
69-
Map<String, HashSet<String>> pkgsAndUses = findPackageReferences(packages, monitor);
69+
Map<String, Set<String>> pkgsAndUses = findPackageReferences(packages, monitor);
7070
if (monitor.isCanceled()) {
7171
return;
7272
}
@@ -94,9 +94,9 @@ protected Collection<String> getPublicExportedPackages() {
9494
return list;
9595
}
9696

97-
protected Map<String, HashSet<String>> findPackageReferences(Collection<String> packages, IProgressMonitor monitor) {
97+
protected Map<String, Set<String>> findPackageReferences(Collection<String> packages, IProgressMonitor monitor) {
9898
IJavaProject jp = JavaCore.create(fProject);
99-
HashMap<String, HashSet<String>> pkgsAndUses = new HashMap<>();
99+
Map<String, Set<String>> pkgsAndUses = new HashMap<>();
100100
IPackageFragment[] frags = PDEJavaHelper.getPackageFragments(jp, Collections.emptySet(), false);
101101
SubMonitor subMonitor = SubMonitor.convert(monitor, frags.length * 2);
102102
for (IPackageFragment fragment : frags) {
@@ -107,11 +107,11 @@ protected Map<String, HashSet<String>> findPackageReferences(Collection<String>
107107
iterationMonitor.subTask(
108108
NLS.bind(PDEUIMessages.CalculateUsesOperation_calculatingDirective, fragment.getElementName()));
109109
if (packages.contains(fragment.getElementName())) {
110-
HashSet<String> pkgs = new HashSet<>();
110+
Set<String> pkgs = new TreeSet<>();
111111
pkgsAndUses.put(fragment.getElementName(), pkgs);
112112
try {
113113
findReferences(fragment.getCompilationUnits(), pkgs, iterationMonitor.split(1), false);
114-
findReferences(fragment.getClassFiles(), pkgs, iterationMonitor.split(1), true);
114+
findReferences(fragment.getOrdinaryClassFiles(), pkgs, iterationMonitor.split(1), true);
115115
} catch (JavaModelException e) {
116116
}
117117
}
@@ -205,14 +205,14 @@ protected final void addPackages(String[] typeSignatures, Set<String> pkgs, ITyp
205205
}
206206
}
207207

208-
protected void handleSetUsesDirectives(Map<String, HashSet<String>> pkgsAndUses) {
208+
protected void handleSetUsesDirectives(Map<String, Set<String>> pkgsAndUses) {
209209
if (pkgsAndUses.isEmpty()) {
210210
return;
211211
}
212212
setUsesDirectives(pkgsAndUses);
213213
}
214214

215-
protected void setUsesDirectives(Map<String, HashSet<String>> pkgsAndUses) {
215+
protected void setUsesDirectives(Map<String, Set<String>> pkgsAndUses) {
216216
IBundle bundle = fModel.getBundleModel().getBundle();
217217
IManifestHeader header = bundle.getManifestHeader(Constants.EXPORT_PACKAGE);
218218
// header will not equal null b/c we would not get this far (ie. no exported packages so we would have returned earlier
@@ -226,7 +226,7 @@ protected void setUsesDirectives(Map<String, HashSet<String>> pkgsAndUses) {
226226
}
227227
}
228228

229-
protected String getDirectiveValue(String pkgName, Map<String, HashSet<String>> pkgsAndUses) {
229+
protected String getDirectiveValue(String pkgName, Map<String, Set<String>> pkgsAndUses) {
230230
Set<String> usesPkgs = pkgsAndUses.get(pkgName);
231231
usesPkgs.remove(pkgName);
232232
StringBuilder buffer = null;

0 commit comments

Comments
 (0)