@NotNull
  private static Pair<String, AbstractVariableData[]> getNameAndVariableData(@NotNull final Project project,
                                                                             @NotNull final CodeFragment fragment,
                                                                             @NotNull final PsiElement element,
                                                                             final boolean isClassMethod,
                                                                             final boolean isStaticMethod) {
    final ExtractMethodValidator validator = new PyExtractMethodValidator(element, project);
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      String name = System.getProperty(NAME);
      if (name == null) {
        name = "foo";
      }
      final String error = validator.check(name);
      if (error != null) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
          throw new CommonRefactoringUtil.RefactoringErrorHintException(error);
        }
        if (!MessageDialogBuilder.okCancel(RefactoringBundle.message("warning.title"), error + ". " + RefactoringBundle.message("do.you.wish.to.continue")).
          icon(UIUtil.getWarningIcon()).ask(project)) {
          throw new CommonRefactoringUtil.RefactoringErrorHintException(error);
        }
      }
      final List<AbstractVariableData> data = new ArrayList<>();
      for (String in : fragment.getInputVariables()) {
        final AbstractVariableData d = new AbstractVariableData();
        d.name = in + "_new";
        d.originalName = in;
        d.passAsParameter = true;
        data.add(d);
      }
      return Pair.create(name, data.toArray(new AbstractVariableData[0]));
    }

    final boolean isMethod = PyPsiUtils.isMethodContext(element);
    final ExtractMethodDecorator<Object> decorator = new ExtractMethodDecorator<>() {
      @Override
      @NotNull
      public String createMethodSignature(@NotNull ExtractMethodSettings<Object> settings) {
        final StringBuilder builder = new StringBuilder();
        if (isClassMethod) {
          builder.append("cls");
        }
        else if (isMethod && !isStaticMethod) {
          builder.append("self");
        }
        for (AbstractVariableData variableData : settings.getAbstractVariableData()) {
          if (variableData.passAsParameter) {
            if (builder.length() != 0) {
              builder.append(", ");
            }
            builder.append(variableData.name);
          }
        }
        builder.insert(0, "(");
        builder.insert(0, settings.getMethodName());
        builder.insert(0, "def ");
        builder.append(")");
        return builder.toString();
      }
    };

    ExtractMethodSettings<?> extractMethodSettings = PyRefactoringUiService.getInstance().showExtractMethodDialog(project, "method_name", fragment,
                                                                                                                  ArrayUtilRt.EMPTY_OBJECT_ARRAY, validator,
                                                                                                                  decorator, PythonFileType.INSTANCE,
                                                                                                                  "python.reference.extractMethod");
    //return if don`t want to extract method
    if (extractMethodSettings == null) {
      return Pair.empty();
    }

    return Pair.create(extractMethodSettings.getMethodName(), extractMethodSettings.getAbstractVariableData());
  }
@NotNull
  private static Pair<String, AbstractVariableData[]> getNameAndVariableData(@NotNull final Project project,
                                                                             @NotNull final CodeFragment fragment,
                                                                             @NotNull final PsiElement element,
                                                                             final boolean isClassMethod,
                                                                             final boolean isStaticMethod)