boolean (PsiElement element, PsiVariable iterator, @NotNull PsiType contentType) { if (element == null) { return false; } if (element instanceof PsiParenthesizedExpression) { return isIteratorNext(((PsiParenthesizedExpression)element).getExpression(), iterator, contentType); } if (element instanceof PsiTypeCastExpression castExpression) { final PsiType type = castExpression.getType(); if (!contentType.equals(type)) { return false; } final PsiExpression operand = castExpression.getOperand(); return isIteratorNext(operand, iterator, contentType); } if (!(element instanceof PsiMethodCallExpression callExpression)) { return false; } if (!callExpression.getArgumentList().isEmpty()) { return false; } final PsiReferenceExpression reference = callExpression.getMethodExpression(); @NonNls final String referenceName = reference.getReferenceName(); if (!HardcodedMethodConstants.NEXT.equals(referenceName)) { return false; } final PsiExpression expression = reference.getQualifierExpression(); return ExpressionUtils.isReferenceTo(expression, iterator); }