GlobalSearchScope (GlobalSearchScope @NotNull [] scopes) { if (scopes.length == 2) { GlobalSearchScope unionScope = tryCreateUnionFor2Scopes(scopes); if (unionScope != null) return unionScope; } Set<GlobalSearchScope> result = new HashSet<>(scopes.length); Project project = null; for (GlobalSearchScope scope : scopes) { if (scope == EMPTY_SCOPE) continue; Project scopeProject = scope.getProject(); if (scopeProject != null) project = scopeProject; if (scope instanceof UnionScope) { ContainerUtil.addAll(result, ((UnionScope)scope).myScopes); } else { result.add(scope); } } if (result.isEmpty()) return EMPTY_SCOPE; if (result.size() == 1) return result.iterator().next(); return new UnionScope(project, result.toArray(EMPTY_ARRAY)); }