void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { final PsiConditionalLoopStatement parent = ObjectUtils.tryCast(element.getParent(), PsiConditionalLoopStatement.class); if (parent == null) return; final PsiExpression loopCondition = parent.getCondition(); if (loopCondition == null) return; final PsiStatement body = parent.getBody(); final boolean firstStatement = !(parent instanceof PsiDoWhileStatement); final PsiStatement statement; if (body instanceof PsiBlockStatement blockStatement) { final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); final PsiStatement[] statements = codeBlock.getStatements(); if (statements.length == 0) { return; } if (firstStatement) { statement = statements[0]; } else { statement = statements[statements.length - 1]; } } else { statement = body; } if (!(statement instanceof PsiIfStatement ifStatement)) { return; } final PsiExpression ifCondition = ifStatement.getCondition(); if (ifCondition == null) { return; } final PsiStatement thenBranch = ifStatement.getThenBranch(); final PsiStatement elseBranch = ifStatement.getElseBranch(); if (containsUnlabeledBreakStatement(thenBranch)) { CommentTracker commentTracker = new CommentTracker(); final String negatedExpressionText = BoolUtils.getNegatedExpressionText(ifCondition, commentTracker); PsiReplacementUtil.replaceExpression(loopCondition, negatedExpressionText, commentTracker); replaceStatement(ifStatement, elseBranch); } else if (containsUnlabeledBreakStatement(elseBranch)) { loopCondition.replace(ifCondition); if (thenBranch == null) { ifStatement.delete(); } else { replaceStatement(ifStatement, thenBranch); } } }