Search in sources :

Example 31 with Match

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

the class LineElement method getNumberOfMatches.

public int getNumberOfMatches(AbstractTextSearchResult result) {
    int count = 0;
    Match[] matches = result.getMatches(fParent);
    for (Match match : matches) {
        FileMatch curr = (FileMatch) match;
        if (curr.getLineElement() == this) {
            count++;
        }
    }
    return count;
}
Also used : Match(org.eclipse.search.ui.text.Match)

Example 32 with Match

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

the class ReplaceRefactoring method collectMatches.

private void collectMatches(Object object) throws CoreException {
    if (object instanceof LineElement) {
        LineElement lineElement = (LineElement) object;
        FileMatch[] matches = lineElement.getMatches(fResult);
        for (FileMatch fileMatch : matches) {
            if (isMatchToBeIncluded(fileMatch)) {
                getBucket(fileMatch.getFile()).add(fileMatch);
            }
        }
    } else if (object instanceof IContainer) {
        IContainer container = (IContainer) object;
        IResource[] members = container.members();
        for (IResource member : members) {
            collectMatches(member);
        }
    } else if (object instanceof IFile) {
        Match[] matches = fResult.getMatches(object);
        if (matches.length > 0) {
            Collection<FileMatch> bucket = null;
            for (Match match : matches) {
                FileMatch fileMatch = (FileMatch) match;
                if (isMatchToBeIncluded(fileMatch)) {
                    if (bucket == null) {
                        bucket = getBucket((IFile) object);
                    }
                    bucket.add(fileMatch);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) Match(org.eclipse.search.ui.text.Match)

Example 33 with Match

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

the class AnnotationHighlighter method addHighlights.

@Override
public void addHighlights(Match[] matches) {
    HashMap<Annotation, Position> map = new HashMap<>(matches.length);
    for (Match match : matches) {
        int offset = match.getOffset();
        int length = match.getLength();
        if (offset >= 0 && length >= 0) {
            Position position = createPosition(match);
            if (position != null) {
                Annotation annotation = match.isFiltered() ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null) : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null);
                fMatchesToAnnotations.put(match, annotation);
                map.put(annotation, position);
            }
        }
    }
    addAnnotations(map);
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) Annotation(org.eclipse.jface.text.source.Annotation) Match(org.eclipse.search.ui.text.Match)

Example 34 with Match

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

the class AnnotationHighlighter method removeHighlights.

@Override
public void removeHighlights(Match[] matches) {
    HashSet<Annotation> annotations = new HashSet<>(matches.length);
    for (Match match : matches) {
        Annotation annotation = fMatchesToAnnotations.remove(match);
        if (annotation != null) {
            annotations.add(annotation);
        }
    }
    removeAnnotations(annotations);
}
Also used : Annotation(org.eclipse.jface.text.source.Annotation) HashSet(java.util.HashSet) Match(org.eclipse.search.ui.text.Match)

Example 35 with Match

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

the class EditorAccessHighlighter method removeHighlights.

@Override
public void removeHighlights(Match[] matches) {
    Map<IAnnotationModel, HashSet<Annotation>> setsByAnnotationModel = new HashMap<>();
    for (Match match : matches) {
        Annotation annotation = fMatchesToAnnotations.remove(match);
        if (annotation != null) {
            Set<Annotation> annotations = getSet(setsByAnnotationModel, match);
            if (annotations != null)
                annotations.add(annotation);
        }
    }
    for (IAnnotationModel model : setsByAnnotationModel.keySet()) {
        Set<Annotation> set = setsByAnnotationModel.get(model);
        removeAnnotations(model, set);
    }
}
Also used : HashMap(java.util.HashMap) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation) HashSet(java.util.HashSet) Match(org.eclipse.search.ui.text.Match)

Aggregations

Match (org.eclipse.search.ui.text.Match)45 AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)19 Test (org.junit.Test)14 ISearchQuery (org.eclipse.search.ui.ISearchQuery)11 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)7 IFile (org.eclipse.core.resources.IFile)7 Position (org.eclipse.jface.text.Position)7 Annotation (org.eclipse.jface.text.source.Annotation)6 ArrayList (java.util.ArrayList)5 BadLocationException (org.eclipse.jface.text.BadLocationException)5 IDocument (org.eclipse.jface.text.IDocument)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)4 ISearchResult (org.eclipse.search.ui.ISearchResult)4 IResource (org.eclipse.core.resources.IResource)3 MatchEvent (org.eclipse.search.ui.text.MatchEvent)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2