Search in sources :

Example 41 with Match

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

the class JsSearchRequestor method addSearchMatch.

protected void addSearchMatch(IDocument jspDocument, IFile jspFile, int jspStart, int jspEnd, String jspText) {
    if (!jspFile.exists()) {
        return;
    }
    int lineNumber = -1;
    try {
        lineNumber = jspDocument.getLineOfOffset(jspStart);
    } catch (BadLocationException e) {
        // $NON-NLS-1$
        Logger.logException("offset: " + Integer.toString(jspStart), e);
    }
    createSearchMarker(jspFile, jspStart, jspEnd, lineNumber);
    if (this.fJavaRequestor != null) {
        Match match = new Match(jspFile, jspStart, jspEnd - jspStart);
        this.fJavaRequestor.reportMatch(match);
    }
}
Also used : BadLocationException(org.eclipse.jface.text.BadLocationException) Match(org.eclipse.search.ui.text.Match)

Example 42 with Match

use of org.eclipse.search.ui.text.Match in project titan.EclipsePlug-ins by eclipse.

the class SearchLabelProvider method getText.

@Override
public String getText(final Object element) {
    if (element instanceof IResource) {
        return WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider().getText(element);
    }
    if (element instanceof Match) {
        Match match = (Match) element;
        IFile logFile = (IFile) match.getElement();
        RandomAccessFile file = null;
        String result = "";
        try {
            // TODO: This should be cached in some way
            File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
            LogRecordIndex[] indexes = LogFileCacheHandler.readLogRecordIndexFile(indexFile, match.getOffset(), 1);
            file = new RandomAccessFile(new File(logFile.getLocationURI()), "r");
            int length = indexes[0].getRecordLength() > MAX_TEXT_LENGTH ? MAX_TEXT_LENGTH : indexes[0].getRecordLength();
            byte[] record = new byte[length];
            file.seek(indexes[0].getFileOffset());
            file.read(record);
            result = new String(record);
        } catch (FileNotFoundException e) {
            ErrorReporter.logExceptionStackTrace(e);
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": File not found " + e.getMessage()));
            return logFile.getName() + ": File not found";
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new TechnicalException("Error while reading the log file." + e.getMessage()));
            return "Error while reading the log file.";
        } finally {
            IOUtils.closeQuietly(file);
        }
        return result;
    }
    return "Unexpected element";
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Match(org.eclipse.search.ui.text.Match) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource)

Example 43 with Match

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

the class ErlSearchQuery method addMatches.

private void addMatches(final List<ModuleLineFunctionArityRef> chunk) {
    final List<Match> l = Lists.newArrayListWithCapacity(chunk.size());
    final List<ErlangSearchElement> resultAdded = Lists.newArrayListWithCapacity(chunk.size());
    for (final ModuleLineFunctionArityRef ref : chunk) {
        final Match m = SearchUtil.createMatch(ref, pathToModuleMap);
        l.add(m);
        resultAdded.add((ErlangSearchElement) m.getElement());
    }
    fSearchResult = (ErlangSearchResult) getSearchResult();
    final List<ErlangSearchElement> result = fSearchResult.getResult();
    result.addAll(resultAdded);
    fSearchResult.setResult(result);
    fSearchResult.addMatches(l.toArray(new Match[l.size()]));
}
Also used : ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) Match(org.eclipse.search.ui.text.Match)

Example 44 with Match

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

the class ErlangSearchResult method removeMatches.

@Override
public void removeMatches(final Match[] matches) {
    for (final Match match : matches) {
        final Object element = match.getElement();
        final int matchCount = getMatchCount(element);
        if (matchCount == 1 || matchCount == countMatches(element, matches)) {
            removeElement(element);
        }
    }
    super.removeMatches(matches);
}
Also used : Match(org.eclipse.search.ui.text.Match)

Example 45 with Match

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

the class ErlangSearchResult method computeContainedMatches.

@Override
public Match[] computeContainedMatches(final AbstractTextSearchResult aResult, final IFile file) {
    final ErlangSearchResult esr = (ErlangSearchResult) aResult;
    final List<Match> l = new ArrayList<>();
    final List<ErlangSearchElement> eses = esr.getResult();
    final String name = file.getName();
    if (eses == null) {
        // || !ErlideUtil.hasModuleExtension(name)) {
        return ErlangSearchResult.NO_MATCHES;
    }
    for (final ErlangSearchElement ese : eses) {
        final String moduleName = new Path(ese.getModuleName()).lastSegment();
        if (moduleName.equals(name)) {
            final Match[] matches = getMatches(ese);
            Collections.addAll(l, matches);
        }
    }
    return l.toArray(new Match[l.size()]);
}
Also used : Path(org.eclipse.core.runtime.Path) ArrayList(java.util.ArrayList) 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