Search in sources :

Example 11 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.

the class TestSearchResult method testAddMatchDifferentStart.

@Test
public void testAddMatchDifferentStart() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 2, 0);
    result.addMatch(match1);
    assertEquals(result.getMatchCount(), 1);
    Match match2 = new Match(object, 1, 1);
    result.addMatch(match2);
    Match match3 = new Match(object, 0, 2);
    result.addMatch(match3);
    Match[] matches = result.getMatches(object);
    assertTrue("matches[0]", matches[0] == match3);
    assertTrue("matches[1]", matches[1] == match2);
    assertTrue("matches[2]", matches[2] == match1);
}
Also used : AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match) Test(org.junit.Test)

Example 12 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.

the class TestSearchResult method testMatchEvent.

@Test
public void testMatchEvent() {
    final boolean[] wasAdded = { false };
    final boolean[] wasRemoved = { false };
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    result.addListener(new ISearchResultListener() {

        @Override
        public void searchResultChanged(SearchResultEvent e) {
            if (e instanceof MatchEvent) {
                MatchEvent evt = (MatchEvent) e;
                if (evt.getKind() == MatchEvent.ADDED) {
                    wasAdded[0] = true;
                } else {
                    wasRemoved[0] = true;
                }
            }
        }
    });
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    result.addMatch(match1);
    assertTrue(wasAdded[0]);
    wasAdded[0] = false;
    result.addMatch(match1);
    assertFalse(wasAdded[0]);
    Match match2 = new Match(object, 0, 0);
    result.addMatch(match2);
    assertTrue(wasAdded[0]);
    wasAdded[0] = false;
    result.removeMatch(match2);
    assertTrue(wasRemoved[0]);
    wasRemoved[0] = false;
    result.removeMatch(match2);
    assertFalse(wasRemoved[0]);
}
Also used : SearchResultEvent(org.eclipse.search.ui.SearchResultEvent) MatchEvent(org.eclipse.search.ui.text.MatchEvent) ISearchResultListener(org.eclipse.search.ui.ISearchResultListener) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match) Test(org.junit.Test)

Example 13 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.

the class TestSearchResult method testRemoveMatch.

@Test
public void testRemoveMatch() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    result.addMatch(match1);
    Match match2 = new Match(object, 0, 0);
    result.addMatch(match2);
    assertEquals(result.getMatchCount(), 2);
    result.removeMatch(match1);
    assertEquals(result.getMatchCount(), 1);
    result.removeMatch(match1);
    assertEquals(result.getMatchCount(), 1);
}
Also used : AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match) Test(org.junit.Test)

Example 14 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.

the class TestSearchResult method testAddMatches.

@Test
public void testAddMatches() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    Match match2 = new Match(object, 0, 0);
    result.addMatches(new Match[] { match1, match2 });
    assertEquals(result.getMatchCount(), 2);
    result.addMatch(match1);
    assertEquals(result.getMatchCount(), 2);
}
Also used : AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match) Test(org.junit.Test)

Example 15 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.

the class TestSearchResult method testAddMatchDifferentStartInOrder.

@Test
public void testAddMatchDifferentStartInOrder() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    result.addMatch(match1);
    assertEquals(result.getMatchCount(), 1);
    Match match2 = new Match(object, 1, 1);
    result.addMatch(match2);
    Match match3 = new Match(object, 2, 2);
    result.addMatch(match3);
    Match[] matches = result.getMatches(object);
    assertTrue("matches[0]", matches[0] == match1);
    assertTrue("matches[1]", matches[1] == match2);
    assertTrue("matches[2]", matches[2] == match3);
}
Also used : AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match) Test(org.junit.Test)

Aggregations

AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)35 Test (org.junit.Test)20 Match (org.eclipse.search.ui.text.Match)19 ISearchQuery (org.eclipse.search.ui.ISearchQuery)11 IFile (org.eclipse.core.resources.IFile)6 Position (org.eclipse.jface.text.Position)6 Annotation (org.eclipse.jface.text.source.Annotation)5 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)5 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)4 IDocument (org.eclipse.jface.text.IDocument)4 ISearchResult (org.eclipse.search.ui.ISearchResult)4 MatchEvent (org.eclipse.search.ui.text.MatchEvent)4 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)2 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)2 ISearchResultListener (org.eclipse.search.ui.ISearchResultListener)2 SearchResultEvent (org.eclipse.search.ui.SearchResultEvent)2