public class CollectionToArrayHeuristics extends Object
Collection.toArray() and determines
the appropriate nullness type of the returned value.
The semantics of Collection.toArray() and
Collection.toArray(T[]) cannot be captured by the
regular type system. Namely, the nullness of the returned array
component depends on the receiver type argument. So
Collection<@NonNull String> c1 = ...;
c1.toArray(); // returns @NonNull Object []
Collection<@Nullable String> c2 = ...;
c2.toArray(); // returns @Nullable Object []
In the case of Collection.toArray(T[]), the type of the returned array depends on the
passed parameter as well and its size. In particular, the returned
array component would be of type @NonNull if the following
conditions hold:
NonNullCollection.toArray(T[]), namely if the
passed array is
c.toArray(new String[] { }),c.toArray(new String[0]), orc.toArray(new String[c.size()])| Constructor and Description |
|---|
CollectionToArrayHeuristics(ProcessingEnvironment env,
NullnessAnnotatedTypeFactory factory) |
| Modifier and Type | Method and Description |
|---|---|
void |
handle(MethodInvocationTree tree,
AnnotatedTypeMirror.AnnotatedExecutableType method)
Apply the heuristics to the given method invocation and corresponding
Collection.toArray() type. |
public CollectionToArrayHeuristics(ProcessingEnvironment env, NullnessAnnotatedTypeFactory factory)
public void handle(MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedExecutableType method)
Collection.toArray() type.
If the method invocation is a call to toArray, then it
manipulates the returned type of method arg to contain the
appropriate nullness. Otherwise, it does nothing.tree - method invocation treemethod - invoked method type