void (@NotNull PsiMethodCallExpression call) { if (!LIST_REMOVE.test(call)) return; PsiReferenceExpression arg = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(call.getArgumentList().getExpressions()[0]), PsiReferenceExpression.class); if (arg == null) return; PsiExpressionStatement parentStatement = ObjectUtils.tryCast(call.getParent(), PsiExpressionStatement.class); if (parentStatement == null) return; PsiElement parent = parentStatement.getParent(); while (parent instanceof PsiLabeledStatement || parent instanceof PsiIfStatement || parent instanceof PsiSwitchLabelStatementBase || parent instanceof PsiSwitchStatement || parent instanceof PsiBlockStatement || parent instanceof PsiCodeBlock) { parent = parent.getParent(); } if (!(parent instanceof PsiForStatement)) return; CountingLoop loop = CountingLoop.from((PsiForStatement)parent); if (loop == null || loop.isDescending()) return; if (!arg.isReferenceTo(loop.getCounter())) return; if (ControlFlowUtils.isExecutedOnceInLoop(parentStatement, (PsiLoopStatement)parent)) return; holder.registerProblem(Objects.requireNonNull(call.getMethodExpression().getReferenceNameElement()), JavaBundle.message("inspection.suspicious.list.remove.display.name")); }