Search in sources :

Example 1 with ISearchRequestor

use of org.eclipse.jdt.ui.search.ISearchRequestor in project che by eclipse.

the class JavaSearchQuery method run.

public IStatus run(IProgressMonitor monitor) {
    final JavaSearchResult textResult = (JavaSearchResult) getSearchResult();
    textResult.removeAll();
    // Don't need to pass in working copies in 3.0 here
    SearchEngine engine = new SearchEngine();
    try {
        int totalTicks = 1000;
        IProject[] projects = JavaSearchScopeFactory.getInstance().getProjects(fPatternData.getScope());
        final SearchParticipantRecord[] participantDescriptors = SearchParticipantsExtensionPoint.getInstance().getSearchParticipants(projects);
        final int[] ticks = new int[participantDescriptors.length];
        for (int i = 0; i < participantDescriptors.length; i++) {
            final int iPrime = i;
            ISafeRunnable runnable = new ISafeRunnable() {

                public void handleException(Throwable exception) {
                    ticks[iPrime] = 0;
                    String message = SearchMessages.JavaSearchQuery_error_participant_estimate;
                    JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, exception));
                }

                public void run() throws Exception {
                    ticks[iPrime] = participantDescriptors[iPrime].getParticipant().estimateTicks(fPatternData);
                }
            };
            SafeRunner.run(runnable);
            totalTicks += ticks[i];
        }
        SearchPattern pattern;
        String stringPattern;
        if (fPatternData instanceof ElementQuerySpecification) {
            IJavaElement element = ((ElementQuerySpecification) fPatternData).getElement();
            stringPattern = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
            if (!element.exists()) {
                return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null);
            }
            pattern = SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
        } else {
            PatternQuerySpecification patternSpec = (PatternQuerySpecification) fPatternData;
            stringPattern = patternSpec.getPattern();
            int matchMode = getMatchMode(stringPattern) | SearchPattern.R_ERASURE_MATCH;
            if (patternSpec.isCaseSensitive())
                matchMode |= SearchPattern.R_CASE_SENSITIVE;
            pattern = SearchPattern.createPattern(patternSpec.getPattern(), patternSpec.getSearchFor(), patternSpec.getLimitTo(), matchMode);
        }
        if (pattern == null) {
            return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_unsupported_pattern, stringPattern), null);
        }
        monitor.beginTask(Messages.format(SearchMessages.JavaSearchQuery_task_label, stringPattern), totalTicks);
        IProgressMonitor mainSearchPM = new SubProgressMonitor(monitor, 1000);
        boolean ignorePotentials = NewSearchUI.arePotentialMatchesIgnored();
        NewSearchResultCollector collector = new NewSearchResultCollector(textResult, ignorePotentials);
        engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector, mainSearchPM);
        for (int i = 0; i < participantDescriptors.length; i++) {
            final ISearchRequestor requestor = new SearchRequestor(participantDescriptors[i].getParticipant(), textResult);
            final IProgressMonitor participantPM = new SubProgressMonitor(monitor, ticks[i]);
            final int iPrime = i;
            ISafeRunnable runnable = new ISafeRunnable() {

                public void handleException(Throwable exception) {
                    participantDescriptors[iPrime].getDescriptor().disable();
                    String message = SearchMessages.JavaSearchQuery_error_participant_search;
                    JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, exception));
                }

                public void run() throws Exception {
                    final IQueryParticipant participant = participantDescriptors[iPrime].getParticipant();
                    final PerformanceStats stats = PerformanceStats.getStats(PERF_SEARCH_PARTICIPANT, participant);
                    stats.startRun();
                    participant.search(requestor, fPatternData, participantPM);
                    stats.endRun();
                }
            };
            SafeRunner.run(runnable);
        }
    } catch (CoreException e) {
        return e.getStatus();
    }
    String message = Messages.format(SearchMessages.JavaSearchQuery_status_ok_message, String.valueOf(textResult.getMatchCount()));
    return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, message, null);
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IJavaElement(org.eclipse.jdt.core.IJavaElement) IQueryParticipant(org.eclipse.jdt.ui.search.IQueryParticipant) ElementQuerySpecification(org.eclipse.jdt.ui.search.ElementQuerySpecification) PatternQuerySpecification(org.eclipse.jdt.ui.search.PatternQuerySpecification) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ISearchRequestor(org.eclipse.jdt.ui.search.ISearchRequestor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISearchRequestor(org.eclipse.jdt.ui.search.ISearchRequestor) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with ISearchRequestor

use of org.eclipse.jdt.ui.search.ISearchRequestor in project webtools.sourceediting by eclipse.

the class JSPQueryParticipant method search.

/**
 * @see org.eclipse.jdt.ui.search.IQueryParticipant#search(org.eclipse.jdt.ui.search.ISearchRequestor, org.eclipse.jdt.ui.search.QuerySpecification, org.eclipse.core.runtime.IProgressMonitor)
 */
public void search(ISearchRequestor requestor, QuerySpecification querySpecification, IProgressMonitor monitor) throws CoreException {
    if (shouldSupplyJSPSearchResultsToJavaSearch()) {
        // do search based on the particular Java query
        if (querySpecification instanceof ElementQuerySpecification) {
            // element search (eg. from global find references in Java file)
            ElementQuerySpecification elementQuery = (ElementQuerySpecification) querySpecification;
            IJavaElement element = elementQuery.getElement();
            if (DEBUG)
                // $NON-NLS-1$
                System.out.println("JSP Query Participant searching on ELEMENT: " + element);
            SearchRequestor jspRequestor = new JSPSearchRequestor(requestor);
            // pa_TODO need to adapt JavaSearchScope to a JSPSearchScope
            JSPSearchSupport.getInstance().search(element, new JSPSearchScope(), jspRequestor, monitor);
        } else if (querySpecification instanceof PatternQuerySpecification) {
            // pattern search (eg. from Java search page)
            PatternQuerySpecification patternQuery = (PatternQuerySpecification) querySpecification;
            String pattern = patternQuery.getPattern();
            if (DEBUG)
                // $NON-NLS-1$
                System.out.println("JSP Query Participant searching on PATTERN: " + pattern);
            SearchRequestor jspRequestor = new JSPSearchRequestor(requestor);
            JSPSearchSupport.getInstance().search(pattern, new JSPSearchScope(), patternQuery.getSearchFor(), patternQuery.getLimitTo(), SearchPattern.R_PATTERN_MATCH, false, jspRequestor, monitor);
        }
    }
}
Also used : SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) ISearchRequestor(org.eclipse.jdt.ui.search.ISearchRequestor) JSPSearchRequestor(org.eclipse.jst.jsp.ui.internal.java.search.JSPSearchRequestor) IJavaElement(org.eclipse.jdt.core.IJavaElement) ElementQuerySpecification(org.eclipse.jdt.ui.search.ElementQuerySpecification) PatternQuerySpecification(org.eclipse.jdt.ui.search.PatternQuerySpecification) JSPSearchScope(org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope) JSPSearchRequestor(org.eclipse.jst.jsp.ui.internal.java.search.JSPSearchRequestor)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)2 ElementQuerySpecification (org.eclipse.jdt.ui.search.ElementQuerySpecification)2 ISearchRequestor (org.eclipse.jdt.ui.search.ISearchRequestor)2 PatternQuerySpecification (org.eclipse.jdt.ui.search.PatternQuerySpecification)2 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 IStatus (org.eclipse.core.runtime.IStatus)1 PerformanceStats (org.eclipse.core.runtime.PerformanceStats)1 Status (org.eclipse.core.runtime.Status)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)1 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)1 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)1 IQueryParticipant (org.eclipse.jdt.ui.search.IQueryParticipant)1 JSPSearchScope (org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope)1 JSPSearchRequestor (org.eclipse.jst.jsp.ui.internal.java.search.JSPSearchRequestor)1