void (@NotNull Project project, @NotNull PsiFile file, @Nullable Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { PsiFile myFile = startElement.getContainingFile(); if (!FileModificationService.getInstance().prepareFileForWrite(myFile)) return; try { String error; PsiDirectory directory = null; try { directory = CommonMoveClassesOrPackagesUtil.chooseDestinationPackage(project, myTargetPackage, myFile.getContainingDirectory()); if (directory == null) { return; } error = RefactoringMessageUtil.checkCanCreateFile(directory, myFile.getName()); } catch (IncorrectOperationException e) { error = e.getLocalizedMessage(); } if (error != null) { Messages.showMessageDialog(project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } SingleSourceRootMoveDestination moveDestination = new SingleSourceRootMoveDestination(PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(directory)), directory); JavaRefactoringFactory.getInstance(project) .createMoveClassesOrPackages(((PsiJavaFile) myFile).getClasses(), moveDestination, false, false).run(); } catch (IncorrectOperationException e) { LOG.error(e); } }