@Override
  protected void doRun(
      ITextSelection selection, Event event, UIInstrumentationBuilder instrumentation) {
    CompilationUnit input = SelectionConverter.getInputAsCompilationUnit(editor);
    instrumentation.record(input);

    if (!ActionUtil.isProcessable(getShell(), input)) {
      instrumentation.metric("Problem", "input cu is not processable");
      return;
    }

    try {
      DartElement[] elements = SelectionConverter.codeResolveOrInputForked(editor);
      if (elements == null) {
        instrumentation.metric("Problem", "elements was null");
        return;
      }
      ActionInstrumentationUtilities.record(elements, "Selections", instrumentation);

      List<DartElement> candidates = new ArrayList<DartElement>(elements.length);
      for (int i = 0; i < elements.length; i++) {
        DartElement element = elements[i];
        if (CallHierarchy.isPossibleInputElement(element)) {
          candidates.add(element);
        }
      }

      if (candidates.isEmpty()) {
        DartElement enclosingMethod = getEnclosingMethod(input, selection);
        if (enclosingMethod != null) {
          candidates.add(enclosingMethod);
        }
      }
      ActionInstrumentationUtilities.record(candidates, "Candidates", instrumentation);

      CallHierarchyUI.openSelectionDialog(
          candidates.toArray(new DartElement[candidates.size()]), getSite().getWorkbenchWindow());

    } catch (InvocationTargetException e) {
      ExceptionHandler.handle(
          e,
          getShell(),
          CallHierarchyMessages.OpenCallHierarchyAction_dialog_title,
          ActionMessages.SelectionConverter_codeResolve_failed);
    } catch (InterruptedException e) {
      // cancelled
      instrumentation.metric("Problem", "User cancelled");
    }
  }
Esempio n. 2
0
  @Override
  public void run(ITextSelection selection) {
    CompilationUnit input = SelectionConverter.getInputAsCompilationUnit(editor);
    if (!ActionUtil.isProcessable(getShell(), input)) {
      return;
    }

    try {
      DartElement[] elements = SelectionConverter.codeResolveOrInputForked(editor);
      if (elements == null) {
        return;
      }
      List<DartElement> candidates = new ArrayList<DartElement>(elements.length);
      for (int i = 0; i < elements.length; i++) {
        DartElement element = elements[i];
        if (CallHierarchy.isPossibleInputElement(element)) {
          candidates.add(element);
        }
      }
      if (candidates.isEmpty()) {
        DartElement enclosingMethod = getEnclosingMethod(input, selection);
        if (enclosingMethod != null) {
          candidates.add(enclosingMethod);
        }
      }
      CallHierarchyUI.openSelectionDialog(
          candidates.toArray(new DartElement[candidates.size()]), getSite().getWorkbenchWindow());

    } catch (InvocationTargetException e) {
      ExceptionHandler.handle(
          e,
          getShell(),
          CallHierarchyMessages.OpenCallHierarchyAction_dialog_title,
          ActionMessages.SelectionConverter_codeResolve_failed);
    } catch (InterruptedException e) {
      // cancelled
    }
  }