use of com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor in project intellij-community by JetBrains.
the class PyMoveTest method doMoveFileTest.
private void doMoveFileTest(String fileName, String toDirName) {
Project project = myFixture.getProject();
PsiManager manager = PsiManager.getInstance(project);
String root = "/refactoring/move/" + getTestName(true);
String rootBefore = root + "/before/src";
String rootAfter = root + "/after/src";
VirtualFile dir1 = myFixture.copyDirectoryToProject(rootBefore, "");
PsiDocumentManager.getInstance(project).commitAllDocuments();
VirtualFile virtualFile = dir1.findFileByRelativePath(fileName);
assertNotNull(virtualFile);
PsiElement file = manager.findFile(virtualFile);
if (file == null) {
file = manager.findDirectory(virtualFile);
}
assertNotNull(file);
VirtualFile toVirtualDir = dir1.findFileByRelativePath(toDirName);
assertNotNull(toVirtualDir);
PsiDirectory toDir = manager.findDirectory(toVirtualDir);
new MoveFilesOrDirectoriesProcessor(project, new PsiElement[] { file }, toDir, false, false, null, null).run();
VirtualFile dir2 = getVirtualFileByName(PythonTestUtil.getTestDataPath() + rootAfter);
try {
PlatformTestUtil.assertDirectoriesEqual(dir2, dir1);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor in project intellij-community by JetBrains.
the class CustomResourceBundleTest method testCustomResourceBundleFilesMovedOrDeleted.
public void testCustomResourceBundleFilesMovedOrDeleted() throws IOException {
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-dev/my-app-dev.properties", ""));
final PropertiesFile file2 = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-dev/my-app-test.properties", ""));
final PropertiesFile file3 = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-prod/my-app-prod.properties", ""));
assertNotNull(file);
assertNotNull(file2);
assertNotNull(file3);
assertOneElement(file.getResourceBundle().getPropertiesFiles());
assertOneElement(file2.getResourceBundle().getPropertiesFiles());
assertOneElement(file3.getResourceBundle().getPropertiesFiles());
final ResourceBundleManager resourceBundleBaseNameManager = ResourceBundleManager.getInstance(getProject());
resourceBundleBaseNameManager.combineToResourceBundle(list(file, file2, file3), "my-app");
assertSize(3, file.getResourceBundle().getPropertiesFiles());
final PsiDirectory newDir = PsiManager.getInstance(getProject()).findDirectory(myFixture.getTempDirFixture().findOrCreateDir("new-resources-dir"));
new MoveFilesOrDirectoriesProcessor(getProject(), new PsiElement[] { file2.getContainingFile() }, newDir, false, false, null, null).run();
ApplicationManager.getApplication().runWriteAction(() -> file3.getContainingFile().delete());
assertSize(2, file.getResourceBundle().getPropertiesFiles());
final ResourceBundleManagerState state = ResourceBundleManager.getInstance(getProject()).getState();
assertNotNull(state);
assertSize(1, state.getCustomResourceBundles());
assertSize(2, state.getCustomResourceBundles().get(0).getFileUrls());
}
use of com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method moveFile.
@Override
public void moveFile(@NotNull final String filePath, @NotNull final String to, @NotNull final String... additionalFiles) {
assertInitialized();
final Project project = getProject();
configureByFiles(ArrayUtil.reverseArray(ArrayUtil.append(additionalFiles, filePath)));
final VirtualFile file = findFileInTempDir(to);
assertNotNull("Directory " + to + " not found", file);
assertTrue(to + " is not a directory", file.isDirectory());
final PsiDirectory directory = myPsiManager.findDirectory(file);
new MoveFilesOrDirectoriesProcessor(project, new PsiElement[] { getFile() }, directory, false, false, null, null).run();
}
use of com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor in project intellij-plugins by JetBrains.
the class DartHighlightingTest method _testUpdateImportsOnFileMove.
public void _testUpdateImportsOnFileMove() {
myFixture.addFileToProject("pubspec.yaml", "name: ProjectName\n");
final PsiFile libFile = myFixture.addFileToProject("lib/libFile.dart", "");
final PsiFile libFile2 = myFixture.addFileToProject("lib/sub/libFile2.dart", "import '../libFile.dart';\n" + "import 'package:ProjectName/libFile.dart';");
new MoveFilesOrDirectoriesProcessor(getProject(), new PsiElement[] { libFile2 }, libFile.getParent(), true, true, true, null, null).run();
myFixture.openFileInEditor(libFile2.getVirtualFile());
myFixture.checkResult("import 'libFile.dart';\n" + "import 'package:ProjectName/libFile.dart';");
}
use of com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor in project intellij-community by JetBrains.
the class GrMoveToDirFix method doFix.
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
PsiFile file = descriptor.getPsiElement().getContainingFile();
if (!(file instanceof GroovyFile))
return;
VirtualFile vfile = file.getVirtualFile();
if (vfile == null)
return;
final Module module = ModuleUtilCore.findModuleForFile(vfile, project);
if (module == null)
return;
final String packageName = ((GroovyFile) file).getPackageName();
PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, null, true);
if (directory == null)
return;
String error = RefactoringMessageUtil.checkCanCreateFile(directory, file.getName());
if (error != null) {
Messages.showMessageDialog(project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
return;
}
new MoveFilesOrDirectoriesProcessor(project, new PsiElement[] { file }, directory, false, false, false, null, null).run();
}
Aggregations