Search in sources :

Example 6 with Match

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

the class EditorAccessHighlighter method handleContentReplaced.

@Override
protected void handleContentReplaced(IFileBuffer buffer) {
    if (!(buffer instanceof ITextFileBuffer))
        return;
    IDocument document = null;
    ITextFileBuffer textBuffer = (ITextFileBuffer) buffer;
    for (Match match : fMatchesToAnnotations.keySet()) {
        document = fEditorAcess.getDocument(match);
        if (document != null)
            break;
    }
    if (document != null && document.equals(textBuffer.getDocument())) {
        Match[] matches = new Match[fMatchesToAnnotations.keySet().size()];
        fMatchesToAnnotations.keySet().toArray(matches);
        removeAll();
        addHighlights(matches);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Match(org.eclipse.search.ui.text.Match)

Example 7 with Match

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

the class EditorAnnotationManager method addAnnotations.

private void addAnnotations(AbstractTextSearchResult result) {
    IEditorMatchAdapter matchAdapter = result.getEditorMatchAdapter();
    if (matchAdapter == null)
        return;
    Match[] matches = matchAdapter.computeContainedMatches(result, fEditor);
    if (matches == null || matches.length == 0)
        return;
    addAnnotations(matches);
}
Also used : IEditorMatchAdapter(org.eclipse.search.ui.text.IEditorMatchAdapter) Match(org.eclipse.search.ui.text.Match)

Example 8 with Match

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

the class PositionTracker method dirtyStateChanged.

@Override
public void dirtyStateChanged(IFileBuffer buffer, boolean isDirty) {
    if (isDirty)
        return;
    final int[] trackCount = new int[1];
    doForExistingMatchesIn(buffer, new IFileBufferMatchOperation() {

        @Override
        public void run(ITextFileBuffer textBuffer, Match match) {
            trackCount[0]++;
            Position pos = fMatchesToPositions.get(match);
            if (pos != null) {
                if (pos.isDeleted()) {
                    AbstractTextSearchResult result = fMatchesToSearchResults.get(match);
                    // might be that the containing element has been removed.
                    if (result != null) {
                        result.removeMatch(match);
                    }
                    untrackPosition(textBuffer, match);
                } else {
                    if (match.getBaseUnit() == Match.UNIT_LINE) {
                        try {
                            pos = convertToLinePosition(pos, textBuffer.getDocument());
                        } catch (BadLocationException e) {
                            SearchPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, e.getLocalizedMessage(), e));
                        }
                    }
                    match.setOffset(pos.getOffset());
                    match.setLength(pos.getLength());
                }
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Position(org.eclipse.jface.text.Position) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) BadLocationException(org.eclipse.jface.text.BadLocationException) Match(org.eclipse.search.ui.text.Match)

Example 9 with Match

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

the class PositionTracker method bufferCreated.

// IFileBufferListener implementation ---------------------------------------------------------------------
@Override
public void bufferCreated(IFileBuffer buffer) {
    final int[] trackCount = new int[1];
    if (!(buffer instanceof ITextFileBuffer))
        return;
    IPath location = buffer.getLocation();
    if (location == null)
        return;
    IFile file = FileBuffers.getWorkspaceFileAtLocation(location);
    if (file == null)
        return;
    ISearchQuery[] queries = NewSearchUI.getQueries();
    for (ISearchQuery query : queries) {
        ISearchResult result = query.getSearchResult();
        if (result instanceof AbstractTextSearchResult) {
            AbstractTextSearchResult textResult = (AbstractTextSearchResult) result;
            IFileMatchAdapter adapter = textResult.getFileMatchAdapter();
            if (adapter != null) {
                Match[] matches = adapter.computeContainedMatches(textResult, file);
                for (Match match : matches) {
                    trackCount[0]++;
                    trackPosition((AbstractTextSearchResult) result, (ITextFileBuffer) buffer, match);
                }
            }
        }
    }
}
Also used : ISearchResult(org.eclipse.search.ui.ISearchResult) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IFileMatchAdapter(org.eclipse.search.ui.text.IFileMatchAdapter) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match)

Example 10 with Match

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

the class FileTreeContentProvider method initialize.

private synchronized void initialize(AbstractTextSearchResult result) {
    fResult = result;
    fChildrenMap = new HashMap<>();
    boolean showLineMatches = !((FileSearchQuery) fResult.getQuery()).isFileNameSearch();
    if (result != null) {
        Object[] elements = result.getElements();
        for (Object element : elements) {
            if (showLineMatches) {
                Match[] matches = result.getMatches(element);
                for (Match match : matches) {
                    insert(((FileMatch) match).getLineElement(), false);
                }
            } else {
                insert(element, false);
            }
        }
    }
}
Also used : 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