Search in sources :

Example 81 with IDocument

use of org.eclipse.jface.text.IDocument 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 82 with IDocument

use of org.eclipse.jface.text.IDocument 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 83 with IDocument

use of org.eclipse.jface.text.IDocument 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 84 with IDocument

use of org.eclipse.jface.text.IDocument 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 85 with IDocument

use of org.eclipse.jface.text.IDocument 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

IDocument (org.eclipse.jface.text.IDocument)488 BadLocationException (org.eclipse.jface.text.BadLocationException)195 Document (org.eclipse.jface.text.Document)118 Test (org.junit.Test)93 IRegion (org.eclipse.jface.text.IRegion)72 Point (org.eclipse.swt.graphics.Point)63 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)54 Position (org.eclipse.jface.text.Position)51 ArrayList (java.util.ArrayList)44 CoreException (org.eclipse.core.runtime.CoreException)39 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)30 IPath (org.eclipse.core.runtime.IPath)26 IFile (org.eclipse.core.resources.IFile)25 IStatus (org.eclipse.core.runtime.IStatus)25 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)24 TextEdit (org.eclipse.text.edits.TextEdit)23 Region (org.eclipse.jface.text.Region)22 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)22 LinkedPositionGroup (org.eclipse.jface.text.link.LinkedPositionGroup)21 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)20