Search in sources :

Example 6 with MoveClassesOrPackagesProcessor

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

the class MovePackageTest method performAction.

private void performAction(String[] packageNames, String newPackageName) throws Exception {
    final PsiPackage[] packages = new PsiPackage[packageNames.length];
    for (int i = 0; i < packages.length; i++) {
        String packageName = packageNames[i];
        packages[i] = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(packageName);
        assertNotNull("Package " + packageName + " not found", packages[i]);
    }
    PsiPackage newParentPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName);
    assertNotNull(newParentPackage);
    final PsiDirectory[] dirs = newParentPackage.getDirectories();
    assertEquals(dirs.length, 1);
    new MoveClassesOrPackagesProcessor(myProject, packages, new SingleSourceRootMoveDestination(PackageWrapper.create(newParentPackage), dirs[0]), true, false, null).run();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) SingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination) PsiPackage(com.intellij.psi.PsiPackage) MoveClassesOrPackagesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor)

Example 7 with MoveClassesOrPackagesProcessor

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

the class GroovyMoveScriptTest method performAction.

private void performAction(String[] fileNames, String newDirName, String dir) {
    final PsiFile[] files = new PsiFile[fileNames.length];
    for (int i = 0; i < files.length; i++) {
        String fileName = fileNames[i];
        final VirtualFile file = myFixture.getTempDirFixture().getFile(dir + "/" + fileName);
        assertNotNull("File " + fileName + " not found", file);
        files[i] = PsiManager.getInstance(getProject()).findFile(file);
        assertNotNull("File " + fileName + " not found", files[i]);
    }
    final VirtualFile virDir = myFixture.getTempDirFixture().getFile(dir + "/" + newDirName);
    assertNotNull("Directory " + newDirName + " not found", virDir);
    final PsiDirectory psiDirectory = PsiManager.getInstance(getProject()).findDirectory(virDir);
    assertNotNull("Directory " + newDirName + " not found", psiDirectory);
    final PsiPackage pkg = JavaDirectoryService.getInstance().getPackage(psiDirectory);
    List<PsiClass> classList = new ArrayList<>();
    for (PsiFile file : files) {
        Collections.addAll(classList, ((PsiClassOwner) file).getClasses());
    }
    final PsiClass[] classes = classList.toArray(new PsiClass[classList.size()]);
    new MoveClassesOrPackagesProcessor(getProject(), classes, new SingleSourceRootMoveDestination(PackageWrapper.create(pkg), psiDirectory), true, true, null).run();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : ArrayList(java.util.ArrayList) MoveClassesOrPackagesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor) SingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination)

Example 8 with MoveClassesOrPackagesProcessor

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

the class AndroidRenameTest method doMoveClass.

private void doMoveClass(String className, String newParentPackageName) throws Exception {
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
    final PsiClass psiClass = facade.findClass(className, GlobalSearchScope.projectScope(getProject()));
    final PsiPackage newParentPackage = facade.findPackage(newParentPackageName);
    assertNotNull(newParentPackage);
    final PsiDirectory[] dirs = newParentPackage.getDirectories();
    assertEquals(dirs.length, 1);
    new MoveClassesOrPackagesProcessor(getProject(), new PsiElement[] { psiClass }, 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 9 with MoveClassesOrPackagesProcessor

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

the class AndroidRenameTest method moveClass.

private void moveClass(final String className, final String newPackageName) throws Throwable {
    PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass(className, GlobalSearchScope.projectScope(getProject()));
    PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage(newPackageName);
    assertNotNull(aPackage);
    final PsiDirectory[] dirs = aPackage.getDirectories();
    assertEquals(dirs.length, 1);
    new MoveClassesOrPackagesProcessor(getProject(), new PsiElement[] { aClass }, new SingleSourceRootMoveDestination(PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(dirs[0])), dirs[0]), true, true, null).run();
}
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