@Override
  protected void invoke(@NotNull ActionContext context, @NotNull PyIfStatement expression, @NotNull ModPsiUpdater updater) {
    PyIfStatement outerIfStatement = getIfStatement(expression);
    if (outerIfStatement == null) return;

    PyIfStatement innerIfStatement = as(getFirstStatement(outerIfStatement), PyIfStatement.class);
    if (innerIfStatement == null) return;

    PyExpression innerCondition = innerIfStatement.getIfPart().getCondition();
    PyExpression outerCondition = outerIfStatement.getIfPart().getCondition();
    if (outerCondition == null || innerCondition == null) return;

    PyElementGenerator elementGenerator = PyElementGenerator.getInstance(context.project());
    LanguageLevel pyVersion = LanguageLevel.forElement(context.file());
    PyBinaryExpression fakeAndExpression = (PyBinaryExpression)elementGenerator.createExpressionFromText(pyVersion, "foo and bar");
    StringBuilder replacementText = new StringBuilder();
    if (PyReplaceExpressionUtil.isNeedParenthesis(fakeAndExpression.getLeftExpression(), outerCondition)) {
      replacementText.append("(").append(outerCondition.getText()).append(")");
    }
    else {
      replacementText.append(outerCondition.getText());
    }
    replacementText.append(" and ");
    if (PyReplaceExpressionUtil.isNeedParenthesis(fakeAndExpression.getLeftExpression(), innerCondition)) {
      replacementText.append("(").append(innerCondition.getText()).append(")");
    }
    else {
      replacementText.append(innerCondition.getText());
    }

    PyExpression newCondition = elementGenerator.createExpressionFromText(pyVersion, replacementText.toString());
    outerCondition.replace(newCondition);

    PyStatementList innerStatementList = innerIfStatement.getIfPart().getStatementList();
    PyStatementList outerStatementList = outerIfStatement.getIfPart().getStatementList();
    List<PsiComment> comments = PsiTreeUtil.getChildrenOfTypeAsList(outerIfStatement.getIfPart(), PsiComment.class);
    comments = ContainerUtil.concat(comments, PsiTreeUtil.getChildrenOfTypeAsList(innerIfStatement.getIfPart(), PsiComment.class));
    comments = ContainerUtil.concat(comments, PsiTreeUtil.getChildrenOfTypeAsList(outerStatementList, PsiComment.class));
    comments = ContainerUtil.concat(comments, PsiTreeUtil.getChildrenOfTypeAsList(innerStatementList, PsiComment.class));

    for (PsiElement comm : comments) {
      outerIfStatement.getIfPart().addBefore(comm, outerStatementList);
      comm.delete();
    }
    outerStatementList.replace(innerStatementList);
  }
@Override
  protected void invoke(@NotNull ActionContext context, @NotNull PyIfStatement expression, @NotNull ModPsiUpdater updater)