private boolean relevantInitializerMethodOrBlock()

in nullaway/src/main/java/com/uber/nullaway/NullAway.java [1258:1295]


  private boolean relevantInitializerMethodOrBlock(
      TreePath enclosingBlockPath, VisitorState state) {
    Tree methodLambdaOrBlock = enclosingBlockPath.getLeaf();
    if (methodLambdaOrBlock instanceof LambdaExpressionTree) {
      return false;
    } else if (methodLambdaOrBlock instanceof MethodTree) {
      MethodTree methodTree = (MethodTree) methodLambdaOrBlock;
      if (isConstructor(methodTree) && !constructorInvokesAnother(methodTree, state)) {
        return true;
      }

      Symbol.ClassSymbol enclClassSymbol = enclosingClassSymbol(enclosingBlockPath);

      // Checking for initialization is only meaningful if the full class is null-annotated, which
      // might not be the case with @NullMarked methods inside @NullUnmarked classes (note that,
      // in those cases, we won't even have a populated class2Entities map). We skip this check if
      // we are not inside a @NullMarked/annotated *class*:
      if (nullMarkingForTopLevelClass == NullMarking.PARTIALLY_MARKED
          && !codeAnnotationInfo.isClassNullAnnotated(enclClassSymbol, config, handler)) {
        return false;
      }

      if (ASTHelpers.getSymbol(methodTree).isStatic()) {
        ImmutableSet<MethodTree> staticInitializerMethods =
            castToNonNull(class2Entities.get(enclClassSymbol)).staticInitializerMethods();
        return staticInitializerMethods.size() == 1
            && staticInitializerMethods.contains(methodTree);
      } else {
        ImmutableSet<MethodTree> instanceInitializerMethods =
            castToNonNull(class2Entities.get(enclClassSymbol)).instanceInitializerMethods();
        return instanceInitializerMethods.size() == 1
            && instanceInitializerMethods.contains(methodTree);
      }
    } else {
      // initializer or field declaration
      return true;
    }
  }