Search in sources :

Example 86 with IDocument

use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test1.

/*
	 * Tests the creation of file buffer for an existing file.
	 */
@Test
public void test1() throws Exception {
    IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
    IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
    IPath path = file.getFullPath();
    assertNotNull(path);
    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);
    assertEquals(CONTENT1, document.get());
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.NORMALIZE, null);
    assertNull(manager.getTextFileBuffer(path, 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) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 87 with IDocument

use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test3_1.

/*
	 * Tests the creation of a file buffer for a linked file.
	 */
@Test
public void test3_1() throws Exception {
    IPath path = createLinkedFile("file", "testResources/LinkedFileTarget");
    assertNotNull(path);
    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(CONTENT2.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)

Example 88 with IDocument

use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test4_IFILE.

/*
	 * Tests that two different files linked to the same target file result
	 * in two different, independent file buffers.
	 */
@Test
public void test4_IFILE() 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.IFILE, null);
    ITextFileBuffer buffer1 = manager.getTextFileBuffer(path1, LocationKind.IFILE);
    assertNotNull(buffer1);
    manager.connect(path2, LocationKind.IFILE, null);
    ITextFileBuffer buffer2 = manager.getTextFileBuffer(path2, LocationKind.IFILE);
    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.IFILE, null);
    assertNull(manager.getTextFileBuffer(path1, LocationKind.IFILE));
    assertNotNull(manager.getTextFileBuffer(path2, LocationKind.IFILE));
    manager.disconnect(path2, LocationKind.IFILE, null);
    assertNull(manager.getTextFileBuffer(path2, 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) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 89 with IDocument

use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test1_IFILE.

/*
	 * Tests the creation of file buffer for an existing file.
	 */
@Test
public void test1_IFILE() throws Exception {
    IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
    IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
    IPath path = file.getFullPath();
    assertNotNull(path);
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path, LocationKind.IFILE, null);
    ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
    assertNotNull(buffer);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertEquals(CONTENT1, document.get());
    assertSame(buffer, manager.getTextFileBuffer(document));
    manager.disconnect(path, LocationKind.IFILE, null);
    assertNull(manager.getTextFileBuffer(path, LocationKind.IFILE));
}
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) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 90 with IDocument

use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.

the class FileBufferFunctions method test12_1.

/*
	 * Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced
	 */
@Test
public void test12_1() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer preBuffer, postBuffer;

        public int preCount, postCount;

        @Override
        public void bufferContentAboutToBeReplaced(IFileBuffer buffer) {
            ++preCount;
            preBuffer = buffer;
        }

        @Override
        public void bufferContentReplaced(IFileBuffer buffer) {
            ++postCount;
            postBuffer = buffer;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            IDocument document = fileBuffer.getDocument();
            document.replace(0, 0, "prefix");
            fileBuffer.revert(null);
            assertTrue(listener.preCount == 1);
            assertTrue(listener.preBuffer == fileBuffer);
            assertTrue(listener.postCount == 1);
            assertTrue(listener.postBuffer == fileBuffer);
        } finally {
            fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) 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