void (@NotNull PsiElement element) { final PsiWhileStatement whileStatement = (PsiWhileStatement)element.getParent(); if (whileStatement == null) { return; } final PsiExpression condition = whileStatement.getCondition(); if (condition == null) { return; } final String conditionText = BoolUtils.getNegatedExpressionText(condition); final Project project = whileStatement.getProject(); final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory(); condition.replace(factory.createExpressionFromText("true", whileStatement)); final PsiStatement body = whileStatement.getBody(); final PsiStatement ifStatement = factory.createStatementFromText("if (" + conditionText + ") break;", whileStatement); final PsiElement newElement; if (body instanceof PsiBlockStatement blockStatement) { final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); newElement = codeBlock.addBefore(ifStatement, codeBlock.getFirstBodyElement()); } else if (body != null) { final PsiStatement newStatement = BlockUtils.expandSingleStatementToBlockStatement(body); newElement = newStatement.getParent().addBefore(ifStatement, newStatement); } else { return; } CodeStyleManager.getInstance(project).reformat(newElement); }