Search in sources :

Example 6 with AbstractTextSearchResult

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

the class AnnotationManagerTest method testAddAnnotation.

@Test
public void testAddAnnotation() throws Exception {
    NewSearchUI.runQueryInForeground(null, fQuery1);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    Object[] files = result.getElements();
    try {
        for (int i = 0; i < files.length; i++) {
            IFile file = (IFile) files[i];
            ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
            IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
            annotationModel.getAnnotationIterator();
            HashSet<Position> positions = new HashSet<>();
            for (Iterator<Annotation> iter = annotationModel.getAnnotationIterator(); iter.hasNext(); ) {
                Annotation annotation = iter.next();
                if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
                    positions.add(annotationModel.getPosition(annotation));
                }
            }
            Match[] matches = result.getMatches(file);
            for (int j = 0; j < matches.length; j++) {
                Position position = new Position(matches[j].getOffset(), matches[j].getLength());
                // $NON-NLS-1$
                assertTrue("position not found at: " + j, positions.remove(position));
            }
            assertEquals(0, positions.size());
        }
    } finally {
        SearchPlugin.getActivePage().closeAllEditors(false);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Annotation(org.eclipse.jface.text.source.Annotation) FileMatch(org.eclipse.search.internal.ui.text.FileMatch) Match(org.eclipse.search.ui.text.Match) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with AbstractTextSearchResult

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

the class LineAnnotationManagerTest method testLineBasedQuery.

@Test
public void testLineBasedQuery() throws Exception {
    NewSearchUI.runQueryInForeground(null, fLineQuery);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fLineQuery.getSearchResult();
    Object[] files = result.getElements();
    try {
        for (int i = 0; i < files.length; i++) {
            IFile file = (IFile) files[0];
            ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
            IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
            IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
            annotationModel.getAnnotationIterator();
            ArrayList<Position> positions = new ArrayList<>();
            for (Iterator<Annotation> iter = annotationModel.getAnnotationIterator(); iter.hasNext(); ) {
                Annotation annotation = iter.next();
                if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
                    positions.add(annotationModel.getPosition(annotation));
                }
            }
            Match[] matches = result.getMatches(file);
            for (int j = 0; j < matches.length; j++) {
                Position position = computeDocumentPositionFromLineMatch(document, matches[j]);
                assertTrue("position not found at: " + j, positions.remove(position));
            }
            assertEquals(0, positions.size());
        }
    } finally {
        SearchPlugin.getActivePage().closeAllEditors(false);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Annotation(org.eclipse.jface.text.source.Annotation) Match(org.eclipse.search.ui.text.Match) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 8 with AbstractTextSearchResult

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

the class ResultUpdaterTest method testRemoveFile.

@Test
public void testRemoveFile() throws Exception {
    NewSearchUI.runQueryInForeground(null, fQuery1);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    Object[] elements = result.getElements();
    int fileCount = result.getMatchCount(elements[0]);
    int totalCount = result.getMatchCount();
    ResourceHelper.delete((IFile) elements[0]);
    assertEquals(totalCount - fileCount, result.getMatchCount());
    assertEquals(0, result.getMatchCount(elements[0]));
}
Also used : AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Test(org.junit.Test)

Example 9 with AbstractTextSearchResult

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

the class SearchResultPageTest method checkViewerDisplay.

private void checkViewerDisplay(FileSearchPage page) {
    StructuredViewer viewer = page.getViewer();
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    // make sure all elements have items.
    if (viewer instanceof AbstractTreeViewer)
        ((AbstractTreeViewer) viewer).expandAll();
    Object[] elements = result.getElements();
    for (int i = 0; i < elements.length; i++) {
        // make sure all elements in the test result are present in the viewer and have the proper count displayed
        checkElementDisplay(viewer, result, elements[i]);
    }
}
Also used : AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult)

Example 10 with AbstractTextSearchResult

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

the class SortingTest method testSorted.

@Test
public void testSorted() throws Exception {
    NewSearchUI.activateSearchResultView();
    NewSearchUI.runQueryInForeground(null, fQuery1);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    int originalMatchCount = result.getMatchCount();
    List<Match> allMatches = new ArrayList<>(originalMatchCount);
    // first, collect all matches
    Object[] elements = result.getElements();
    for (int i = 0; i < elements.length; i++) {
        Match[] matches = result.getMatches(elements[i]);
        for (int j = 0; j < matches.length; j++) {
            allMatches.add(matches[j]);
        }
    }
    // now remove them and readd them in reverse order
    result.removeAll();
    assertTrue("removed all matches", result.getMatchCount() == 0);
    for (int i = allMatches.size() - 1; i >= 0; i--) {
        result.addMatch(allMatches.get(i));
    }
    assertEquals("Test that all matches have been added again", result.getMatchCount(), originalMatchCount);
    // now check that they're ordered by position.
    for (int i = 0; i < elements.length; i++) {
        Match[] matches = result.getMatches(elements[i]);
        assertTrue("has matches", matches.length > 0);
        for (int j = 1; j < matches.length; j++) {
            assertTrue("order problem", isLessOrEqual(matches[j - 1], matches[j]));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) 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