PsiDirectory (@NotNull Project project, PsiDirectory @NotNull [] packageDirectories, @Nullable PsiDirectory defaultDirectory, @Nullable String postfixToShow) { ProjectFileIndex projectFileIndex = getInstance(project).getFileIndex(); List<PsiDirectory> possibleDirs = new ArrayList<>(); for (PsiDirectory dir : packageDirectories) { if (!dir.isValid() || !dir.isWritable() || possibleDirs.contains(dir) || !projectFileIndex.isInContent(dir.getVirtualFile())) { continue; } possibleDirs.add(dir); } if (possibleDirs.isEmpty()) return null; if (possibleDirs.size() == 1) return possibleDirs.get(0); if (getApplication().isUnitTestMode()) return possibleDirs.get(0); DirectoryChooser chooser = new DirectoryChooser(project); chooser.setTitle(message("title.choose.destination.directory")); chooser.fillList(possibleDirs.toArray(PsiDirectory.EMPTY_ARRAY), defaultDirectory, project, postfixToShow); return chooser.showAndGet() ? chooser.getSelectedDirectory() : null; }