public static void replaceStatement(GrStatement oldStatement, GrStatement newStatement) throws IncorrectOperationException {
    if (newStatement instanceof GrBlockStatement blockStatement) {
      final GrOpenBlock openBlock = blockStatement.getBlock();
      final GrStatement[] statements = openBlock.getStatements();
      if (statements.length == 0) {
        oldStatement.removeStatement();
      }
      else {
        final PsiElement parent = oldStatement.getParent();
        if (parent instanceof GrStatementOwner statementOwner) {
          for (GrStatement statement : statements) {
            statementOwner.addStatementBefore(statement, oldStatement);
          }
          oldStatement.removeStatement();
        }
        else if (parent instanceof GrControlStatement) {
          oldStatement.replace(newStatement);
        }
      }
    }
    else {
      oldStatement.replaceWithStatement(newStatement);
    }
  }
public static void replaceStatement(GrStatement oldStatement, GrStatement newStatement)