Search in sources :

Example 11 with ITextFileBufferManager

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

the class FileBufferCreation method test3_2_new.

/*
	 * Tests the creation of a file buffer for a file in a linked folder.
	 */
@Test
public void test3_2_new() throws Exception {
    IPath path = createLinkedFolder("linkedFolder", "testResources/linkedFolderTarget");
    assertNotNull(path);
    path = path.append("FileInLinkedFolder");
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path, LocationKind.IFILE, null);
    ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
    Assert.assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    Assert.assertNotNull(document);
    Assert.assertTrue(CONTENT4.equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.IFILE, null);
    assertNull(manager.getTextFileBuffer(path, LocationKind.IFILE));
}
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) Test(org.junit.Test)

Example 12 with ITextFileBufferManager

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

the class FileBufferCreation method test3_1_IFILE.

/*
	 * Tests the creation of a file buffer for a linked file.
	 */
@Test
public void test3_1_IFILE() throws Exception {
    IPath path = createLinkedFile("file", "testResources/LinkedFileTarget");
    assertNotNull(path);
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path, LocationKind.IFILE, null);
    ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
    Assert.assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    Assert.assertNotNull(document);
    Assert.assertTrue(CONTENT2.equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.IFILE, null);
    assertNull(manager.getTextFileBuffer(path, LocationKind.IFILE));
}
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) Test(org.junit.Test)

Example 13 with ITextFileBufferManager

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

the class FileBufferCreation method test5.

/*
	 * Tests the creation of a file buffer for an external file.
	 */
@Test
public void test5() 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.NORMALIZE, null);
    ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.NORMALIZE);
    assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertTrue(CONTENT3.equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path, LocationKind.NORMALIZE));
}
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)

Example 14 with ITextFileBufferManager

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

the class FileBufferCreation method test7_IFileStore.

/*
	 * Tests the creation of a file buffer for a non-existing file.
	 */
@Test
public void test7_IFileStore() throws Exception {
    IPath path = FileBuffersTestPlugin.getDefault().getStateLocation();
    path = path.append("NonExistingFile");
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connectFileStore(fileStore, null);
    ITextFileBuffer buffer = manager.getFileStoreTextFileBuffer(fileStore);
    Assert.assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    Assert.assertNotNull(document);
    Assert.assertTrue("".equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnectFileStore(fileStore, null);
    assertNull(manager.getFileStoreTextFileBuffer(fileStore));
}
Also used : 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) Test(org.junit.Test)

Example 15 with ITextFileBufferManager

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

the class FileBufferCreation method test3_2.

/*
	 * Tests the creation of a file buffer for a file in a linked folder.
	 */
@Test
public void test3_2() throws Exception {
    IPath path = createLinkedFolder("linkedFolder", "testResources/linkedFolderTarget");
    assertNotNull(path);
    path = path.append("FileInLinkedFolder");
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path, LocationKind.NORMALIZE, null);
    ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.NORMALIZE);
    Assert.assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    Assert.assertNotNull(document);
    Assert.assertTrue(CONTENT4.equals(document.get()));
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path, 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) Test(org.junit.Test)

Aggregations

ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)86 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)65 IDocument (org.eclipse.jface.text.IDocument)53 IPath (org.eclipse.core.runtime.IPath)51 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 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)6 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 TextEdit (org.eclipse.text.edits.TextEdit)6 UndoEdit (org.eclipse.text.edits.UndoEdit)6 FileNotFoundException (java.io.FileNotFoundException)5 MalformedURLException (java.net.MalformedURLException)5