StreamEx<GlobalSearchScope> (Module module) { // Try search in narrow scopes first return StreamEx.<Supplier<GlobalSearchScope>>of( () -> GlobalSearchScope.EMPTY_SCOPE, () -> module.getModuleScope(false), module::getModuleWithDependenciesScope, () -> { GlobalSearchScope[] scopes = ContainerUtil.map2Array(ModuleUtilCore.getAllDependentModules(module), GlobalSearchScope.EMPTY_ARRAY, Module::getModuleContentWithDependenciesScope); return scopes.length == 0 ? GlobalSearchScope.EMPTY_SCOPE : GlobalSearchScope.union(scopes); }, () -> GlobalSearchScopesCore.projectProductionScope(module.getProject()) ).takeWhile(supplier -> !module.isDisposed()) .map(Supplier::get) .pairMap((prev, next) -> next.intersectWith(GlobalSearchScope.notScope(prev))); }