Search in sources :

Example 1 with MoveClassesOrPackagesProcessor

use of com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor in project smali by JesusFreke.

the class ClassMoveTest method doMove.

private void doMove(String oldQualifiedName, final String newPackage) throws Exception {
    final PsiClass testClass = myJavaFacade.findClass(oldQualifiedName, GlobalSearchScope.allScope(getProject()));
    final List<VirtualFile> contentSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(getProject());
    new MoveClassesOrPackagesProcessor(getProject(), new PsiClass[] { testClass }, new AutocreatingSingleSourceRootMoveDestination(new PackageWrapper(getPsiManager(), newPackage), contentSourceRoots.get(0)), false, false, null).run();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClass(com.intellij.psi.PsiClass) AutocreatingSingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination) MoveClassesOrPackagesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor) PackageWrapper(com.intellij.refactoring.PackageWrapper)

Example 2 with MoveClassesOrPackagesProcessor

use of com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor in project intellij-community by JetBrains.

the class MoveToPackageFix method applyFix.

@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    if (element == null)
        return;
    final PsiFile myFile = element.getContainingFile();
    if (!FileModificationService.getInstance().prepareFileForWrite(myFile))
        return;
    try {
        String error;
        PsiDirectory directory = null;
        try {
            directory = MoveClassesOrPackagesUtil.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;
        }
        new MoveClassesOrPackagesProcessor(project, ((PsiJavaFile) myFile).getClasses(), new SingleSourceRootMoveDestination(PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(directory)), directory), false, false, null).run();
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : SingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination) IncorrectOperationException(com.intellij.util.IncorrectOperationException) MoveClassesOrPackagesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor)

Example 3 with MoveClassesOrPackagesProcessor

use of com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor in project intellij-community by JetBrains.

the class ConfigurationRefactoringsTest method move.

private void move(final PsiElement psiElement, String packageName) {
    VirtualFile pkgFile = mySource.createPackageDir(packageName);
    final PsiDirectory toDir = PsiManager.getInstance(myProject).findDirectory(pkgFile);
    assertNotNull(toDir);
    PackageWrapper wrapper = PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(toDir));
    new MoveClassesOrPackagesProcessor(myProject, new PsiElement[] { psiElement }, new SingleSourceRootMoveDestination(wrapper, toDir), false, false, null).run();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination) PackageWrapper(com.intellij.refactoring.PackageWrapper) MoveClassesOrPackagesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor)

Example 4 with MoveClassesOrPackagesProcessor

use of com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor in project android by JetBrains.

the class AndroidRenameTest method doMovePackage.

private void doMovePackage(String packageName, String newPackageName) throws Exception {
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
    final PsiPackage aPackage = facade.findPackage(packageName);
    final PsiPackage newParentPackage = facade.findPackage(newPackageName);
    assertNotNull(newParentPackage);
    final PsiDirectory[] dirs = newParentPackage.getDirectories();
    assertEquals(dirs.length, 1);
    new MoveClassesOrPackagesProcessor(getProject(), new PsiElement[] { aPackage }, new SingleSourceRootMoveDestination(PackageWrapper.create(newParentPackage), dirs[0]), true, false, null).run();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : SingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination) MoveClassesOrPackagesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor)

Example 5 with MoveClassesOrPackagesProcessor

use of com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor in project intellij-community by JetBrains.

the class MoveClassTest method performAction.

private void performAction(String[] classNames, String newPackageName) throws Exception {
    final PsiClass[] classes = new PsiClass[classNames.length];
    for (int i = 0; i < classes.length; i++) {
        String className = classNames[i];
        classes[i] = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(getProject()));
        assertNotNull("Class " + className + " not found", classes[i]);
    }
    PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName);
    assertNotNull("Package " + newPackageName + " not found", aPackage);
    final PsiDirectory[] dirs = aPackage.getDirectories();
    assertEquals(dirs.length, 1);
    new MoveClassesOrPackagesProcessor(myProject, classes, new SingleSourceRootMoveDestination(PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(dirs[0])), dirs[0]), true, true, null).run();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : SingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination) MoveClassesOrPackagesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor)

Aggregations

MoveClassesOrPackagesProcessor (com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor)9 SingleSourceRootMoveDestination (com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PackageWrapper (com.intellij.refactoring.PackageWrapper)2 PsiClass (com.intellij.psi.PsiClass)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiPackage (com.intellij.psi.PsiPackage)1 AutocreatingSingleSourceRootMoveDestination (com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ArrayList (java.util.ArrayList)1