docs: private static boolean inStaticContext(TreePath path) {
      Tree prev = path.getLeaf();
      path = path.getParentPath();
  
      ClassSymbol enclosingClass =
          ASTHelpers.getSymbol(ASTHelpers.findEnclosingNode(path, ClassTree.class));
      ClassSymbol directSuperClass = (ClassSymbol) enclosingClass.getSuperclass().tsym;
  
      for (Tree tree : path) {
        switch (tree.getKind()) {
          case METHOD:
            return ASTHelpers.getSymbol(tree).isStatic();
          case BLOCK: // static initializer
            if (((BlockTree) tree).isStatic()) {
              return true;
            }
            break;
          case VARIABLE: // variable initializer of static variable
            VariableTree variableTree = (VariableTree) tree;
            VarSymbol variableSym = ASTHelpers.getSymbol(variableTree);
            if (variableSym.getKind() == ElementKind.FIELD) {
              return Objects.equals(variableTree.getInitializer(), prev) && variableSym.isStatic();
            }
            break;
          case METHOD_INVOCATION: // JLS 8.8.7.1 explicit constructor invocation
            MethodSymbol methodSym = ASTHelpers.getSymbol((MethodInvocationTree) tree);
            if (methodSym == null) {
              // sometimes javac can't resolve the symbol. In this case just assume that we are
              // in a static context - this is a safe approximation in our context (checking
              // visibility)
              return true;
            }
            if (methodSym.isConstructor()
                && (Objects.equals(methodSym.owner, enclosingClass)
                    || Objects.equals(methodSym.owner, directSuperClass))) {
              return true;
            }
            break;
          default:
            break;
        }
        prev = tree;
      }
      return false;
    }