Search in sources :

Example 81 with BadLocationException

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

the class FindReplaceDocumentAdapterTest method testReplace.

@Test
public void testReplace() {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    try {
        // $NON-NLS-1$
        findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
        // $NON-NLS-1$
        IRegion r = findReplaceDocumentAdapter.replace("private", false);
        assertNotNull(r);
        // $NON-NLS-1$
        findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.replace("private", false);
        assertNotNull(r);
        // $NON-NLS-1$
        findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.replace("private", false);
        assertNotNull(r);
        // Search again: there will be no match
        // $NON-NLS-1$
        findReplaceDocumentAdapter.find(0, "public", true, true, false, false);
        try {
            // $NON-NLS-1$
            findReplaceDocumentAdapter.replace("private", false);
        } catch (IllegalStateException e) {
            assertTrue(true);
        }
        String text = // $NON-NLS-1$
        "package TestPackage;\n" + // $NON-NLS-1$
        "/*\n" + // $NON-NLS-1$
        "* comment\n" + // $NON-NLS-1$
        "*/\n" + // $NON-NLS-1$
        "	private class Class {\n" + // $NON-NLS-1$
        "		// comment1\n" + // $NON-NLS-1$
        "		private void method1() {\n" + // $NON-NLS-1$
        "		}\n" + // $NON-NLS-1$
        "		// comment2\n" + // $NON-NLS-1$
        "		private void method2() {\n" + // $NON-NLS-1$
        "		}\n" + // $NON-NLS-1$
        "	}\n" + // $NON-NLS-1$S
        "// Gel\u00f6st";
        assertEquals(text, fDocument.get());
    } catch (BadLocationException e) {
        Assert.assertTrue(false);
    }
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 82 with BadLocationException

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

the class FindReplaceDocumentAdapterTest method testUTF8Pattern.

@Test
public void testUTF8Pattern() {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    try {
        IRegion result = new Region(153, 6);
        // Find case-sensitive
        // $NON-NLS-1$
        IRegion r = findReplaceDocumentAdapter.find(0, "Gel\u00F6st", true, true, false, false);
        assertEquals(result, r);
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.find(0, "Gel\u00F6st", true, true, false, false);
        assertEquals(result, r);
        // Find non-case-sensitive
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.find(0, "Gel\u00D6st", true, false, false, false);
        assertEquals(result, r);
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.find(0, "Gel\u00D6st", true, false, false, false);
        assertEquals(result, r);
    } catch (BadLocationException e) {
        Assert.assertTrue(false);
    }
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 83 with BadLocationException

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

the class FindReplaceDocumentAdapterTest method testBug74993.

/**
 * Test case for: https://bugs.eclipse.org/bugs/show_bug.cgi?id=74993
 */
@Test
public void testBug74993() {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    try {
        // $NON-NLS-1$
        IRegion r = findReplaceDocumentAdapter.find(12, "\\w+", false, false, false, true);
        assertEquals(new Region(6, 1), r);
    } catch (BadLocationException e) {
        Assert.assertTrue(false);
    }
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 84 with BadLocationException

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

the class TextUtilitiesTest method testMergeEvents2.

@Test
public void testMergeEvents2() {
    IDocument reference = new Document();
    LazilyMirroredDocument2 testee = new LazilyMirroredDocument2(reference);
    try {
        List<DocumentEvent> events = new ArrayList<>();
        int currentLength = 0;
        events.add(new DocumentEvent(reference, 0, 0, "foo bar goo haa"));
        events.add(new DocumentEvent(reference, 0, "foo bar goo haa".length(), "foo bar goo haa"));
        events.add(new DocumentEvent(reference, 4, 4, "xxxx"));
        events.add(new DocumentEvent(reference, 4, 4, "yyy"));
        events.add(new DocumentEvent(reference, 4, 3, "moo "));
        events.add(new DocumentEvent(reference, 9, 2, "asd"));
        events.add(new DocumentEvent(reference, 0, 2, "asd"));
        for (Iterator<DocumentEvent> iterator = events.iterator(); iterator.hasNext(); ) {
            DocumentEvent event = iterator.next();
            currentLength += event.getText().length() - event.getLength();
        }
        for (int i = 0; i < 500; i++) {
            char character = (char) (32 + i % 95);
            DocumentEvent event = createRandomEvent(reference, currentLength, character);
            currentLength += event.getText().length() - event.getLength();
            events.add(event);
        }
        for (Iterator<DocumentEvent> iterator = events.iterator(); iterator.hasNext(); ) {
            DocumentEvent event = iterator.next();
            reference.replace(event.getOffset(), event.getLength(), event.getText());
            if (Math.random() < 0.3) {
                check(reference, testee);
            }
        }
        check(reference, testee);
    } catch (BadLocationException e) {
        Assert.fail("bad location exception");
    }
}
Also used : ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentEvent(org.eclipse.jface.text.DocumentEvent) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 85 with BadLocationException

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

the class LinkedModeModelTest method testAddCompatibleGroups.

@Test
public void testAddCompatibleGroups() throws BadLocationException {
    IDocument doc1 = new Document(GARTEN1);
    // set up linked mode
    LinkedPositionGroup group1 = new LinkedPositionGroup();
    createLinkedPositions(group1, doc1, "MARGARETE");
    LinkedPositionGroup group2 = new LinkedPositionGroup();
    createLinkedPositions(group2, doc1, "FAUST");
    LinkedModeModel env = new LinkedModeModel();
    try {
        env.addGroup(group1);
        env.addGroup(group2);
    } catch (BadLocationException e) {
        assertFalse(true);
    }
    assertUnchanged(group1, group2);
}
Also used : LinkedPositionGroup(org.eclipse.jface.text.link.LinkedPositionGroup) LinkedModeModel(org.eclipse.jface.text.link.LinkedModeModel) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Aggregations

BadLocationException (org.eclipse.jface.text.BadLocationException)455 IDocument (org.eclipse.jface.text.IDocument)196 IRegion (org.eclipse.jface.text.IRegion)161 Test (org.junit.Test)102 Position (org.eclipse.jface.text.Position)101 Region (org.eclipse.jface.text.Region)68 Point (org.eclipse.swt.graphics.Point)61 Document (org.eclipse.jface.text.Document)47 CoreException (org.eclipse.core.runtime.CoreException)34 ArrayList (java.util.ArrayList)27 ITypedRegion (org.eclipse.jface.text.ITypedRegion)27 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)22 DocumentEvent (org.eclipse.jface.text.DocumentEvent)21 ITextSelection (org.eclipse.jface.text.ITextSelection)21 StyledText (org.eclipse.swt.custom.StyledText)18 StyledString (org.eclipse.jface.viewers.StyledString)17 IStatus (org.eclipse.core.runtime.IStatus)16 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)15 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)15 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)15