VirtualFile (@NotNull PackageWrapper targetPackage, @NotNull List<? extends VirtualFile> contentSourceRoots, @Nullable PsiDirectory initialDirectory) { Project project = targetPackage.getManager().getProject(); //ensure that there would be no duplicates: e.g. when one content root is subfolder of another root (configured via excluded roots) LinkedHashSet<PsiDirectory> targetDirectories = new LinkedHashSet<>(); Map<PsiDirectory, String> relativePathsToCreate = new HashMap<>(); ActionUtil.underModalProgress(project, JavaRefactoringBundle.message("move.class.or.package.build.directories"), () -> { buildDirectoryList(targetPackage, contentSourceRoots, targetDirectories, relativePathsToCreate); return null; }); PsiDirectory selectedDir = DirectoryChooserUtil.chooseDirectory( targetDirectories.toArray(PsiDirectory.EMPTY_ARRAY), initialDirectory, project, relativePathsToCreate ); return ReadAction.compute(() -> { VirtualFile vDir = selectedDir == null ? null : selectedDir.getVirtualFile(); return vDir == null ? null : ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(vDir); }); }