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();
}
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);
}
}
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();
}
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();
}
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();
}
Aggregations