@Override
  protected @Nullable String validateAndCommitData() {
    final String functionName = myNameField.getText().trim();
    if (!functionName.equals(myMethod.getName())) {
      final boolean defined = IntroduceValidator.isDefinedInScope(functionName, myMethod.getMethod());
      if (defined) {
        return PyBundle.message("refactoring.change.signature.dialog.validation.name.defined");
      }
      if (!isNameValid(functionName, myProject)) {
        return PyBundle.message("refactoring.change.signature.dialog.validation.function.name");
      }
    }
    final List<PyParameterTableModelItem> parameters = myParametersTableModel.getItems();
    final Set<String> parameterNames = new HashSet<>();
    boolean hadPositionalContainer = false;
    boolean hadKeywordContainer = false;
    boolean hadDefaultValue = false;
    boolean hadSlash = false;
    boolean hadSingleStar = false;
    boolean hadParamsAfterSingleStar = false;
    final LanguageLevel languageLevel = LanguageLevel.forElement(myMethod.getMethod());

    final int parametersLength = parameters.size();

    for (int index = 0; index < parametersLength; index++) {
      final PyParameterTableModelItem info = parameters.get(index);
      final PyParameterInfo parameter = info.parameter;
      final String name = parameter.getName();
      final boolean isMarkerParameter = name.equals(PySlashParameter.TEXT) || name.equals(PySingleStarParameter.TEXT);
      if (!isMarkerParameter) {
        final String nameWithoutStars = StringUtil.trimLeading(name, '*').trim();
        if (parameterNames.contains(nameWithoutStars)) {
          return PyPsiBundle.message("ANN.duplicate.param.name");
        }
        parameterNames.add(nameWithoutStars);
      }

      if (name.equals(PySingleStarParameter.TEXT)) {
        if (hadSingleStar) {
          return PyBundle.message("refactoring.change.signature.dialog.validation.multiple.star");
        }
        hadSingleStar = true;
        if (index == parametersLength - 1) {
          return PyPsiBundle.message("ANN.named.parameters.after.star");
        }
      }
      else if (name.equals(PySlashParameter.TEXT)) {
        if (hadSlash) {
          return PyPsiBundle.message("ANN.multiple.slash");
        }
        hadSlash = true;
        if (hadPositionalContainer || hadSingleStar) {
          return PyPsiBundle.message("ANN.slash.param.after.vararg");
        }
        else if (hadKeywordContainer) {
          return PyPsiBundle.message("ANN.slash.param.after.keyword");
        }
        if (index == 0) {
          return PyPsiBundle.message("ANN.named.parameters.before.slash");
        }
      }
      else if (name.startsWith(PySingleStarParameter.TEXT) && !name.startsWith("**")) {
        if (hadKeywordContainer) {
          return PyPsiBundle.message("ANN.starred.param.after.kwparam");
        }
        if (hadSingleStar || hadPositionalContainer) {
          return PyBundle.message("refactoring.change.signature.dialog.validation.multiple.star");
        }
        if (!isNameValid(name.substring(1), myProject)) {
          return PyBundle.message("refactoring.change.signature.dialog.validation.parameter.name");
        }
        hadPositionalContainer = true;
      }
      else if (name.startsWith("**")) {
        if (hadSingleStar && !hadParamsAfterSingleStar) {
          return PyPsiBundle.message("ANN.named.parameters.after.star");
        }
        if (hadKeywordContainer) {
          return PyBundle.message("refactoring.change.signature.dialog.validation.multiple.double.star");
        }
        if (!isNameValid(name.substring(2), myProject)) {
          return PyBundle.message("refactoring.change.signature.dialog.validation.parameter.name");
        }
        hadKeywordContainer = true;
      }
      else {
        if (!isNameValid(name, myProject)) {
          return PyBundle.message("refactoring.change.signature.dialog.validation.parameter.name");
        }
        if (hadSingleStar) {
          hadParamsAfterSingleStar = true;
        }
        if (hadPositionalContainer && languageLevel.isPython2()) {
          return PyPsiBundle.message("ANN.regular.param.after.vararg");
        }
        else if (hadKeywordContainer) {
          return PyPsiBundle.message("ANN.regular.param.after.keyword");
        }
        final String defaultValue = info.getDefaultValue();
        if (defaultValue != null && !StringUtil.isEmptyOrSpaces(defaultValue) && parameter.getDefaultInSignature()) {
          hadDefaultValue = true;
        }
        else {
          if (hadDefaultValue && !hadSingleStar && (languageLevel.isPython2() || !hadPositionalContainer)) {
            return PyPsiBundle.message("ANN.non.default.param.after.default");
          }
        }
      }
      if (parameter.getOldIndex() < 0) {
        if (ParamHelper.couldHaveDefaultValue(name)) {
          if (StringUtil.isEmpty(info.defaultValueCodeFragment.getText())) {
            return PyBundle.message("refactoring.change.signature.dialog.validation.default.missing");
          }
          if (StringUtil.isEmptyOrSpaces(name)) {
            return PyBundle.message("refactoring.change.signature.dialog.validation.parameter.missing");
          }
        }
      }
      else if (myMethod.getParameters().get(parameter.getOldIndex()).getDefaultInSignature() &&
               StringUtil.isEmptyOrSpaces(parameter.getDefaultValue())) {
        return PyBundle.message("refactoring.change.signature.dialog.validation.default.missing");
      }
    }

    return null;
  }
@Override
  protected @Nullable String validateAndCommitData()