private @NotNull PsiIfStatement concatenateIfStatements(@NotNull PsiIfStatement originalIfStatement) {
      if (myAdditionalIfStatementsCount == 0) return originalIfStatement;
      StringBuilder sb = new StringBuilder();
      CommentTracker commentTracker = new CommentTracker();
      PsiIfStatement currentStatement = originalIfStatement;
      int currentAdditionalIfStatementsCount = 0;
      List<PsiElement> toDeleteElements = new ArrayList<>();
      boolean addText = true;
      while (true) {
        if (addText) {
          String text = commentTracker.text(currentStatement);
          sb.append(text);
        }
        PsiStatement elseBranch = currentStatement.getElseBranch();
        if (elseBranch instanceof PsiIfStatement nextIfStatement) {
          addText = false;
          currentStatement = nextIfStatement;
          continue;
        }
        if (elseBranch == null && currentAdditionalIfStatementsCount < myAdditionalIfStatementsCount) {
          PsiIfStatement upperIf =  currentStatement;
          while (upperIf.getParent() instanceof PsiIfStatement parentIfStatement &&
                 parentIfStatement.getElseBranch() == upperIf) {
            upperIf = parentIfStatement;
          }

          PsiElement nextElement = PsiTreeUtil.skipWhitespacesAndCommentsForward(upperIf);
          if (nextElement instanceof PsiIfStatement nextIfStatement) {
            PsiElement nextSibling = upperIf.getNextSibling();
            while (nextSibling != null && nextSibling != nextIfStatement) {
              sb.append(commentTracker.text(nextSibling));
              if (!(nextSibling instanceof PsiWhiteSpace)) {
                toDeleteElements.add(nextSibling);
              }
              nextSibling = nextSibling.getNextSibling();
            }
            addText = true;
            sb.append("\n else \n");
            currentStatement = nextIfStatement;
            currentAdditionalIfStatementsCount++;
            toDeleteElements.add(nextIfStatement);
            continue;
          }
        }
        break;
      }
      for (PsiElement toDelete : toDeleteElements) {
        toDelete.delete();
      }
      PsiElement replaced = commentTracker.replace(originalIfStatement, sb.toString());
      return replaced instanceof PsiIfStatement ? (PsiIfStatement)replaced : originalIfStatement;
    }
private @NotNull PsiIfStatement concatenateIfStatements(@NotNull PsiIfStatement originalIfStatement)