private static IEditorPart openInEditor(IEditorInput input, String editorID, boolean activate)
      throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInEditor-IEditorInput");
    try {

      Assert.isNotNull(input);
      Assert.isNotNull(editorID);

      instrumentation.data("Name", input.getName());
      instrumentation.data("EditorID", editorID);
      instrumentation.metric("activate", activate);

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorPart editorPart = p.openEditor(input, editorID, activate);
      initializeHighlightRange(editorPart);
      return editorPart;
    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }
  @Override
  public void doRun(ISelection selection, Event event, UIInstrumentationBuilder instrumentation) {
    instrumentation.metric("command", command);

    if (!(selection instanceof ITextSelection)) {
      instrumentation.metric("Problem", "Selection was not a TextSelection");
    }

    IWorkbenchPage page = DartToolsPlugin.getActivePage();
    if (page == null) {
      instrumentation.metric("Problem", "Page was null");
      return;
    }

    IEditorPart part = page.getActiveEditor();
    if (part == null) {
      instrumentation.metric("Problem", "Part was null");
      return;
    }

    IEditorInput editorInput = part.getEditorInput();
    IProject project = EditorUtility.getProject(editorInput);
    instrumentation.data("Project", project.getName());
    savePubspecFile(project);
    runPubJob(project);
  }
  @Override
  public void doRun(
      IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) {

    instrumentation.metric("command", command);

    if (!selection.isEmpty() && selection.getFirstElement() instanceof IResource) {
      Object object = selection.getFirstElement();
      if (object instanceof IFile) {
        object = ((IFile) object).getParent();
      }
      while (object != null
          && ((IContainer) object).findMember(DartCore.PUBSPEC_FILE_NAME) == null) {
        object = ((IContainer) object).getParent();
      }
      if (object instanceof IContainer) {
        IContainer container = (IContainer) object;
        instrumentation.data("name", container.getName());
        savePubspecFile(container);
        runPubJob(container);
        return;
      } else {
        instrumentation.metric("Problem", "Object was null").log();
      }
    }

    instrumentation.metric("Problem", "pubspec.yaml file not selected, showing dialog");

    MessageDialog.openError(
        getShell(), ActionMessages.RunPubAction_fail, ActionMessages.RunPubAction_fileNotFound);

    instrumentation.log();
  }
  @Override
  public void doRun(
      ITextSelection selection, Event event, UIInstrumentationBuilder instrumentation) {

    if (!ActionUtil.isEditable(fEditor)) {
      instrumentation.metric("Problem", "Editor not editable");
      return;
    }

    CompilationUnit cu = SelectionConverter.getInputAsCompilationUnit(fEditor);
    instrumentation.record(cu);
    try {
      DartFunction function = DartModelUtil.findFunction(cu, selection.getOffset());
      instrumentation.data("function", function.getSource());

      boolean success =
          RefactoringExecutionStarter_OLD.startConvertGetterToMethodRefactoring(
              function, getShell());

      if (success) {
        return;
      }
      instrumentation.metric(
          "Problem", "RefactoringExecutionStarter.startConvertGetterToMethodRefactoring False");

    } catch (Throwable e) {
      instrumentation.record(e);
    }

    instrumentation.metric("Problem", "No valid selection, showing dialog");
    MessageDialog.openInformation(
        getShell(),
        RefactoringMessages.ConvertGetterToMethodAction_dialog_title,
        RefactoringMessages.ConvertGetterToMethodAction_select);
  }
  @Override
  public void doRun(
      IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) {

    try {
      Object element = selection.getFirstElement();
      if (element instanceof DartFunction) {
        DartFunction function = (DartFunction) element;
        instrumentation.data("function", function.getSource());

        if (!RefactoringAvailabilityTester.isConvertGetterToMethodAvailable(function)) {
          instrumentation.metric("Problem", "RefactoringAvailabilityTester Returned false");
        }

        boolean success =
            RefactoringExecutionStarter_OLD.startConvertGetterToMethodRefactoring(
                function, getShell());
        if (success) {
          return;
        }

        instrumentation.metric(
            "Problem",
            "RefactoringExecutionStarter.startConvertGetterToMethodRefactoring returned False");
      }
    } catch (DartModelException e) {
      ExceptionHandler.handle(
          e,
          getShell(),
          RefactoringMessages.ConvertGetterToMethodAction_dialog_title,
          RefactoringMessages.InlineMethodAction_unexpected_exception);
    }
  }
  /**
   * Executes the associated action for this element.
   *
   * @param text the current string in the search box
   */
  public void execute(String text) {
    UIInstrumentationBuilder instrumentation = UIInstrumentation.builder(this.getClass());

    instrumentation.data("text", text);
    try {
      doExecute(text, instrumentation);
    } finally {
      instrumentation.log();
    }
  }
  private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInEditor-IFile");
    try {

      if (file == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null);
      }

      instrumentation.data("FileName", file.getName());
      instrumentation.data("FilePath", file.getFullPath().toOSString());
      instrumentation.metric("activate", activate);

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorDescriptor desc = IDE.getEditorDescriptor(file, true);

      String editorId = desc.getId();
      boolean isTooComplex = false;
      editorId = maybeSwapDefaultEditorDescriptor(editorId);
      if (DartUI.isTooComplexDartFile(file)) {
        isTooComplex = true;
        editorId = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
      }

      IEditorPart editor = IDE.openEditor(p, file, editorId, activate);
      if (isTooComplex) {
        DartUI.showTooComplexDartFileWarning(editor);
      }
      initializeHighlightRange(editor);
      return editor;
    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }
  /**
   * Opens the given file in the registered editor for the file type, or in the default text editor
   * if no editor is registered. This differs from the openInEditor() method in that the system
   * editor will never be opened.
   *
   * @param file the file to open
   * @return an open editor
   * @throws PartInitException if the editor could not be opened or the input element is not valid
   */
  public static IEditorPart openInTextEditor(IFile file, boolean activate)
      throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInTextEditor");
    try {

      if (file == null) {
        instrumentation.metric("Problem", "file is null");
        throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null);
      }

      instrumentation.data("FileName", file.getName());
      instrumentation.data("FilePath", file.getFullPath().toOSString());

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        instrumentation.metric("Problem", "no active workbench page");
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorDescriptor desc = IDE.getEditorDescriptor(file, true);

      if (desc.getId() == IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID) {
        IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();

        desc = editorReg.findEditor(EditorsUI.DEFAULT_TEXT_EDITOR_ID);
      }

      IEditorPart editorPart =
          IDE.openEditor(p, file, maybeSwapDefaultEditorDescriptor(desc.getId()), activate);
      initializeHighlightRange(editorPart);
      return editorPart;

    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }
  @SuppressWarnings("unused")
  private static IEditorPart openInEditor(URI file, boolean activate) throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInEditor-URI");
    try {

      if (file == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null);
      }

      instrumentation.data("File", file.getPath());
      instrumentation.metric("activate", activate);

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorDescriptor desc =
          PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getPath());
      if (desc == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_cantFindEditor + file.toString());
      }

      IEditorPart editorPart =
          IDE.openEditor(p, file, maybeSwapDefaultEditorDescriptor(desc.getId()), activate);
      initializeHighlightRange(editorPart);
      return editorPart;
    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }