Example #1
0
  /**
   * @return a tuple with the refactoring request, the processor and a boolean indicating if all
   *     pre-conditions succedded.
   * @throws MisconfigurationException
   */
  @Override
  protected MarkOccurrencesRequest createRequest(
      BaseEditor baseEditor, IDocumentProvider documentProvider, IProgressMonitor monitor)
      throws BadLocationException, OperationCanceledException, CoreException,
          MisconfigurationException {
    if (!MarkOccurrencesPreferencesPage.useMarkOccurrences()) {
      return new PyMarkOccurrencesRequest(false, null, null);
    }
    PyEdit pyEdit = (PyEdit) baseEditor;

    // ok, the editor is still there wit ha document... move on
    PyRefactorAction pyRefactorAction = getRefactorAction(pyEdit);

    final RefactoringRequest req =
        getRefactoringRequest(pyEdit, pyRefactorAction, PySelection.fromTextSelection(this.ps));

    if (req == null
        || !req.nature
            .getRelatedInterpreterManager()
            .isConfigured()) { // we check if it's configured because it may still be a stub...
      return new PyMarkOccurrencesRequest(false, null, null);
    }

    PyReferenceSearcher searcher = new PyReferenceSearcher(req);
    // to see if a new request was not created in the meantime (in which case this one will be
    // cancelled)
    if (monitor.isCanceled()) {
      return new PyMarkOccurrencesRequest(false, null, null);
    }

    try {
      searcher.prepareSearch(req);
      if (monitor.isCanceled()) {
        return new PyMarkOccurrencesRequest(false, null, null);
      }
      searcher.search(req);
      if (monitor.isCanceled()) {
        return new PyMarkOccurrencesRequest(false, null, null);
      }
      // Ok, search succeeded.
      return new PyMarkOccurrencesRequest(true, req, searcher);
    } catch (PyReferenceSearcher.SearchException e) {
      // Suppress search failures.
      return new PyMarkOccurrencesRequest(false, null, null);
    } catch (Throwable e) {
      throw new RuntimeException(
          "Error in occurrences while analyzing modName:"
              + req.moduleName
              + " initialName:"
              + req.initialName
              + " line (start at 0):"
              + req.ps.getCursorLine(),
          e);
    }
  }