void (@NotNull PsiMethodCallExpression call) { if (!LIST_REMOVE.test(call)) return; PsiExpression listExpression = call.getMethodExpression().getQualifierExpression(); if (listExpression == null) return; PsiElement parent = call.getParent(); if (!(parent instanceof PsiExpressionStatement)) return; PsiLoopStatement loop = PsiTreeUtil.getParentOfType(parent, PsiLoopStatement.class, true, PsiMember.class); if (loop == null) return; if (ControlFlowUtils.stripBraces(loop.getBody()) != parent) return; PsiExpression arg = call.getArgumentList().getExpressions()[0]; ProblemHighlightType type; if (isRemoveInCountingLoop(loop, arg)) { type = ProblemHighlightType.GENERIC_ERROR_OR_WARNING; } else if (isRemoveInWhileLoop(loop, listExpression, arg)) { // while-loop scenario is not so bad (always the last element is removed which is usually fast), // the replacement is often longer and harder to read // and such loop is often used to remove at most one element which is faster than using subList().clear() if (!isOnTheFly) return; type = ProblemHighlightType.INFORMATION; } else { return; } holder.registerProblem(loop.getFirstChild(), InspectionGadgetsBundle.message("inspection.list.remove.in.loop.message"), type, new ListRemoveInLoopFix()); }