@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
      final PsiWhileStatement statement = (PsiWhileStatement)element.getParent();
      if (statement == null) return;

      final PsiStatement body = statement.getBody();
      if (body == null) return;
      final PsiExpression condition = statement.getCondition();
      final boolean infiniteLoop = BoolUtils.isTrue(condition);

      final Block bodyBlock = Block.init(body);
      final DiffRange duplicateElements = bodyBlock.getDiffRange(Block.find(statement, bodyBlock.statements.size()));
      final StringBuilder result = new StringBuilder();
      final CommentTracker tracker = new CommentTracker();
      if (!infiniteLoop && duplicateElements == null) {
        result.append("if(");
        if (condition != null) {
          result.append(tracker.text(condition));
        }
        result.append(") {\n");
      }
      if (body instanceof PsiBlockStatement blockStatement) {
        result.append("do {");
        final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
        final PsiElement[] children = codeBlock.getChildren();
        if (children.length > 2) {
          for (int i = 1; i < children.length - 1; i++) {
            final PsiElement child = children[i];
            result.append(tracker.text(child));
          }
        }
        result.append('}');
      }
      else {
        result.append("do ").append(tracker.text(body)).append('\n');
      }
      result.append("while(");
      if (condition != null) {
        result.append(tracker.text(condition));
      }
      result.append(");");
      if (!infiniteLoop && duplicateElements == null) {
        result.append("\n}");
      }

      if (duplicateElements != null) {
        statement.getParent().deleteChildRange(duplicateElements.first(), duplicateElements.last());
      }
      PsiReplacementUtil.replaceStatement(statement, result.toString(), tracker);
    }
@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater)