GlobalSearchScope (@NotNull List<? extends OrderEntry> entries) { Set<Module> modulesWithLibrary = new HashSet<>(entries.size()); Set<Module> modulesWithSdk = new HashSet<>(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 = new ArrayList<>(); if (!modulesWithSdk.isEmpty()) { united.add(new ModulesScope(modulesWithSdk, myProject)); united.add(myLibrariesOnlyScope.intersectWith(new LibraryRuntimeClasspathScope(myProject, modulesWithSdk))); } else { united.add(myLibrariesOnlyScope); } if (!modulesWithLibrary.isEmpty()) { united.add(new ModuleWithDependentsScope(myProject, modulesWithLibrary)); } return GlobalSearchScope.union(united.toArray(GlobalSearchScope.EMPTY_ARRAY)); }