com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor Java Examples

The following examples show how to use com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HaxeMoveTest.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private void doTest(final String[] toMove, final String targetDirName) throws Exception {
  doTest(new PerformAction() {
    @Override
    public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
      Collection<PsiElement> files = new ArrayList<PsiElement>();
      for (String s : toMove) {
        final VirtualFile child = VfsUtil.findRelativeFile(s, rootDir);
        assertNotNull("Neither class nor file " + s + " not found", child);
        PsiElement file = myPsiManager.findFile(child);
        if (file == null) file = JavaPsiFacade.getInstance(myProject).findPackage(s);
        files.add(file);
      }
      final VirtualFile child1 = VfsUtil.findRelativeFile(targetDirName, rootDir);
      assertNotNull("Target dir " + targetDirName + " not found", child1);
      final PsiDirectory targetDirectory = myPsiManager.findDirectory(child1);
      assertNotNull(targetDirectory);

      if (files.iterator().next() instanceof PsiFile) {
        new MoveFilesOrDirectoriesProcessor(myProject, PsiUtilCore.toPsiElementArray(files), targetDirectory,
                                            false, false, null, null).run();
      }
      else if (files.iterator().next() instanceof PsiPackage) {
        PsiPackage newParentPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(targetDirName);
        assertNotNull(newParentPackage);
        final PsiDirectory[] dirs = newParentPackage.getDirectories();
        assertEquals(dirs.length, 1);

        new MoveClassesOrPackagesProcessor(myProject, PsiUtilCore.toPsiElementArray(files),
                                           new SingleSourceRootMoveDestination(PackageWrapper.create(newParentPackage),
                                                                               newParentPackage.getDirectories()[0]),
                                           true, true, null).run();
      }
      FileDocumentManager.getInstance().saveAllDocuments();
    }
  });
}