Search in sources :

Example 81 with ITextFileBuffer

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

the class FileBufferFunctions method setUp.

@Before
public void setUp() throws Exception {
    fManager = FileBuffers.getTextFileBufferManager();
    fProject = ResourceHelper.createProject("project");
    fPath = createPath(fProject);
    ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
    assertTrue(buffer == null);
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Before(org.junit.Before)

Example 82 with ITextFileBuffer

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

the class FileBufferFunctions method test7.

/*
	 * Test commit.
	 */
@Test
public void test7() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        // set dirty bit
        IDocument document = fileBuffer.getDocument();
        document.replace(document.getLength(), 0, "appendix");
        String originalContent = document.get();
        // commit
        fileBuffer.commit(null, true);
        // check assertions
        assertEquals(originalContent, document.get());
        assertFalse(fileBuffer.isDirty());
        assertTrue(fileBuffer.isSynchronized());
        // revert to see effect is persistent
        fileBuffer.revert(null);
        // check assertions
        assertEquals(originalContent, document.get());
        assertFalse(fileBuffer.isDirty());
        assertTrue(fileBuffer.isSynchronized());
        // disconnect
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        // reconnect
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            document = fileBuffer.getDocument();
            // check assertions
            assertEquals(originalContent, document.get());
            assertFalse(fileBuffer.isDirty());
            assertTrue(fileBuffer.isSynchronized());
        } finally {
            fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        }
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 83 with ITextFileBuffer

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

the class FileBufferFunctions method test8_1.

/*
	 * Test validateState.
	 */
@Test
public void test8_1() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        fileBuffer.validateState(null, null);
        assertTrue(fileBuffer.isStateValidated());
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 84 with ITextFileBuffer

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

the class FileBufferFunctions method test4.

/*
	 * Tests isShared.
	 */
@Test
public void test4() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer fileBuffer1 = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertFalse(fileBuffer1.isShared());
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            ITextFileBuffer fileBuffer2 = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            assertTrue(fileBuffer1.isShared());
            assertTrue(fileBuffer2.isShared());
        } finally {
            fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        }
        assertFalse(fileBuffer1.isShared());
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 85 with ITextFileBuffer

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

the class FileBufferFunctions method testGetFileStoreAnnotationModel.

/*
	 * Tests isSynchronized.
	 */
@Test
public void testGetFileStoreAnnotationModel() throws Exception {
    IFileStore fileStore = EFS.getNullFileSystem().getStore(new Path("/dev/null"));
    assertNotNull(fileStore);
    fManager.connectFileStore(fileStore, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fileStore);
        IAnnotationModel model = fileBuffer.getAnnotationModel();
        Class<IAnnotationModel> clazz = getAnnotationModelClass();
        if (clazz != null)
            assertTrue(clazz.isInstance(model));
        else
            assertNotNull(model);
    } finally {
        fManager.disconnectFileStore(fileStore, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) 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