private void chooseDirectoryAndMove(Project project, PsiFile myFile) { try { PsiDirectory directory = MoveClassesOrPackagesUtil.chooseDestinationPackage(project, myTargetPackage, null); if (directory == null) { return; } String error = RefactoringMessageUtil.checkCanCreateFile(directory, myFile.getName()); if (error != null) { Messages.showMessageDialog( project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } new MoveClassesOrPackagesProcessor( project, new PsiElement[] {((PsiJavaFile) myFile).getClasses()[0]}, new SingleSourceRootMoveDestination( PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(directory)), directory), false, false, null) .run(); } catch (IncorrectOperationException e) { LOG.error(e); } }
@Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { if (!(file instanceof GroovyFile)) return; VirtualFile vfile = file.getVirtualFile(); if (vfile == null) return; final Module module = ModuleUtilCore.findModuleForFile(vfile, project); if (module == null) return; final String packageName = ((GroovyFile) file).getPackageName(); PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, null, true); if (directory == null) return; String error = RefactoringMessageUtil.checkCanCreateFile(directory, file.getName()); if (error != null) { Messages.showMessageDialog( project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } new MoveFilesOrDirectoriesProcessor( project, new PsiElement[] {file}, directory, false, false, false, null, null) .run(); }