@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);
    }
  }
 /** Test for {@link DartFunction#isGlobal()} and {@link DartFunction#isLocal()}. */
 public void test_isGlobal_isLocal() throws Exception {
   TestProject testProject = new TestProject("Test");
   try {
     CompilationUnit unit =
         testProject.setUnitContent(
             "Test.dart",
             Joiner.on("\n")
                 .join(
                     "// filler filler filler filler filler filler filler filler filler filler",
                     "f() {",
                     "  v() {};",
                     "}",
                     ""));
     // global function
     DartFunction globalFunction = (DartFunction) unit.getChildren()[0];
     assertTrue(globalFunction.isGlobal());
     assertFalse(globalFunction.isLocal());
     // local functions
     DartElement[] functions = globalFunction.getChildren();
     assertThat(functions).hasSize(1);
     // v
     {
       DartFunction f = (DartFunction) functions[0];
       assertFalse(f.isGlobal());
       assertTrue(f.isLocal());
     }
   } finally {
     testProject.dispose();
   }
 }
 /** Test for {@link DartFunction#getVisibleRange()} for local functions. */
 public void test_getVisibleRange() throws Exception {
   TestProject testProject = new TestProject("Test");
   try {
     CompilationUnit unit =
         testProject.setUnitContent(
             "Test.dart",
             Joiner.on("\n")
                 .join(
                     "// filler filler filler filler filler filler filler filler filler filler",
                     "f() {",
                     "  v1() {};",
                     "  {",
                     "    v2() {};",
                     "  }//marker1",
                     "  v3() {};",
                     "}//marker2",
                     ""));
     String source = unit.getSource();
     DartFunction globalFunction = (DartFunction) unit.getChildren()[0];
     DartElement[] functions = globalFunction.getChildren();
     assertThat(functions).hasSize(3);
     // v1
     {
       DartFunction f = (DartFunction) functions[0];
       SourceRange range = f.getVisibleRange();
       assertEquals("v1", f.getElementName());
       assertEquals(source.indexOf("v1"), range.getOffset());
       assertEquals(source.indexOf("marker2") - 1, range.getOffset() + range.getLength());
     }
     // v2
     {
       DartFunction f = (DartFunction) functions[1];
       SourceRange range = f.getVisibleRange();
       assertEquals("v2", f.getElementName());
       assertEquals(source.indexOf("v2"), range.getOffset());
       assertEquals(source.indexOf("marker1") - 1, range.getOffset() + range.getLength());
     }
     // v3
     {
       DartFunction f = (DartFunction) functions[2];
       SourceRange range = f.getVisibleRange();
       assertEquals("v3", f.getElementName());
       assertEquals(source.indexOf("v3"), range.getOffset());
       assertEquals(source.indexOf("marker2") - 1, range.getOffset() + range.getLength());
     }
   } finally {
     testProject.dispose();
   }
 }