Search in sources :

Example 1 with LibraryRuntimeClasspathScope

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;
}
Also used : java.util(java.util) LibraryRuntimeClasspathScope(com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope) ModulesScope(com.intellij.openapi.module.impl.scopes.ModulesScope) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) TObjectHashingStrategy(gnu.trove.TObjectHashingStrategy) ConcurrentMap(java.util.concurrent.ConcurrentMap) JdkScope(com.intellij.openapi.module.impl.scopes.JdkScope) com.intellij.openapi.roots(com.intellij.openapi.roots) DelegatingGlobalSearchScope(com.intellij.psi.search.DelegatingGlobalSearchScope) Nullable(org.jetbrains.annotations.Nullable) ServiceManager(com.intellij.openapi.components.ServiceManager) Project(com.intellij.openapi.project.Project) ConcurrentFactoryMap(com.intellij.util.containers.ConcurrentFactoryMap) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) SdkResolveScopeProvider(com.intellij.psi.SdkResolveScopeProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) 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) DelegatingGlobalSearchScope(com.intellij.psi.search.DelegatingGlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LibraryRuntimeClasspathScope

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));
}
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) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LibraryRuntimeClasspathScope

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()]));
}
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)3 LibraryRuntimeClasspathScope (com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope)3 DelegatingGlobalSearchScope (com.intellij.psi.search.DelegatingGlobalSearchScope)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 NotNull (org.jetbrains.annotations.NotNull)3 ModulesScope (com.intellij.openapi.module.impl.scopes.ModulesScope)2 THashSet (gnu.trove.THashSet)2 ServiceManager (com.intellij.openapi.components.ServiceManager)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 JdkScope (com.intellij.openapi.module.impl.scopes.JdkScope)1 Project (com.intellij.openapi.project.Project)1 com.intellij.openapi.roots (com.intellij.openapi.roots)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 SdkResolveScopeProvider (com.intellij.psi.SdkResolveScopeProvider)1 ConcurrencyUtil (com.intellij.util.ConcurrencyUtil)1 ConcurrentFactoryMap (com.intellij.util.containers.ConcurrentFactoryMap)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 TObjectHashingStrategy (gnu.trove.TObjectHashingStrategy)1 java.util (java.util)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1