Search in sources :

Example 1 with MoveFilesOrDirectoriesProcessor

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) IOException(java.io.IOException) MoveFilesOrDirectoriesProcessor(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor)

Example 2 with MoveFilesOrDirectoriesProcessor

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());
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) MoveFilesOrDirectoriesProcessor(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 3 with MoveFilesOrDirectoriesProcessor

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();
}
Also used : Project(com.intellij.openapi.project.Project) MoveFilesOrDirectoriesProcessor(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor)

Example 4 with MoveFilesOrDirectoriesProcessor

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';");
}
Also used : PsiFile(com.intellij.psi.PsiFile) MoveFilesOrDirectoriesProcessor(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 5 with MoveFilesOrDirectoriesProcessor

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) MoveFilesOrDirectoriesProcessor(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

MoveFilesOrDirectoriesProcessor (com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor)5 PsiElement (com.intellij.psi.PsiElement)3 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiFile (com.intellij.psi.PsiFile)2 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Module (com.intellij.openapi.module.Module)1 IOException (java.io.IOException)1 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)1