PsiDirectory (final PsiDirectory[] directories) { final VirtualFile sourceFile = mySourceClass.getContainingFile().getVirtualFile(); if (sourceFile != null) { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(sourceFile); if (sourceRoot != null) { for (PsiDirectory dir : directories) { if (Comparing.equal(fileIndex.getSourceRootForFile(dir.getVirtualFile()), sourceRoot)) { return dir; } } } } return directories[0]; }