ExistingStreamSource (PsiMethodCallExpression call, PsiLambdaExpression lambda) { PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 1) return null; PsiParameter parameter = parameters[0]; boolean isCollectionForEach = ITERABLE_FOREACH.test(call); PsiExpression qualifier = call.getMethodExpression().getQualifierExpression(); if (qualifier == null) return null; PsiStatement parent = tryCast(call.getParent(), PsiExpressionStatement.class); if (parent == null) return null; return new ExistingStreamSource(parent, parameter, qualifier, isCollectionForEach); }