Search in sources :

Example 86 with ITextFileBuffer

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

the class FileBufferFunctions method test9_2.

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

Example 87 with ITextFileBuffer

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

the class FileBufferFunctions method test13_3.

/*
	 * Test IFileBufferListener#stateValidationChanged
	 */
@Test
public void test13_3() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        public boolean isStateValidated;

        @Override
        public void stateValidationChanged(IFileBuffer buf, boolean state) {
            ++count;
            this.buffer = buf;
            this.isStateValidated = state;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            fileBuffer.validateState(null, null);
            fileBuffer.resetStateValidation();
            if (isStateValidationSupported()) {
                assertTrue(listener.count == 2);
                assertTrue(listener.buffer == fileBuffer);
                assertFalse(listener.isStateValidated);
            }
        } 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) Test(org.junit.Test)

Example 88 with ITextFileBuffer

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

the class FileBufferFunctions method test13_1.

/*
	 * Test IFileBufferListener#stateValidationChanged
	 */
@Test
public void test13_1() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        public boolean isStateValidated;

        @Override
        public void stateValidationChanged(IFileBuffer buf, boolean state) {
            ++count;
            this.buffer = buf;
            this.isStateValidated = state;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            fileBuffer.validateState(null, null);
            if (isStateValidationSupported()) {
                assertTrue(listener.count == 1);
                assertTrue(listener.buffer == fileBuffer);
                assertTrue(listener.isStateValidated);
            }
        } 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) Test(org.junit.Test)

Example 89 with ITextFileBuffer

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

the class FileBufferFunctions method test11_1.

/*
	 * Test IFileBufferListener#dirtyStateChanged
	 */
@Test
public void test11_1() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        public boolean isDirty;

        @Override
        public void dirtyStateChanged(IFileBuffer buf, boolean state) {
            ++count;
            this.buffer = buf;
            this.isDirty = state;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            IDocument document = fileBuffer.getDocument();
            document.replace(0, 0, "prefix");
            assertTrue(listener.count == 1);
            assertTrue(listener.buffer == fileBuffer);
            assertTrue(listener.isDirty);
            fileBuffer.commit(null, true);
            assertTrue(listener.count == 2);
            assertTrue(listener.buffer == fileBuffer);
            assertFalse(listener.isDirty);
        } 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)

Example 90 with ITextFileBuffer

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

the class FileBufferFunctions method test17_3.

/*
	 * Test IFileBufferListener#stateChanging for internal changes
	 */
@Test
public void test17_3() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        @Override
        public void stateChanging(IFileBuffer buf) {
            ++count;
            this.buffer = buf;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            IDocument document = fileBuffer.getDocument();
            document.replace(0, 0, "prefix");
            fileBuffer.commit(null, true);
            assertTrue(listener.count == 1);
            assertTrue(listener.buffer == 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