private void writeModel()

in jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/DefinitelyDerefedParamsDriver.java [434:474]


  private void writeModel(DataOutputStream out) throws IOException {
    ImmutableMap<String, String> importedAnnotations =
        ImmutableMap.<String, String>builder()
            .put("Nonnull", "javax.annotation.Nonnull")
            .put("Nullable", "javax.annotation.Nullable")
            .build();
    Map<String, Set<String>> packageAnnotations = new HashMap<>();
    Map<String, Set<String>> typeAnnotations = new HashMap<>();
    Map<String, MethodAnnotationsRecord> methodRecords = new LinkedHashMap<>();

    for (Map.Entry<String, Set<Integer>> entry : nonnullParams.entrySet()) {
      String sign = entry.getKey();
      Set<Integer> ddParams = entry.getValue();
      if (ddParams.isEmpty()) {
        continue;
      }
      Map<Integer, ImmutableSet<String>> argAnnotation = new HashMap<>();
      for (Integer param : ddParams) {
        argAnnotation.put(param, ImmutableSet.of("Nonnull"));
      }
      methodRecords.put(
          sign,
          MethodAnnotationsRecord.create(
              nullableReturns.contains(sign) ? ImmutableSet.of("Nullable") : ImmutableSet.of(),
              ImmutableMap.copyOf(argAnnotation)));
      nullableReturns.remove(sign);
    }
    for (String nullableReturnMethodSign : Iterator2Iterable.make(nullableReturns.iterator())) {
      methodRecords.put(
          nullableReturnMethodSign,
          MethodAnnotationsRecord.create(ImmutableSet.of("Nullable"), ImmutableMap.of()));
    }
    StubxWriter.write(
        out,
        importedAnnotations,
        packageAnnotations,
        typeAnnotations,
        methodRecords,
        Collections.emptySet(),
        Collections.emptyMap());
  }