Search in sources :

Example 76 with IDocument

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

the class FileUtils method readFully.

public static IDocument readFully(IFile file) throws CoreException, IOException {
    if (file.exists()) {
        InputStream stream = file.getContents();
        byte[] bytes = readFully(stream);
        String string = new String(bytes, file.getCharset());
        return new Document(string);
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Example 77 with IDocument

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

the class FileBufferFunctions method test3.

/*
	 * Tests isDirty.
	 */
@Test
public void test3() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertFalse(fileBuffer.isDirty());
        IDocument document = fileBuffer.getDocument();
        document.replace(document.getLength(), 0, "appendix");
        assertTrue(fileBuffer.isDirty());
    } 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 78 with IDocument

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

the class FileBufferFunctions method test11_2.

/*
	 * Test IFileBufferListener#dirtyStateChanged
	 */
@Test
public void test11_2() 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.revert(null);
            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 79 with IDocument

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

the class FileStoreFileBufferFunctions 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.getFileStoreTextFileBuffer(fFileStore);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connectFileStore(fFileStore, null);
        try {
            fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
            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.disconnectFileStore(fFileStore, 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 80 with IDocument

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

the class AbstractFileBufferDocCreationTests method assertParticipantsInvoked.

/* Utilities */
private void assertParticipantsInvoked(String path, Class<?>[] expectedDSPsArray) {
    LocationKind[] lks = getSupportLocationKinds();
    for (int i = 0; i < lks.length; i++) {
        IDocument document = fManager.createEmptyDocument(new Path(path), lks[i]);
        String content = document.get();
        Set<String> expectedDSPs = new HashSet<>(Arrays.asList(toString(expectedDSPsArray)));
        Set<String> actualDSPs = new HashSet<>(Arrays.asList(content.split("\n")));
        assertEquals(expectedDSPs, actualDSPs);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) LocationKind(org.eclipse.core.filebuffers.LocationKind) IDocument(org.eclipse.jface.text.IDocument) HashSet(java.util.HashSet)

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