Search in sources :

Example 21 with ITextFileBuffer

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

the class FileBufferFunctions method test19.

/*
	 * Test notification in case of failing listener.
	 */
@Test
public void test19() throws Exception {
    class NotifiedListener extends FileBufferListener {

        int notifyCount = 0;

        @Override
        public void bufferCreated(IFileBuffer buffer) {
            notifyCount++;
        }

        @Override
        public void bufferDisposed(IFileBuffer buffer) {
            notifyCount++;
        }
    }
    class ForcedException extends RuntimeException {

        private static final long serialVersionUID = 1L;

        @Override
        public void printStackTrace(PrintStream s) {
            s.println("!FORCED BY TEST: this entry is intentional");
        }

        @Override
        public void printStackTrace(PrintWriter s) {
            s.println("!FORCED BY TEST: this entry is intentional");
        }
    }
    NotifiedListener notifyCounter1 = new NotifiedListener();
    NotifiedListener notifyCounter2 = new NotifiedListener();
    FileBufferListener failingListener = new FileBufferListener() {

        @Override
        public void bufferCreated(IFileBuffer buffer) {
            throw new ForcedException();
        }

        @Override
        public void bufferDisposed(IFileBuffer buffer) {
            throw new ForcedException();
        }
    };
    fManager.addFileBufferListener(notifyCounter1);
    fManager.addFileBufferListener(failingListener);
    fManager.addFileBufferListener(notifyCounter2);
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertNotNull(buffer);
        Class<IAnnotationModel> clazz = getAnnotationModelClass();
        if (clazz != null) {
            IAnnotationModel model = buffer.getAnnotationModel();
            assertTrue(clazz.isInstance(model));
        }
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        fManager.removeFileBufferListener(notifyCounter1);
        fManager.removeFileBufferListener(failingListener);
        fManager.removeFileBufferListener(notifyCounter2);
    }
    assertEquals(2, notifyCounter1.notifyCount);
    assertEquals(2, notifyCounter2.notifyCount);
}
Also used : PrintStream(java.io.PrintStream) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 22 with ITextFileBuffer

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

the class FileBufferFunctions method test5.

/*
	 * Tests getModificationStamp.
	 */
@Test
public void test5() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        long modificationStamp = fileBuffer.getModificationStamp();
        IFileStore fileStore = FileBuffers.getFileStoreAtLocation(fPath);
        IFileInfo fileInfo = fileStore.fetchInfo();
        assertEquals(modificationStamp != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP, fileInfo.exists());
        fileInfo.setLastModified(1000);
        if (fileInfo.exists())
            fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
        long lastModified = fileStore.fetchInfo().getLastModified();
        assertTrue(lastModified == EFS.NONE || modificationStamp != fileBuffer.getModificationStamp());
    } 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 23 with ITextFileBuffer

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

the class FileBufferFunctions method test8_2.

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

Example 24 with ITextFileBuffer

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

the class FileBufferFunctions method test9_1.

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

Example 25 with ITextFileBuffer

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

the class FileBufferFunctions method tearDown.

@After
public void tearDown() {
    ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
    assertTrue(buffer == null);
    ResourceHelper.deleteProject("project");
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) After(org.junit.After)

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