public NullnessHint onDataflowVisitMethodInvocation()

in nullaway/src/main/java/com/uber/nullaway/handlers/AssertionHandler.java [47:89]


  public NullnessHint onDataflowVisitMethodInvocation(
      MethodInvocationNode node,
      Symbol.MethodSymbol callee,
      VisitorState state,
      AccessPath.AccessPathContext apContext,
      AccessPathNullnessPropagation.SubNodeValues inputs,
      AccessPathNullnessPropagation.Updates thenUpdates,
      AccessPathNullnessPropagation.Updates elseUpdates,
      AccessPathNullnessPropagation.Updates bothUpdates) {
    if (!methodNameUtil.isUtilInitialized()) {
      methodNameUtil.initializeMethodNames(callee.name.table);
    }

    // Look for statements of the form: assertThat(A).isNotNull() or
    // assertThat(A).isInstanceOf(Foo.class)
    // A will not be NULL after this statement.
    if (methodNameUtil.isMethodIsNotNull(callee) || methodNameUtil.isMethodIsInstanceOf(callee)) {
      AccessPath ap = getAccessPathForNotNullAssertThatExpr(node, state, apContext);
      if (ap != null) {
        bothUpdates.set(ap, NONNULL);
      }
    }

    // Look for statements of the form:
    //    * assertThat(A, is(not(nullValue())))
    //    * assertThat(A, is(notNullValue()))
    //    * assertThat(A, is(instanceOf(Foo.class)))
    //    * assertThat(A, isA(Foo.class))
    if (methodNameUtil.isMethodHamcrestAssertThat(callee)
        || methodNameUtil.isMethodJunitAssertThat(callee)) {
      List<Node> args = node.getArguments();
      if (args.size() == 2
          && (methodNameUtil.isMatcherIsNotNull(args.get(1))
              || methodNameUtil.isMatcherIsInstanceOf(args.get(1)))) {
        AccessPath ap = AccessPath.getAccessPathForNode(args.get(0), state, apContext);
        if (ap != null) {
          bothUpdates.set(ap, NONNULL);
        }
      }
    }

    return NullnessHint.UNKNOWN;
  }