code: public static <S extends ScopeType<S>> boolean isScopeTypeAncestor(S scopeType, S possibleAncestor) {
      Queue<S> ancestors = new LinkedList<>();
      ancestors.add(scopeType);
      while (true) {
        if (ancestors.isEmpty()) {
          return false;
        }
        if (ancestors.peek().equals(possibleAncestor)) {
          return true;
        }
        Collection<S> parentScopes = ancestors.poll().parentScopes();
        if (parentScopes != null) {
          ancestors.addAll(parentScopes);
        }
      }
    }
docs: Determine if a {@link ScopeType} is an ancestor of another {@link ScopeType}.