Set<GlobalSearchScope> (List<? extends DependenciesBuilder> builders, List<? extends GlobalSearchScope> scopes) { Set<GlobalSearchScope> usedScopes = new LinkedHashSet<>(); for (DependenciesBuilder builder : builders) { for (Set<PsiFile> files : builder.getDependencies().values()) { for (PsiFile file : files) { VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { for (GlobalSearchScope scope : scopes) { if (scope.contains(virtualFile)) { usedScopes.add(scope); } } } } } } return usedScopes; }