public static StreamNullabilityPropagator getJavaStreamNullabilityPropagator()

in nullaway/src/main/java/com/uber/nullaway/handlers/StreamNullabilityPropagatorFactory.java [34:104]


  public static StreamNullabilityPropagator getJavaStreamNullabilityPropagator() {
    ImmutableList<StreamTypeRecord> streamModels =
        StreamModelBuilder.start()
            .addStreamType(new DescendantOf(Suppliers.typeFromString("java.util.stream.Stream")))
            // Names of all the methods of java.util.stream.Stream that behave like .filter(...)
            // (must take exactly 1 argument)
            .withFilterMethodFromSignature("filter(java.util.function.Predicate<? super T>)")
            // Names and relevant arguments of all the methods of java.util.stream.Stream that
            // behave
            // like .map(...) for the purposes of this checker (the listed arguments are those that
            // take the potentially filtered objects from the stream)
            .withMapMethodFromSignature(
                "<R>map(java.util.function.Function<? super T,? extends R>)",
                "apply",
                ImmutableSet.of(0))
            .withMapMethodFromSignature(
                "mapToInt(java.util.function.ToIntFunction<? super T>)",
                "applyAsInt",
                ImmutableSet.of(0))
            .withMapMethodFromSignature(
                "mapToLong(java.util.function.ToLongFunction<? super T>)",
                "applyAsLong",
                ImmutableSet.of(0))
            .withMapMethodFromSignature(
                "mapToDouble(java.util.function.ToDoubleFunction<? super T>)",
                "applyAsDouble",
                ImmutableSet.of(0))
            .withMapMethodFromSignature(
                "forEach(java.util.function.Consumer<? super T>)", "accept", ImmutableSet.of(0))
            .withMapMethodFromSignature(
                "forEachOrdered(java.util.function.Consumer<? super T>)",
                "accept",
                ImmutableSet.of(0))
            .withMapMethodAllFromName("flatMap", "apply", ImmutableSet.of(0))
            // Names and relevant arguments of all the methods of java.util.stream.Stream that
            // behave like .collect(...) for the purposes of this checker
            .withCollectMethodFromSignature(
                "<R,A>collect(java.util.stream.Collector<? super T,A,R>)",
                "java.util.stream.Collectors",
                "<T,K,U>toMap(java.util.function.Function<? super T,? extends K>,java.util.function.Function<? super T,? extends U>)",
                ImmutableSet.of(0, 1),
                "apply",
                ImmutableSet.of(0))
            .withCollectMethodFromSignature(
                "<R,A>collect(java.util.stream.Collector<? super T,A,R>)",
                "java.util.stream.Collectors",
                "<T,K>groupingBy(java.util.function.Function<? super T,? extends K>)",
                ImmutableSet.of(0),
                "apply",
                ImmutableSet.of(0))
            .withCollectMethodFromSignature(
                "<R,A>collect(java.util.stream.Collector<? super T,A,R>)",
                "com.google.common.collect.ImmutableMap",
                "<T,K,V>toImmutableMap(java.util.function.Function<? super T,? extends K>,java.util.function.Function<? super T,? extends V>)",
                ImmutableSet.of(0, 1),
                "apply",
                ImmutableSet.of(0))
            // List of methods of java.util.stream.Stream through which we just propagate the
            // nullability information of the last call, e.g. m() in
            // Observable.filter(...).m().map(...) means the
            // nullability information from filter(...) should still be propagated to map(...),
            // ignoring the interleaving call to m().
            .withPassthroughMethodFromSignature("distinct()")
            // List of methods of java.util.stream.Stream that both use the nullability information
            // internally (like map does), but also don't change the values flowing through the
            // stream
            // and thus propagate
            // the nullability information of the last call.
            .end();
    return new StreamNullabilityPropagator(streamModels);
  }