void (PsiElement[] elements, @Nullable PsiDirectory defaultTargetDirectory, Project project) { PsiDirectory targetDirectory; String newName; boolean openInEditor; VirtualFile[] files = Arrays.stream(elements).map(el -> ((PsiFileSystemItem)el).getVirtualFile()).toArray(VirtualFile[]::new); if (ApplicationManager.getApplication().isUnitTestMode()) { targetDirectory = defaultTargetDirectory; newName = null; openInEditor = true; } else { CopyFilesOrDirectoriesDialog dialog = new CopyFilesOrDirectoriesDialog(elements, defaultTargetDirectory, project, false); if (dialog.showAndGet()) { newName = elements.length == 1 ? dialog.getNewName() : null; targetDirectory = dialog.getTargetDirectory(); openInEditor = dialog.isOpenInEditor(); } else { return; } } if (targetDirectory != null) { PsiManager manager = PsiManager.getInstance(project); try { for (VirtualFile file : files) { if (file.isDirectory()) { PsiFileSystemItem psiElement = manager.findDirectory(file); MoveFilesOrDirectoriesUtil.checkIfMoveIntoSelf(psiElement, targetDirectory); } } } catch (IncorrectOperationException e) { CommonRefactoringUtil.showErrorHint(project, null, e.getMessage(), CommonBundle.getErrorTitle(), null); return; } CommandProcessor.getInstance().executeCommand(project, () -> copyImpl(files, newName, targetDirectory, false, openInEditor), RefactoringBundle.message("copy.handler.copy.files.directories"), null); } }