@Override
 public void run(ITextSelection selection) {
   if (!ActionUtil.isEditable(fEditor)) return;
   RefactoringExecutionStarter.startChangeTypeRefactoring(
       SelectionConverter.getInputAsCompilationUnit(fEditor),
       getShell(),
       selection.getOffset(),
       selection.getLength());
 }
 @Override
 public void run(ITextSelection selection) {
   if (!ActionUtil.isEditable(fEditor)) return;
   ConvertGroovyLocalToFieldRefactoring refactoring =
       new ConvertGroovyLocalToFieldRefactoring(
           fEditor.getGroovyCompilationUnit(), selection.getOffset(), selection.getLength());
   new RefactoringStarter()
       .activate(
           new PromoteTempWizard(refactoring),
           getShell(),
           RefactoringMessages.ConvertLocalToField_title,
           RefactoringSaveHelper.SAVE_NOTHING);
 }
 /* (non-JavaDoc)
  * Method declared in SelectionDispatchAction.
  */
 @Override
 public final void run(ITextSelection ts) {
   ITypeRoot input = getEditorInput(fEditor);
   if (!ActionUtil.isProcessable(getShell(), input)) return;
   OccurrencesFinder finder = new OccurrencesFinder();
   FindOccurrencesEngine engine = FindOccurrencesEngine.create(finder);
   try {
     String result = engine.run(input, ts.getOffset(), ts.getLength());
     if (result != null) showMessage(getShell(), fEditor, result);
   } catch (JavaModelException e) {
     JavaPlugin.log(e);
   }
 }
 @Override
 public void run(IStructuredSelection selection) {
   IMember member = getMember(selection);
   if (!ActionUtil.isProcessable(getShell(), member)) return;
   FindOccurrencesEngine engine = FindOccurrencesEngine.create(new OccurrencesFinder());
   try {
     ISourceRange range = member.getNameRange();
     String result = engine.run(member.getTypeRoot(), range.getOffset(), range.getLength());
     if (result != null) showMessage(getShell(), fActionBars, result);
   } catch (JavaModelException e) {
     JavaPlugin.log(e);
   }
 }
 @Override
 public void run(IStructuredSelection selection) {
   try {
     IMember member = getMember(selection);
     if (member == null || !ActionUtil.isEditable(getShell(), member)) return;
     ISourceRange range = member.getNameRange();
     RefactoringExecutionStarter.startChangeTypeRefactoring(
         member.getCompilationUnit(), getShell(), range.getOffset(), range.getLength());
   } catch (CoreException e) {
     ExceptionHandler.handle(
         e,
         RefactoringMessages.ChangeTypeAction_dialog_title,
         RefactoringMessages.ChangeTypeAction_exception);
   }
 }
 /**
  * Try to execute the correction command.
  *
  * @return <code>true</code> iff the correction could be started
  * @since 3.6
  */
 public boolean doExecute() {
   ISelection selection = fEditor.getSelectionProvider().getSelection();
   ICompilationUnit cu = JavaUI.getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
   IAnnotationModel model =
       JavaUI.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
   if (selection instanceof ITextSelection && cu != null && model != null) {
     if (!ActionUtil.isEditable(fEditor)) {
       return false;
     }
     ICompletionProposal proposal =
         findCorrection(fId, fIsAssist, (ITextSelection) selection, cu, model);
     if (proposal != null) {
       invokeProposal(proposal, ((ITextSelection) selection).getOffset());
       return true;
     }
   }
   return false;
 }
  public JavadocHelpContext(IContext context, Object[] elements) throws JavaModelException {
    Assert.isNotNull(elements);
    if (context instanceof IContext2) fTitle = ((IContext2) context).getTitle();

    List helpResources = new ArrayList();

    String javadocSummary = null;
    for (int i = 0; i < elements.length; i++) {
      if (elements[i] instanceof IJavaElement) {
        IJavaElement element = (IJavaElement) elements[i];
        // if element isn't on the build path skip it
        if (!ActionUtil.isOnBuildPath(element)) continue;

        // Create Javadoc summary
        if (BUG_85721_FIXED) {
          if (javadocSummary == null) {
            javadocSummary = retrieveText(element);
            if (javadocSummary != null) {
              String elementLabel =
                  JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_DEFAULT);

              // FIXME: needs to be NLSed once the code becomes active
              javadocSummary =
                  "<b>Javadoc for "
                      + elementLabel
                      + ":</b><br>"
                      + javadocSummary; //$NON-NLS-1$//$NON-NLS-2$
            }
          } else {
            javadocSummary = ""; // no Javadoc summary for multiple selection //$NON-NLS-1$
          }
        }

        URL url = JavaUI.getJavadocLocation(element, true);
        if (url == null || doesNotExist(url)) {
          IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element);
          if (root != null) {
            url = JavaUI.getJavadocBaseLocation(element);
            if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
              element = element.getJavaProject();
            } else {
              element = root;
            }
            url = JavaUI.getJavadocLocation(element, false);
          }
        }
        if (url != null) {
          IHelpResource javaResource = new JavaUIHelpResource(element, getURLString(url));
          helpResources.add(javaResource);
        }
      }
    }

    // Add static help topics
    if (context != null) {
      IHelpResource[] resources = context.getRelatedTopics();
      if (resources != null) {
        for (int j = 0; j < resources.length; j++) {
          helpResources.add(resources[j]);
        }
      }
    }

    fHelpResources =
        (IHelpResource[]) helpResources.toArray(new IHelpResource[helpResources.size()]);

    if (context != null) fText = context.getText();

    if (BUG_85721_FIXED) {
      if (javadocSummary != null && javadocSummary.length() > 0) {
        if (fText != null) fText = context.getText() + "<br><br>" + javadocSummary; // $NON-NLS-1$
        else fText = javadocSummary;
      }
    }

    if (fText == null) fText = ""; // $NON-NLS-1$
  }
  /**
   * Note: This method is for internal use only. Clients should not call this method.
   *
   * @param cu The compilation unit to process
   */
  public void run(ICompilationUnit cu) {
    if (!ElementValidator.check(
        cu, getShell(), ActionMessages.OrganizeImportsAction_error_title, fEditor != null)) return;
    if (!ActionUtil.isProcessable(getShell(), cu)) return;

    IEditingSupport helper = createViewerHelper();
    try {
      CodeGenerationSettings settings =
          JavaPreferencesSettings.getCodeGenerationSettings(cu.getJavaProject());

      if (fEditor == null && EditorUtility.isOpenInEditor(cu) == null) {
        IEditorPart editor = EditorUtility.openInEditor(cu);
        if (editor instanceof JavaEditor) {
          fEditor = (JavaEditor) editor;
        }
      }

      CompilationUnit astRoot =
          JavaPlugin.getDefault().getASTProvider().getAST(cu, ASTProvider.WAIT_ACTIVE_ONLY, null);

      AJOrganizeImportsOperation op =
          new AJOrganizeImportsOperation(
              cu,
              astRoot,
              settings.importIgnoreLowercase,
              !cu.isWorkingCopy(),
              true,
              createChooseImportQuery());

      IRewriteTarget target = null;
      if (fEditor != null) {
        target = (IRewriteTarget) fEditor.getAdapter(IRewriteTarget.class);
        if (target != null) {
          target.beginCompoundChange();
        }
      }

      IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
      IRunnableContext context = getSite().getWorkbenchWindow();
      if (context == null) {
        context = progressService;
      }
      try {
        registerHelper(helper);
        progressService.runInUI(
            context, new WorkbenchRunnableAdapter(op, op.getScheduleRule()), op.getScheduleRule());
        IProblem parseError = op.getParseError();
        if (parseError != null) {
          String message =
              Messages.format(
                  ActionMessages.OrganizeImportsAction_single_error_parse, parseError.getMessage());
          MessageDialog.openInformation(
              getShell(), ActionMessages.OrganizeImportsAction_error_title, message);
          if (fEditor != null && parseError.getSourceStart() != -1) {
            fEditor.selectAndReveal(
                parseError.getSourceStart(),
                parseError.getSourceEnd() - parseError.getSourceStart() + 1);
          }
        } else {
          if (fEditor != null) {
            setStatusBarMessage(getOrganizeInfo(op));
          }
        }
      } catch (InvocationTargetException e) {
        ExceptionHandler.handle(
            e,
            getShell(),
            ActionMessages.OrganizeImportsAction_error_title,
            ActionMessages.OrganizeImportsAction_error_message);
      } catch (InterruptedException e) {
      } finally {
        deregisterHelper(helper);
        if (target != null) {
          target.endCompoundChange();
        }
      }
    } catch (CoreException e) {
      ExceptionHandler.handle(
          e,
          getShell(),
          ActionMessages.OrganizeImportsAction_error_title,
          ActionMessages.OrganizeImportsAction_error_message);
    }
  }