ucr-riple / NullAwayAnnotator

A tool to help adapting code bases to NullAway type system.
MIT License
13 stars 6 forks source link

Acknowledge existing nonnull annotations #139

Closed nimakarimipour closed 1 year ago

nimakarimipour commented 1 year ago

Following #113 fixes were collected from the containing nonnull location in serialized errors. Previous to that PR fixes were read from the fixes.tsv serialized by NullAway and it was already skipping fixes for elements with explicit @Nonnull annotations. This PR enables annotator to follow the same logic and acknowledge existing @Nonnull annotations and prevent from adding @Nullable on such annotations.

The logic for detecting a @Nonnull annotations from its name is as below:

annotName.endsWith(".NonNull")
|| annotName.endsWith(".NotNull")
|| annotName.endsWith(".Nonnull")
|| annotName.equals("androidx.annotation.RecentlyNonNull")
|| config.isNonnullAnnotation(annotName);

To pass a custom set of nonnull annotations, use flag below:

-nna, --nonnull-annotations : Adds a list of nonnull annotations separated by comma to be acknowledged by Annotator (e.g. com.example1.Nonnull,com.example2.Nonnull)

In this PR scanner serializes all elements with explicit @Nonnull annotations to nonnull_elements.tsv and informs annotator-core module from existing elements, then in the deserialization of errors, these locations are used and marked as unresolvable.

Please note that prior to this PR, scanner was only serializing outputs below:

  1. Impacted regions
  2. Existing methods
  3. Existing classes flat names

This PR requires serialization of the exact location for elements with @Nonnull annotation, hence it uses the same API from NullAway (from location package) to serialize the exact location of an element. This the main reason that this is rather a large PR.