/** @see IEditorActionDelegate#run */
  public void run(IAction action) {
    try {
      clearErrorMessage();

      if (editor instanceof JavaEditor) {
        try {
          IJavaElement[] editorElements = SelectionConverter.codeResolve((JavaEditor) editor);

          IJavaElement[] elements = internalSearch(editorElements, getProgressMonitor());
          if (elements != null) {
            if (elements.length == 1) {
              jumpToElement(elements[0]);
            } else if (elements.length > 1) {
              selectElementToJumpTo(elements);
            } else {
              showInfoMessage(getNoResultsMessage());
            }
          }
        } catch (JavaModelException e) {
          ImplementorsUI.log(e);
        }
      }
    } catch (RuntimeException e) {
      ImplementorsUI.log(e);
    }
  }
 @Override
 public void run(ITextSelection selection) {
   if (!ActionUtil.isEditable(fEditor)) return;
   RefactoringExecutionStarter.startChangeTypeRefactoring(
       SelectionConverter.getInputAsCompilationUnit(fEditor),
       getShell(),
       selection.getOffset(),
       selection.getLength());
 }
 @Override
 protected void startTextSelectionRefactoring(
     JavaEditor javaEditor, ITextSelection textSelection) {
   Shell shell = javaEditor.getSite().getShell();
   InvertLoopRefactoring refactoring =
       new InvertLoopRefactoring(
           SelectionConverter.getInputAsCompilationUnit(javaEditor),
           textSelection.getOffset(),
           textSelection.getLength());
   new RefactoringStarter()
       .activate(
           new InvertLoopWizard(refactoring),
           shell,
           JFlowRefactoringMessages.InvertLoopActions_dialog_title,
           RefactoringSaveHelper.SAVE_NOTHING);
 }
  private static IStructuredSelection getStructuredSelection(
      ISelection selection, IWorkbenchPart workbenchPart) {
    if (selection == null) return null;

    IStructuredSelection structuredSelection = null;

    if (selection instanceof IStructuredSelection) {
      structuredSelection = (IStructuredSelection) selection;
    } else if (workbenchPart != null) {
      try {
        structuredSelection = SelectionConverter.getStructuredSelection(workbenchPart);
      } catch (JavaModelException e) {
        return null;
      }
    }

    return structuredSelection;
  }
 /**
  * Note: This constructor is for internal use only. Clients should not call this constructor.
  *
  * @param editor the java editor
  * @noreference This constructor is not intended to be referenced by clients.
  */
 public ChangeTypeAction(JavaEditor editor) {
   this(editor.getEditorSite());
   fEditor = editor;
   setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
 }