void (PsiElement[] psiElements, ProjectFileIndex fileIndex, Set<? super VirtualFile> initialRoots) { for (PsiElement element : psiElements) { final VirtualFile file = PsiUtilCore.getVirtualFile(element); if (file != null) { final VirtualFile sourceRootForFile = fileIndex.getSourceRootForFile(file); if (sourceRootForFile != null) { initialRoots.add(sourceRootForFile); } } else if (element instanceof PsiDirectoryContainer) { collectSourceRoots(((PsiDirectoryContainer)element).getDirectories(), fileIndex, initialRoots); } } }