Search in sources :

Example 56 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test2.

/*
	 * Tests that two different paths pointing to the same physical resource
	 * result in the same shared file buffer.
	 */
@Test
public void test2() throws Exception {
    IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
    IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
    IPath path1 = file.getFullPath();
    assertNotNull(path1);
    IPath path2 = ResourcesPlugin.getWorkspace().getRoot().getLocation();
    path2 = path2.append(path1.makeAbsolute());
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path1, LocationKind.NORMALIZE, null);
    ITextFileBuffer buffer1 = manager.getTextFileBuffer(path1, LocationKind.NORMALIZE);
    assertNotNull(buffer1);
    ITextFileBuffer buffer2 = manager.getTextFileBuffer(path2, LocationKind.NORMALIZE);
    assertNotNull(buffer2);
    manager.connect(path2, LocationKind.NORMALIZE, null);
    buffer2 = manager.getTextFileBuffer(path2, LocationKind.NORMALIZE);
    assertNotNull(buffer2);
    IDocument document1 = buffer1.getDocument();
    assertNotNull(document1);
    assertEquals(CONTENT1, document1.get());
    assertSame(buffer1, manager.getTextFileBuffer(document1));
    IDocument document2 = buffer2.getDocument();
    assertNotNull(document2);
    assertEquals(CONTENT1, document2.get());
    assertSame(buffer2, manager.getTextFileBuffer(document2));
    try {
        document1.replace(0, document1.getLength(), CONTENT3);
    } catch (BadLocationException x) {
        assertTrue(false);
    }
    assertEquals(CONTENT3, document2.get());
    manager.disconnect(path1, LocationKind.NORMALIZE, null);
    assertNotNull(manager.getTextFileBuffer(path1, LocationKind.NORMALIZE));
    assertNotNull(manager.getTextFileBuffer(path2, LocationKind.NORMALIZE));
    manager.disconnect(path2, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path1, LocationKind.NORMALIZE));
    assertNull(manager.getTextFileBuffer(path2, LocationKind.NORMALIZE));
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 57 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test4.

/*
	 * Tests that two different files linked to the same target file result
	 * in two different, independent file buffers.
	 */
@Test
public void test4() throws Exception {
    IPath path1 = createLinkedFile("file1", "testResources/LinkedFileTarget");
    assertNotNull(path1);
    IPath path2 = createLinkedFile("file2", "testResources/LinkedFileTarget");
    assertNotNull(path2);
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path1, LocationKind.NORMALIZE, null);
    ITextFileBuffer buffer1 = manager.getTextFileBuffer(path1, LocationKind.NORMALIZE);
    assertNotNull(buffer1);
    manager.connect(path2, LocationKind.NORMALIZE, null);
    ITextFileBuffer buffer2 = manager.getTextFileBuffer(path2, LocationKind.NORMALIZE);
    assertNotNull(buffer2);
    IDocument document1 = buffer1.getDocument();
    assertNotNull(document1);
    assertSame(buffer1, manager.getTextFileBuffer(document1));
    IDocument document2 = buffer2.getDocument();
    assertNotNull(document2);
    assertSame(buffer2, manager.getTextFileBuffer(document2));
    assertEquals(document1.get(), document2.get());
    assertEquals(CONTENT2, document1.get());
    try {
        document1.replace(0, document1.getLength(), CONTENT1);
    } catch (BadLocationException x) {
        Assert.assertFalse(false);
    }
    assertFalse(document1.get().equals(document2.get()));
    manager.disconnect(path1, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path1, LocationKind.NORMALIZE));
    assertNotNull(manager.getTextFileBuffer(path2, LocationKind.NORMALIZE));
    manager.disconnect(path2, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path2, LocationKind.NORMALIZE));
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 58 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test1_IFileStore.

/*
	 * Tests the creation of file buffer for an existing file.
	 */
@Test
public void test1_IFileStore() throws Exception {
    IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
    IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
    IPath path = file.getFullPath();
    assertNotNull(path);
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.getLocation());
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connectFileStore(fileStore, null);
    ITextFileBuffer buffer = manager.getFileStoreTextFileBuffer(fileStore);
    assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertEquals(CONTENT1, document.get());
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnectFileStore(fileStore, null);
    assertNull(manager.getFileStoreTextFileBuffer(fileStore));
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) IDocument(org.eclipse.jface.text.IDocument) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 59 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test2_new.

/*
	 * Tests that two different paths pointing to the same physical resource
	 * result in the same shared file buffer.
	 */
@Test
public void test2_new() throws Exception {
    IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
    IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
    IPath path1 = file.getFullPath();
    assertNotNull(path1);
    IPath path2 = ResourcesPlugin.getWorkspace().getRoot().getLocation();
    path2 = path2.append(path1.makeAbsolute());
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path1, LocationKind.IFILE, null);
    ITextFileBuffer buffer1 = manager.getTextFileBuffer(path1, LocationKind.IFILE);
    assertNotNull(buffer1);
    ITextFileBuffer buffer2 = manager.getTextFileBuffer(path2, LocationKind.NORMALIZE);
    assertNotNull(buffer2);
    manager.connect(path2, LocationKind.NORMALIZE, null);
    buffer2 = manager.getTextFileBuffer(path2, LocationKind.NORMALIZE);
    assertNotNull(buffer2);
    IDocument document1 = buffer1.getDocument();
    assertNotNull(document1);
    assertEquals(CONTENT1, document1.get());
    assertSame(buffer1, manager.getTextFileBuffer(document1));
    IDocument document2 = buffer2.getDocument();
    assertNotNull(document2);
    assertEquals(CONTENT1, document2.get());
    assertSame(buffer2, manager.getTextFileBuffer(document2));
    try {
        document1.replace(0, document1.getLength(), CONTENT3);
    } catch (BadLocationException x) {
        assertTrue(false);
    }
    assertEquals(CONTENT3, document2.get());
    manager.disconnect(path1, LocationKind.IFILE, null);
    assertNotNull(manager.getTextFileBuffer(path1, LocationKind.IFILE));
    assertNotNull(manager.getTextFileBuffer(path2, LocationKind.NORMALIZE));
    manager.disconnect(path2, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path1, LocationKind.IFILE));
    assertNull(manager.getTextFileBuffer(path2, LocationKind.NORMALIZE));
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 60 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test5_location.

/*
	 * Tests the creation of a file buffer for an external file.
	 */
@Test
public void test5_location() throws Exception {
    File externalFile = FileTool.getFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
    assertNotNull(externalFile);
    IPath path = new Path(externalFile.getAbsolutePath());
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path, LocationKind.LOCATION, null);
    ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.LOCATION);
    assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertTrue(CONTENT3.equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.LOCATION, null);
    assertNull(manager.getTextFileBuffer(path, LocationKind.LOCATION));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Aggregations

ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)87 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)66 IDocument (org.eclipse.jface.text.IDocument)54 IPath (org.eclipse.core.runtime.IPath)52 CoreException (org.eclipse.core.runtime.CoreException)36 BadLocationException (org.eclipse.jface.text.BadLocationException)26 IFile (org.eclipse.core.resources.IFile)22 Test (org.junit.Test)17 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 IOException (java.io.IOException)10 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)10 IResource (org.eclipse.core.resources.IResource)8 Path (org.eclipse.core.runtime.Path)8 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 TextEdit (org.eclipse.text.edits.TextEdit)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)6 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 UndoEdit (org.eclipse.text.edits.UndoEdit)6 FileNotFoundException (java.io.FileNotFoundException)5 MalformedURLException (java.net.MalformedURLException)5