Annotate often-used Collectors method
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 30 Oct 2015 11:31:18 +0000 (07:31 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 20 Nov 2015 21:13:24 +0000 (16:13 -0500)
We commonly end a Stream with

  .collect(Collectors.toList());

However the returned List is not null-annotated, which means it gives a
warning if we want to save it to a @NonNull List<> reference.

It could be tempting to annotate Stream.collect() directly, however that
would be wrong: there is no guarantee that some shoddy Collector does
not return a null value.

Instead, annotate Collectors.toList(), toSet() and toCollection(), which
should cover for most common use cases.

Change-Id: I8adaf55579bf5b1cc66c5fbb122acc416a4870dc
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/59327
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
common/org.eclipse.tracecompass.common.core/annotations/java/util/stream/Collectors.eea [new file with mode: 0644]

diff --git a/common/org.eclipse.tracecompass.common.core/annotations/java/util/stream/Collectors.eea b/common/org.eclipse.tracecompass.common.core/annotations/java/util/stream/Collectors.eea
new file mode 100644 (file)
index 0000000..b432304
--- /dev/null
@@ -0,0 +1,10 @@
+class java/util/stream/Collectors
+toCollection
+ <T:Ljava/lang/Object;C::Ljava/util/Collection<TT;>;>(Ljava/util/function/Supplier<TC;>;)Ljava/util/stream/Collector<TT;*TC;>;
+ <T:Ljava/lang/Object;C::Ljava/util/Collection<TT;>;>(Ljava/util/function/Supplier<TC;>;)Ljava/util/stream/Collector<TT;*T1C;>;
+toList
+ <T:Ljava/lang/Object;>()Ljava/util/stream/Collector<TT;*Ljava/util/List<TT;>;>;
+ <T:Ljava/lang/Object;>()Ljava/util/stream/Collector<TT;*L1java/util/List<TT;>;>;
+toSet
+ <T:Ljava/lang/Object;>()Ljava/util/stream/Collector<TT;*Ljava/util/Set<TT;>;>;
+ <T:Ljava/lang/Object;>()Ljava/util/stream/Collector<TT;*L1java/util/Set<TT;>;>;
This page took 0.026555 seconds and 5 git commands to generate.