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