boolean (PsiLoopStatement loop, PsiExpression listExpression, PsiExpression arg) { if (!(loop instanceof PsiWhileStatement)) return false; PsiBinaryExpression condition = tryCast(PsiUtil.skipParenthesizedExprDown(((PsiWhileStatement)loop).getCondition()), PsiBinaryExpression.class); if (condition == null) return false; RelationType relationType = DfaPsiUtil.getRelationByToken(condition.getOperationTokenType()); if (relationType == null) return false; PsiExpression sizeExpression; switch (relationType) { case GE, GT -> sizeExpression = condition.getLOperand(); case LE, LT -> sizeExpression = condition.getROperand(); default -> { return false; } } PsiMethodCallExpression sizeCall = tryCast(PsiUtil.skipParenthesizedExprDown(sizeExpression), PsiMethodCallExpression.class); if (!LIST_SIZE.test(sizeCall)) return false; PsiExpression sizeQualifier = sizeCall.getMethodExpression().getQualifierExpression(); if (sizeQualifier == null || !PsiEquivalenceUtil.areElementsEquivalent(sizeQualifier, listExpression)) return false; PsiBinaryExpression diff = tryCast(PsiUtil.skipParenthesizedExprDown(arg), PsiBinaryExpression.class); if (diff == null || !diff.getOperationTokenType().equals(JavaTokenType.MINUS)) return false; if (!ExpressionUtils.isLiteral(diff.getROperand(), 1)) return false; return PsiEquivalenceUtil.areElementsEquivalent(sizeCall, diff.getLOperand()); }