|
94 | 94 | import java.lang.ref.WeakReference; |
95 | 95 | import java.net.URI; |
96 | 96 | import java.nio.CharBuffer; |
| 97 | +import java.util.ArrayList; |
97 | 98 | import java.util.Arrays; |
98 | 99 | import java.util.Collection; |
99 | 100 | import java.util.Collections; |
|
163 | 164 | import org.openide.util.NbCollections; |
164 | 165 | import org.openide.util.WeakListeners; |
165 | 166 | import org.openide.util.lookup.ServiceProvider; |
166 | | - |
167 | | -import static com.sun.source.tree.CaseTree.CaseKind.STATEMENT; |
168 | 167 | import org.netbeans.api.annotations.common.NullAllowed; |
169 | 168 | import org.netbeans.modules.java.hints.providers.spi.HintMetadata; |
170 | 169 | import org.netbeans.modules.refactoring.spi.ui.RefactoringUI; |
|
175 | 174 | import org.openide.util.Parameters; |
176 | 175 | import org.openide.windows.TopComponent; |
177 | 176 |
|
| 177 | +import static com.sun.source.tree.CaseTree.CaseKind.STATEMENT; |
| 178 | + |
178 | 179 | /** |
179 | 180 | * |
180 | 181 | * @author Jan Lahoda |
@@ -288,32 +289,36 @@ public static List<HintDescription> listAllHints(Set<ClassPath> cps) { |
288 | 289 | } |
289 | 290 |
|
290 | 291 | public static List<HintDescription> listClassPathHints(Set<ClassPath> sourceCPs, Set<ClassPath> binaryCPs) { |
291 | | - List<HintDescription> result = new LinkedList<>(); |
292 | | - Set<FileObject> roots = new HashSet<>(); |
293 | 292 |
|
| 293 | + // deduplicate before running queries |
| 294 | + Set<FileObject> unique = new HashSet<>(128); |
294 | 295 | for (ClassPath cp : binaryCPs) { |
295 | | - for (FileObject r : cp.getRoots()) { |
296 | | - Result2 src = SourceForBinaryQuery.findSourceRoots2(r.toURL()); |
| 296 | + unique.addAll(Arrays.asList(cp.getRoots())); |
| 297 | + } |
297 | 298 |
|
298 | | - if (src != null && src.preferSources()) { |
299 | | - roots.addAll(Arrays.asList(src.getRoots())); |
300 | | - } else { |
301 | | - roots.add(r); |
302 | | - } |
| 299 | + Set<FileObject> roots = new HashSet<>(); |
| 300 | + |
| 301 | + for (FileObject fo : unique) { |
| 302 | + Result2 src = SourceForBinaryQuery.findSourceRoots2(fo.toURL()); |
| 303 | + if (src != null && src.preferSources()) { |
| 304 | + roots.addAll(Arrays.asList(src.getRoots())); |
| 305 | + } else { |
| 306 | + roots.add(fo); |
303 | 307 | } |
304 | 308 | } |
305 | 309 |
|
306 | 310 | Set<ClassPath> cps = new HashSet<>(sourceCPs); |
307 | | - |
308 | 311 | cps.add(ClassPathSupport.createClassPath(roots.toArray(FileObject[]::new))); |
309 | 312 |
|
310 | 313 | ClassPath cp = ClassPathSupport.createProxyClassPath(cps.toArray(ClassPath[]::new)); |
311 | 314 |
|
312 | | - for (ClassPathBasedHintProvider p : Lookup.getDefault().lookupAll(ClassPathBasedHintProvider.class)) { |
313 | | - result.addAll(p.computeHints(cp, new AtomicBoolean())); |
| 315 | + List<HintDescription> descriptions = new ArrayList<>(); |
| 316 | + |
| 317 | + for (ClassPathBasedHintProvider prov : Lookup.getDefault().lookupAll(ClassPathBasedHintProvider.class)) { |
| 318 | + descriptions.addAll(prov.computeHints(cp, new AtomicBoolean())); |
314 | 319 | } |
315 | 320 |
|
316 | | - return result; |
| 321 | + return descriptions; |
317 | 322 | } |
318 | 323 |
|
319 | 324 | public static Tree parseAndAttribute(CompilationInfo info, String pattern, Scope scope) { |
|
0 commit comments