void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiLoopStatement loopStatement = PsiTreeUtil.getParentOfType(element, PsiLoopStatement.class); if (loopStatement == null) return; PsiExpressionStatement statement = tryCast(ControlFlowUtils.stripBraces(loopStatement.getBody()), PsiExpressionStatement.class); if (statement == null) return; PsiMethodCallExpression call = tryCast(statement.getExpression(), PsiMethodCallExpression.class); if (call == null) return; PsiExpression listExpression = call.getMethodExpression().getQualifierExpression(); if (listExpression == null) return; CommentTracker ct = new CommentTracker(); Pair<String, String> startEnd = getStartEnd(loopStatement, ct); if (startEnd == null) return; String start = startEnd.getFirst(); String end = startEnd.getSecond(); @NonNls final String statementText = ct.text(listExpression) + ".subList(" + start + "," + end + ").clear();"; final String replacementText = "if(" + end + ">" + start + "){" + statementText + "}"; PsiIfStatement ifStatement = (PsiIfStatement)ct.replaceAndRestoreComments(loopStatement, replacementText); ct = new CommentTracker(); PsiExpression condition = ifStatement.getCondition(); String simplified = JavaPsiMathUtil.simplifyComparison(condition, ct); if (simplified != null) { condition = (PsiExpression)ct.replaceAndRestoreComments(condition, simplified); ct = new CommentTracker(); } if (Boolean.TRUE.equals(DfaUtil.evaluateCondition(condition))) { PsiStatement nakedSubListClear = ControlFlowUtils.stripBraces(ifStatement.getThenBranch()); assert nakedSubListClear != null; ct.replaceAndRestoreComments(ifStatement, nakedSubListClear); } }