void (PsiElement[] elements, PsiDirectory defaultTargetDirectory) { FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.copyClass"); final HashMap<PsiFile, String> relativePathsMap = new HashMap<>(); final Map<PsiFile, PsiClass[]> classes = convertToTopLevelClasses(elements, false, "", relativePathsMap); assert classes != null; if (defaultTargetDirectory == null) { final PsiFile psiFile = classes.keySet().iterator().next(); defaultTargetDirectory = psiFile.getContainingDirectory(); LOG.assertTrue(defaultTargetDirectory != null, psiFile); } Project project = defaultTargetDirectory.getProject(); if (DumbService.isDumb(project)) { int copyDumb = Messages.showYesNoDialog(project, JavaRefactoringBundle.message("copy.handler.is.dumb.during.indexing"), getActionName(elements), Messages.getQuestionIcon()); if (copyDumb == Messages.YES) { copyAsFiles(elements, defaultTargetDirectory, project); } return; } VirtualFile sourceRootForFile = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(defaultTargetDirectory.getVirtualFile()); if (sourceRootForFile == null) { copyAsFiles(elements, defaultTargetDirectory, project); return; } Object targetDirectory = null; String className = null; boolean openInEditor = true; if (copyOneClass(classes, elements)) { final String commonPath = ArrayUtilRt.find(elements, classes.values().iterator().next()) == -1 ? normalizeRelativeMap(relativePathsMap) : null; CopyClassDialog dialog = new CopyClassDialog(classes.values().iterator().next()[0], defaultTargetDirectory, project, false) { @Override protected String getQualifiedName() { final String qualifiedName = super.getQualifiedName(); if (commonPath != null && !commonPath.isEmpty() && !qualifiedName.endsWith(commonPath)) { return StringUtil.getQualifiedName(qualifiedName, commonPath.replaceAll("/", ".")); } return qualifiedName; } }; dialog.setTitle(JavaRefactoringBundle.message("copy.handler.copy.class")); if (dialog.showAndGet()) { openInEditor = dialog.isOpenInEditor(); targetDirectory = dialog.getTargetDirectory(); className = dialog.getClassName(); if (className == null || className.length() == 0) return; } } else { if (ApplicationManager.getApplication().isUnitTestMode()) { targetDirectory = defaultTargetDirectory; } else { defaultTargetDirectory = CopyFilesOrDirectoriesHandler.resolveDirectory(defaultTargetDirectory); if (defaultTargetDirectory == null) return; PsiFile[] files = PsiUtilCore.toPsiFileArray(classes.keySet()); final CopyFilesOrDirectoriesDialog dialog = new CopyFilesOrDirectoriesDialog(files, defaultTargetDirectory, project, false) { @Override public JComponent getPreferredFocusedComponent() { return files.length == 1 ? getTargetDirectoryComponent() : super.getPreferredFocusedComponent(); } }; if (dialog.showAndGet()) { targetDirectory = dialog.getTargetDirectory(); String newName = dialog.getNewName(); if (files.length == 1) { //strip file extension when multiple classes exist in one file className = StringUtil.trimEnd(newName, "." + getFileExtension(files[0])); } openInEditor = dialog.isOpenInEditor(); } } } if (targetDirectory != null) { copyClassesImpl(className, project, classes, relativePathsMap, targetDirectory, defaultTargetDirectory, JavaRefactoringBundle.message( "copy.handler.copy.class"), false, openInEditor); } }