void (PsiElement element, final Project project, PsiElement nameSuggestionContext, Editor editor) { final PsiDirectory psiDirectory = (PsiDirectory)element; final T aPackage = getPackage(psiDirectory); final String qualifiedName = aPackage != null ? getQualifiedName(aPackage) : ""; if (aPackage == null || qualifiedName.length() == 0/*default package*/ || !isIdentifier(psiDirectory.getName(), project)) { PsiElementRenameHandler.rename(element, project, nameSuggestionContext, editor); } else { PsiDirectory[] directories = aPackage.getDirectories(); final VirtualFile[] virtualFiles = occursInPackagePrefixes(aPackage); if (virtualFiles.length == 0 && directories.length == 1) { PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor); } else { // the directory corresponds to a package that has multiple associated directories PsiDirectory[] projectDirectories = aPackage.getDirectories(GlobalSearchScope.projectScope(project)); if (virtualFiles.length == 0 && projectDirectories.length == 1) { //ignore library packages renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, psiDirectory); return; } final @Nls StringBuffer message = new StringBuffer(); RenameUtil.buildPackagePrefixChangedMessage(virtualFiles, message, qualifiedName); Module module = Objects.requireNonNull(ModuleUtilCore.findModuleForFile(psiDirectory.getVirtualFile(), project)); buildMultipleDirectoriesInPackageMessage(message, getQualifiedName(aPackage), projectDirectories, psiDirectory); PsiDirectory[] moduleDirectories = aPackage.getDirectories(GlobalSearchScope.moduleScope(module)); message.append(RefactoringBundle.message("directories.and.all.references.to.package.will.be.renamed")); List<String> options = new ArrayList<>(); options.add(RefactoringBundle.message("rename.package.button.text")); if (projectDirectories.length > moduleDirectories.length) { options.add(RefactoringBundle.message("rename.directory.button.text")); } if (moduleDirectories.length > 1) { options.add(RefactoringBundle.message("rename.source.root.button.text")); } options.add(CommonBundle.getCancelButtonText()); int ret = Messages.showDialog(project, message.toString(), RefactoringBundle.message("dialog.title.rename.package.directories"), ArrayUtil.toStringArray(options), 0, Messages.getQuestionIcon()); if (ret == 0) { if (directories.length > projectDirectories.length) { renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, projectDirectories); } else { PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor); } } else if (ret == 1) { PsiDirectory[] dirsToRename = projectDirectories.length > moduleDirectories.length ? moduleDirectories : new PsiDirectory[]{psiDirectory}; renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, dirsToRename); } else if (ret == 2 && options.size() > 3) { renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, psiDirectory); } } } }