Search in sources :

Example 6 with ElementQuerySpecification

use of org.eclipse.jdt.ui.search.ElementQuerySpecification 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 7 with ElementQuerySpecification

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

the class NonDeprecatedFilter method isApplicable.

@Override
public boolean isApplicable(JavaSearchQuery query) {
    QuerySpecification spec = query.getSpecification();
    if (spec instanceof ElementQuerySpecification) {
        ElementQuerySpecification elementSpec = (ElementQuerySpecification) spec;
        IJavaElement element = elementSpec.getElement();
        return isParameterizedElement(element);
    }
    return false;
}
Also used : QuerySpecification(org.eclipse.jdt.ui.search.QuerySpecification) PatternQuerySpecification(org.eclipse.jdt.ui.search.PatternQuerySpecification) ElementQuerySpecification(org.eclipse.jdt.ui.search.ElementQuerySpecification) IJavaElement(org.eclipse.jdt.core.IJavaElement) ElementQuerySpecification(org.eclipse.jdt.ui.search.ElementQuerySpecification)

Example 8 with ElementQuerySpecification

use of org.eclipse.jdt.ui.search.ElementQuerySpecification 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

ElementQuerySpecification (org.eclipse.jdt.ui.search.ElementQuerySpecification)8 IJavaElement (org.eclipse.jdt.core.IJavaElement)5 JavaSearchQuery (org.eclipse.jdt.internal.ui.search.JavaSearchQuery)3 PatternQuerySpecification (org.eclipse.jdt.ui.search.PatternQuerySpecification)3 JavaSearchScopeFactory (org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory)2 ISearchRequestor (org.eclipse.jdt.ui.search.ISearchRequestor)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Region (org.eclipse.che.ide.ext.java.shared.dto.Region)1 JavaProject (org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject)1 FindUsagesResponse (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse)1 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 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 PerformanceStats (org.eclipse.core.runtime.PerformanceStats)1 Status (org.eclipse.core.runtime.Status)1