boolean (PsiElement candidate, String method) { while (candidate instanceof PsiParenthesizedExpression) { candidate = ((PsiParenthesizedExpression)candidate).getExpression(); } if (!(candidate instanceof PsiMethodCallExpression call)) return false; if (!call.getArgumentList().isEmpty()) return false; PsiReferenceExpression expression = call.getMethodExpression(); return method.equals(expression.getReferenceName()) && ExpressionUtils.isReferenceTo(expression.getQualifierExpression(), myIterator); }