public static Visibility effectiveVisibilityOfElement(Element element) {
    checkNotNull(element);
    Visibility effectiveVisibility = PUBLIC;
    Element currentElement = element;
    while (currentElement != null) {
      // NOTE: We don't use Guava's Comparators.min() because that requires Guava 30, which would
      // make this library unusable in annotation processors using Bazel < 5.0.
      effectiveVisibility = Ordering.natural().min(effectiveVisibility, ofElement(currentElement));
      currentElement = currentElement.getEnclosingElement();
    }
    return effectiveVisibility;
  }
Returns effective visibility of the given element meaning that it takes into account the
visibility of its enclosing elements.
common/src/main/java/com/google/auto/common/Visibility.java