Search in sources :

Example 46 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class VirtualFilePointerTest method testDotDot.

public void testDotDot() throws IOException {
    File tempDirectory = createTempDirectory();
    final VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory);
    VirtualFile dir1 = createChildDirectory(root, "dir1");
    VirtualFile dir2 = createChildDirectory(root, "dir2");
    VirtualFile file = createChildData(dir1, "x.txt");
    VirtualFilePointer pointer = myVirtualFilePointerManager.create(dir2.getUrl() + "/../" + dir1.getName() + "/" + file.getName(), disposable, null);
    assertEquals(file, pointer.getFile());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 47 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class VirtualFilePointerTest method testRenamingPointedFile.

public void testRenamingPointedFile() throws IOException {
    final File tempDir = createTempDirectory();
    final File file = new File(tempDir, "f1");
    assertTrue(file.createNewFile());
    final LoggingListener listener = new LoggingListener();
    VirtualFilePointer pointer = createPointerByFile(file, listener);
    assertTrue(pointer.isValid());
    rename(getVirtualFile(file), "f2");
    assertTrue(pointer.isValid());
    assertEquals("[]", listener.getLog().toString());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 48 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class VirtualFilePointerTest method testTwoPointersMergingIntoOne.

public void testTwoPointersMergingIntoOne() throws IOException {
    File tempDirectory = createTempDirectory();
    final VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory);
    VirtualFile dir1 = createChildDirectory(root, "dir1");
    VirtualFile dir2 = createChildDirectory(root, "dir2");
    VirtualFilePointer p1 = myVirtualFilePointerManager.create(dir1, disposable, null);
    VirtualFilePointer p2 = myVirtualFilePointerManager.create(dir2, disposable, null);
    assertTrue(p1.isValid());
    assertEquals(dir1, p1.getFile());
    assertTrue(p2.isValid());
    assertEquals(dir2, p2.getFile());
    delete(dir1);
    assertNull(p1.getFile());
    assertEquals(dir2, p2.getFile());
    rename(dir2, "dir1");
    assertEquals(dir2, p1.getFile());
    assertEquals(dir2, p2.getFile());
    rename(dir2, "dir2");
    assertEquals(dir2, p1.getFile());
    assertEquals(dir2, p2.getFile());
    createChildDirectory(root, "dir1");
    assertEquals(dir2, p1.getFile());
    assertEquals(dir2, p2.getFile());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 49 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class VirtualFilePointerTest method testCreate.

public void testCreate() throws Exception {
    final File tempDirectory = createTempDirectory();
    final File fileToCreate = new File(tempDirectory, "toCreate.txt");
    final LoggingListener fileToCreateListener = new LoggingListener();
    final VirtualFilePointer fileToCreatePointer = createPointerByFile(fileToCreate, fileToCreateListener);
    assertFalse(fileToCreatePointer.isValid());
    assertTrue(fileToCreate.createNewFile());
    ApplicationManager.getApplication().runWriteAction(() -> {
        VirtualFileManager.getInstance().syncRefresh();
        final VirtualFile virtualFile = getVirtualFile(tempDirectory);
        virtualFile.refresh(false, true);
    });
    assertTrue(fileToCreatePointer.isValid());
    assertEquals("[before:false, after:true]", fileToCreateListener.getLog().toString());
    try {
        String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, fileToCreate.getCanonicalPath().replace(File.separatorChar, '/'));
        assertEquals(expectedUrl.toUpperCase(), fileToCreatePointer.getUrl().toUpperCase());
    } catch (IOException e) {
        fail();
    }
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) IOException(java.io.IOException) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 50 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class VirtualFilePointerTest method testCreate1.

public void testCreate1() throws Exception {
    final File tempDirectory = createTempDirectory();
    final File fileToCreate = new File(tempDirectory, "toCreate1.txt");
    final LoggingListener fileToCreateListener = new LoggingListener();
    final VirtualFilePointer fileToCreatePointer = createPointerByFile(fileToCreate, fileToCreateListener);
    assertFalse(fileToCreatePointer.isValid());
    assertTrue(fileToCreate.createNewFile());
    final Runnable postRunnable = () -> {
        assertTrue(fileToCreatePointer.isValid());
        assertEquals("[before:false, after:true]", fileToCreateListener.getLog().toString());
        try {
            String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, fileToCreate.getCanonicalPath().replace(File.separatorChar, '/'));
            assertEquals(expectedUrl.toUpperCase(), fileToCreatePointer.getUrl().toUpperCase());
        } catch (IOException e) {
            fail();
        }
    };
    ApplicationManager.getApplication().runWriteAction(() -> {
        VirtualFileManager.getInstance().syncRefresh();
        final VirtualFile virtualFile = getVirtualFile(tempDirectory);
        virtualFile.refresh(false, true);
    });
    postRunnable.run();
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) IOException(java.io.IOException) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Aggregations

VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)66 MockVirtualFile (com.intellij.mock.MockVirtualFile)23 File (java.io.File)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)12 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)11 IOException (java.io.IOException)8 Disposable (com.intellij.openapi.Disposable)7 VirtualFilePointerListener (com.intellij.openapi.vfs.pointers.VirtualFilePointerListener)6 ArrayList (java.util.ArrayList)5 Element (org.jdom.Element)5 Nullable (org.jetbrains.annotations.Nullable)4 Job (com.intellij.concurrency.Job)3 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)3 FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)3 VirtualFilePointerManager (com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)3 JobLauncher (com.intellij.concurrency.JobLauncher)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2