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);
}
}
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);
}
}
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]));
}
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]);
}
}
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]));
}
}
}
Aggregations