public Nullness getNullnessOfFieldForReceiverTree()

in nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessAnalysis.java [265:297]


  public Nullness getNullnessOfFieldForReceiverTree(
      TreePath path, Context context, Tree baseExpr, VariableElement field, boolean trimReceiver) {
    Preconditions.checkArgument(field.getKind().equals(ElementKind.FIELD));
    AnalysisResult<Nullness, NullnessStore> result =
        dataFlow.resultForExpr(path, context, nullnessPropagation);
    if (result == null) {
      return Nullness.NULLABLE;
    }
    NullnessStore store = result.getStoreBefore(path.getLeaf());
    // used set of nodes, a tree can have multiple nodes.
    Set<Node> baseNodes = result.getNodesForTree(baseExpr);
    if (store == null || baseNodes == null) {
      return Nullness.NULLABLE;
    }
    // look for all possible access paths might exist in store.
    for (Node baseNode : baseNodes) {
      // it trims the baseExpr to process only the receiver. (e.g. a.f() is trimmed to a)
      if (trimReceiver && baseNode instanceof MethodAccessNode) {
        baseNode = ((MethodAccessNode) baseNode).getReceiver();
      }
      AccessPath accessPath = AccessPath.fromBaseAndElement(baseNode, field, apContext);
      if (accessPath == null) {
        continue;
      }
      Nullness nullness = store.getNullnessOfAccessPath(accessPath);
      // field is non-null if at least one access path referring to it exists with non-null
      // nullness.
      if (!nullness.equals(Nullness.NULLABLE)) {
        return nullness;
      }
    }
    return Nullness.NULLABLE;
  }