Search in sources :

Example 41 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer 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 42 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer 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 43 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer 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 44 with ITextFileBuffer

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

the class FileBufferFunctions method test2.

/*
	 * Tests isSynchronized.
	 */
@Test
public void test2() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(fileBuffer.isSynchronized());
        IFileStore fileStore = FileBuffers.getFileStoreAtLocation(fPath);
        IFileInfo fileInfo = fileStore.fetchInfo();
        fileInfo.setLastModified(1000);
        if (fileInfo.exists())
            fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
        long lastModified = fileStore.fetchInfo().getLastModified();
        assertTrue(lastModified == EFS.NONE || !fileBuffer.isSynchronized());
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) Test(org.junit.Test)

Example 45 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer 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

ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)133 Test (org.junit.Test)85 IDocument (org.eclipse.jface.text.IDocument)54 IFileBuffer (org.eclipse.core.filebuffers.IFileBuffer)37 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)35 IPath (org.eclipse.core.runtime.IPath)31 IFile (org.eclipse.core.resources.IFile)18 BadLocationException (org.eclipse.jface.text.BadLocationException)15 IFileStore (org.eclipse.core.filesystem.IFileStore)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 CoreException (org.eclipse.core.runtime.CoreException)8 Position (org.eclipse.jface.text.Position)8 IFileInfo (org.eclipse.core.filesystem.IFileInfo)7 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)7 Match (org.eclipse.search.ui.text.Match)7 IFolder (org.eclipse.core.resources.IFolder)5 IStatus (org.eclipse.core.runtime.IStatus)5 Path (org.eclipse.core.runtime.Path)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 Status (org.eclipse.core.runtime.Status)4