/*
   * Method declared in IAction.
   */
  @Override
  public final void run() {
    DartElement inputElement = EditorUtility.getEditorInputJavaElement(fEditor, false);
    if (!(inputElement instanceof SourceReference && inputElement.exists())) {
      return;
    }

    SourceReference source = (SourceReference) inputElement;
    SourceRange sourceRange;
    try {
      sourceRange = source.getSourceRange();
      if (sourceRange == null || sourceRange.getLength() == 0) {
        MessageDialog.openInformation(
            fEditor.getEditorSite().getShell(),
            SelectionActionMessages.StructureSelect_error_title,
            SelectionActionMessages.StructureSelect_error_message);
        return;
      }
    } catch (DartModelException e) {
    }
    ITextSelection selection = getTextSelection();
    SourceRange newRange = getNewSelectionRange(createSourceRange(selection), source);
    // Check if new selection differs from current selection
    if (selection.getOffset() == newRange.getOffset()
        && selection.getLength() == newRange.getLength()) {
      return;
    }
    fSelectionHistory.remember(newSourceRange(selection.getOffset(), selection.getLength()));
    try {
      fSelectionHistory.ignoreSelectionChanges();
      fEditor.selectAndReveal(newRange.getOffset(), newRange.getLength());
    } finally {
      fSelectionHistory.listenToSelectionChanges();
    }
  }
Exemplo n.º 2
0
  @Override
  public IStatus run(IProgressMonitor monitor) {
    final DartSearchResult textResult = (DartSearchResult) getSearchResult();
    textResult.removeAll();
    SearchEngine engine = SearchEngineFactory.createSearchEngine();

    //  try {
    //  int totalTicks= 1000;
    // TODO (pquitslund): add search participant support
    //  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;
    //        DartToolsPlugin.log(new Status(IStatus.ERROR, DartToolsPlugin.getPluginId(), 0,
    // message, exception));
    //      }
    //
    //      public void run() throws Exception {
    //        ticks[iPrime]=
    // participantDescriptors[iPrime].getParticipant().estimateTicks(fPatternData);
    //      }
    //    };
    //
    //    SafeRunner.run(runnable);
    //    totalTicks+= ticks[i];
    //  }

    SearchResultCollector collector = new SearchResultCollector(textResult);
    SearchScope scope = patternData.getScope();

    if (patternData.hasElement()) {
      DartElement element = ((ElementQuerySpecification) patternData).getElement();
      if (!element.exists()) {
        String patternString =
            DartElementLabels.getElementLabel(element, DartElementLabels.ALL_DEFAULT);
        return new Status(
            IStatus.ERROR,
            DartToolsPlugin.getPluginId(),
            0,
            Messages.format(
                SearchMessages.DartSearchQuery_error_element_does_not_exist, patternString),
            null);
      }

      try {
        if (patternData.isReferencesSearch()) {
          searchForReferences(engine, element, scope, null, collector, monitor);
        }
        if (patternData.isDeclarationsSearch()) {
          searchForDeclarations(engine, element, scope, null, collector, monitor);
        }
        if (patternData.isOverridesSearch()) {
          searchForOverrides(engine, element, scope, null, collector, monitor);
        }
      } catch (SearchException e) {
        DartToolsPlugin.log(e);
        // TODO: do we need to update the UI as well? Or schedule another search?
      } catch (CoreException ex) {
        DartToolsPlugin.log(ex);
      }

    } else if (patternData.hasNode()) {

      DartNode node = ((NodeQuerySpecification) patternData).getNode();
      if (node instanceof DartIdentifier) {
        DartIdentifier id = (DartIdentifier) node;

        try {
          if (patternData.isReferencesSearch()) {
            searchForReferences(engine, id, scope, null, collector, monitor);
          }
          if (patternData.isDeclarationsSearch()) {
            searchForDeclarations(engine, id, scope, null, collector, monitor);
          }
        } catch (SearchException e) {
          DartToolsPlugin.log(e);
        } catch (CoreException ex) {
          DartToolsPlugin.log(ex);
        }
      }
    }

    //      engine.search(pattern, new SearchParticipant[] {
    // SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector,
    // mainSearchPM);
    // TODO (pquitslund): add search participant support
    //      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;
    //            DartToolsPlugin.log(new Status(IStatus.ERROR, DartToolsPlugin.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.DartSearchQuery_status_ok_message,
            String.valueOf(textResult.getMatchCount()));
    return new Status(IStatus.OK, DartToolsPlugin.getPluginId(), 0, message, null);
  }