Search in sources :

Example 1 with AutocreatingSingleSourceRootMoveDestination

use of com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination 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 AutocreatingSingleSourceRootMoveDestination

use of com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination in project kotlin by JetBrains.

the class MoveKotlinTopLevelDeclarationsDialog method selectPackageBasedTargetDirAndDestination.

@Nullable
private Pair<VirtualFile, ? extends MoveDestination> selectPackageBasedTargetDirAndDestination(boolean askIfDoesNotExist) {
    String packageName = getTargetPackage();
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
    PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
    if (!targetPackage.exists() && askIfDoesNotExist) {
        int ret = Messages.showYesNoDialog(myProject, RefactoringBundle.message("package.does.not.exist", packageName), RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
        if (ret != Messages.YES)
            return null;
    }
    DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper) destinationFolderCB.getComboBox().getSelectedItem();
    PsiDirectory selectedPsiDirectory = selectedItem != null ? selectedItem.getDirectory() : null;
    if (selectedPsiDirectory == null) {
        if (initialTargetDirectory != null) {
            selectedPsiDirectory = initialTargetDirectory;
        } else {
            return Pair.create(null, new MultipleRootsMoveDestination(targetPackage));
        }
    }
    VirtualFile targetDirectory = selectedPsiDirectory.getVirtualFile();
    return Pair.create(targetDirectory, new AutocreatingSingleSourceRootMoveDestination(targetPackage, targetDirectory));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AutocreatingSingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination) PackageWrapper(com.intellij.refactoring.PackageWrapper) DirectoryChooser(com.intellij.ide.util.DirectoryChooser) MultipleRootsMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PackageWrapper (com.intellij.refactoring.PackageWrapper)2 AutocreatingSingleSourceRootMoveDestination (com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination)2 DirectoryChooser (com.intellij.ide.util.DirectoryChooser)1 PsiClass (com.intellij.psi.PsiClass)1 MoveClassesOrPackagesProcessor (com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor)1 MultipleRootsMoveDestination (com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination)1 Nullable (org.jetbrains.annotations.Nullable)1