private static @Nullable PsiType getStreamElementType(PsiExpression expression) {
      PsiMethodCallExpression call =
        ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(expression), PsiMethodCallExpression.class);
      while (STREAM_FILTER.test(call)) {
        PsiExpression predicate = PsiUtil.skipParenthesizedExprDown(call.getArgumentList().getExpressions()[0]);
        if (predicate instanceof PsiMethodReferenceExpression) {
          if (CLASS_INSTANCEOF.methodReferenceMatches((PsiMethodReferenceExpression)predicate)) {
            PsiExpression qualifier = PsiUtil.skipParenthesizedExprDown(((PsiMethodReferenceExpression)predicate).getQualifierExpression());
            if (qualifier instanceof PsiClassObjectAccessExpression) {
              return ((PsiClassObjectAccessExpression)qualifier).getOperand().getType();
            }
          }
        }
        else if (predicate instanceof PsiLambdaExpression) {
          PsiParameter[] parameters = ((PsiLambdaExpression)predicate).getParameterList().getParameters();
          if (parameters.length == 1) {
            PsiExpression lambdaBody =
              PsiUtil.skipParenthesizedExprDown(LambdaUtil.extractSingleExpressionFromBody(((PsiLambdaExpression)predicate).getBody()));
            if (lambdaBody instanceof PsiInstanceOfExpression &&
                ExpressionUtils.isReferenceTo(((PsiInstanceOfExpression)lambdaBody).getOperand(), parameters[0])) {
              PsiTypeElement checkType = ((PsiInstanceOfExpression)lambdaBody).getCheckType();
              if (checkType != null) {
                return checkType.getType();
              }
            }
          }
        }
        call = MethodCallUtils.getQualifierMethodCall(call);
      }
      return StreamApiUtil.getStreamElementType(expression.getType(), false);
    }
private static @Nullable PsiType getStreamElementType(PsiExpression expression)