Search in sources :

Example 1 with ModulesScope

use of com.intellij.openapi.module.impl.scopes.ModulesScope 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()]));
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DelegatingGlobalSearchScope(com.intellij.psi.search.DelegatingGlobalSearchScope) LibraryRuntimeClasspathScope(com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope) Module(com.intellij.openapi.module.Module) ModulesScope(com.intellij.openapi.module.impl.scopes.ModulesScope) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Module (com.intellij.openapi.module.Module)1 LibraryRuntimeClasspathScope (com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope)1 ModulesScope (com.intellij.openapi.module.impl.scopes.ModulesScope)1 DelegatingGlobalSearchScope (com.intellij.psi.search.DelegatingGlobalSearchScope)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 THashSet (gnu.trove.THashSet)1 NotNull (org.jetbrains.annotations.NotNull)1