use of com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope in project intellij-community by JetBrains.
the class LibraryScopeCache method calcLibraryScope.
@NotNull
private GlobalSearchScope calcLibraryScope(@NotNull List<OrderEntry> orderEntries) {
List<Module> modulesLibraryUsedIn = new ArrayList<>();
LibraryOrderEntry lib = null;
for (OrderEntry entry : orderEntries) {
if (entry instanceof JdkOrderEntry) {
return getScopeForSdk((JdkOrderEntry) entry);
}
if (entry instanceof LibraryOrderEntry) {
lib = (LibraryOrderEntry) entry;
modulesLibraryUsedIn.add(entry.getOwnerModule());
} else if (entry instanceof ModuleOrderEntry) {
modulesLibraryUsedIn.add(entry.getOwnerModule());
}
}
Comparator<Module> comparator = (o1, o2) -> o1.getName().compareTo(o2.getName());
Collections.sort(modulesLibraryUsedIn, comparator);
List<Module> uniquesList = ContainerUtil.removeDuplicatesFromSorted(modulesLibraryUsedIn, comparator);
GlobalSearchScope allCandidates = uniquesList.isEmpty() ? myLibrariesOnlyScope : getScopeForLibraryUsedIn(uniquesList);
if (lib != null) {
final LibraryRuntimeClasspathScope preferred = new LibraryRuntimeClasspathScope(myProject, lib);
// prefer current library
return new DelegatingGlobalSearchScope(allCandidates, preferred) {
@Override
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
boolean c1 = preferred.contains(file1);
boolean c2 = preferred.contains(file2);
if (c1 && !c2)
return 1;
if (c2 && !c1)
return -1;
return super.compare(file1, file2);
}
};
}
return allCandidates;
}
use of com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope in project intellij-community by JetBrains.
the class LibraryScopeCache method getScopeForLibraryUsedIn.
@NotNull
private GlobalSearchScope getScopeForLibraryUsedIn(@NotNull List<Module> modulesLibraryIsUsedIn) {
Module[] array = modulesLibraryIsUsedIn.toArray(Module.EMPTY_ARRAY);
GlobalSearchScope scope = myLibraryScopes.get(array);
return scope != null ? scope : ConcurrencyUtil.cacheOrGet(myLibraryScopes, array, new LibraryRuntimeClasspathScope(myProject, modulesLibraryIsUsedIn));
}
use of com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope in project intellij-community by JetBrains.
the class LibraryScopeCache method calcLibraryUseScope.
@NotNull
private GlobalSearchScope calcLibraryUseScope(@NotNull List<OrderEntry> entries) {
Set<Module> modulesWithLibrary = new THashSet<>(entries.size());
Set<Module> modulesWithSdk = new THashSet<>(entries.size());
for (OrderEntry entry : entries) {
(entry instanceof JdkOrderEntry ? modulesWithSdk : modulesWithLibrary).add(entry.getOwnerModule());
}
modulesWithSdk.removeAll(modulesWithLibrary);
// optimisation: if the library attached to all modules (often the case with JDK) then replace the 'union of all modules' scope with just 'project'
if (modulesWithSdk.size() + modulesWithLibrary.size() == ModuleManager.getInstance(myProject).getModules().length) {
return GlobalSearchScope.allScope(myProject);
}
List<GlobalSearchScope> united = ContainerUtil.newArrayList();
if (!modulesWithSdk.isEmpty()) {
united.add(new ModulesScope(modulesWithSdk, myProject));
united.add(myLibrariesOnlyScope.intersectWith(new LibraryRuntimeClasspathScope(myProject, modulesWithSdk)));
} else {
united.add(myLibrariesOnlyScope);
}
for (Module module : modulesWithLibrary) {
united.add(GlobalSearchScope.moduleWithDependentsScope(module));
}
return GlobalSearchScope.union(united.toArray(new GlobalSearchScope[united.size()]));
}
Aggregations