MoveDestination (PsiPackage aPackage, PsiDirectory directory) { final Project project = aPackage.getProject(); final VirtualFile sourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(directory.getVirtualFile()); if (sourceRoot == null) { Messages.showErrorDialog(project, JavaRefactoringBundle.message("destination.directory.does.not.correspond.to.any.package"), JavaRefactoringBundle.message("cannot.move")); return null; } final JavaRefactoringFactory factory = JavaRefactoringFactory.getInstance(project); return myPreserveSourceRoot.isSelected() && myPreserveSourceRoot.isVisible() ? factory.createSourceFolderPreservingMoveDestination(aPackage.getQualifiedName()) : factory.createSourceRootMoveDestination(aPackage.getQualifiedName(), sourceRoot); }