コード例 #1
0
  /* (non-Javadoc)
   * Method declared on SelectionDispatchAction.
   */
  public void run(ITextSelection selection) {
    IModelElement input = SelectionConverter.getInput(fEditor);
    if (!ActionUtil.isProcessable(getShell(), input)) return;

    try {
      IModelElement[] elements = resolveModelElements();
      if (elements == null) return;
      List candidates = new ArrayList(elements.length);
      for (int i = 0; i < elements.length; i++) {
        IModelElement[] resolvedElements = CallHierarchyUI.getCandidates(elements[i]);
        if (resolvedElements != null) candidates.addAll(Arrays.asList(resolvedElements));
      }
      if (candidates.isEmpty()) {
        IModelElement enclosingMethod = getEnclosingMethod(input, selection);
        if (enclosingMethod != null) {
          candidates.add(enclosingMethod);
        }
      }
      run((IModelElement[]) candidates.toArray(new IModelElement[candidates.size()]));
    } catch (InvocationTargetException e) {
      ExceptionHandler.handle(
          e,
          getShell(),
          getErrorDialogTitle(),
          ActionMessages.SelectionConverter_codeResolve_failed);
    } catch (InterruptedException e) {
      // cancelled
    }
  }
コード例 #2
0
  /* (non-Javadoc)
   * Method declared on SelectionDispatchAction.
   */
  public void run(IStructuredSelection selection) {
    if (selection.size() != 1) return;
    Object input = selection.getFirstElement();
    if (!(input instanceof IModelElement))
      input = (IModelElement) ((IAdaptable) input).getAdapter(IModelElement.class);
    if (!(input instanceof IModelElement)) {
      IStatus status =
          createStatus(CallHierarchyMessages.OpenCallHierarchyAction_messages_no_java_element);
      openErrorDialog(status);
      return;
    }
    IModelElement element = (IModelElement) input;
    if (!ActionUtil.isProcessable(getShell(), element)) return;

    List result = new ArrayList(1);
    IStatus status = compileCandidates(result, element);
    if (status.isOK()) {
      run((IModelElement[]) result.toArray(new IModelElement[result.size()]));
    } else {
      openErrorDialog(status);
    }
  }