use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class LineElement method getMatches.
public FileMatch[] getMatches(AbstractTextSearchResult result) {
ArrayList<FileMatch> res = new ArrayList<>();
Match[] matches = result.getMatches(fParent);
for (Match match : matches) {
FileMatch curr = (FileMatch) match;
if (curr.getLineElement() == this) {
res.add(curr);
}
}
return res.toArray(new FileMatch[res.size()]);
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class SearchResultUpdater method handleDelta.
private void handleDelta(IResourceDelta d) {
try {
d.accept(delta -> {
switch(delta.getKind()) {
case IResourceDelta.ADDED:
return false;
case IResourceDelta.REMOVED:
IResource res = delta.getResource();
if (res instanceof IFile) {
Match[] matches = fResult.getMatches(res);
fResult.removeMatches(matches);
}
break;
case IResourceDelta.CHANGED:
// handle changed resource
break;
}
return true;
});
} catch (CoreException e) {
SearchPlugin.log(e);
}
}
use of org.eclipse.search.ui.text.Match 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.Match 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.Match in project eclipse.platform.text by eclipse.
the class PositionTrackerTest method checkInsertAtZero.
private void checkInsertAtZero(AbstractTextSearchResult result, IFile file) throws PartInitException, BadLocationException {
Match[] matches = result.getMatches(file);
int[] originalStarts = new int[matches.length];
for (int i = 0; i < originalStarts.length; i++) {
originalStarts[i] = matches[i].getOffset();
}
try {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
ITextFileBuffer fb = FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
IDocument doc = fb.getDocument();
doc.replace(0, 0, "Test");
for (int i = 0; i < originalStarts.length; i++) {
Position currentPosition = InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(matches[i]);
assertNotNull(currentPosition);
assertEquals(originalStarts[i] + "Test".length(), currentPosition.getOffset());
}
} finally {
SearchPlugin.getActivePage().closeAllEditors(false);
}
}
Aggregations