code: @SuppressWarnings("unchecked")
      public <T extends ElementBase> T getAncestor(Class<T> clazz) {
          ElementBase parent = getParent();
          
          while (parent != null && !clazz.isInstance(parent)) {
              parent = parent.getParent();
          }
          
          return (T) parent;
      }
docs: Returns the first ancestor corresponding to the specified class.
  
  @param <T> The type of ancestor sought.
  @param clazz Class of ancestor sought.
  @return An ancestor of the specified class or null if not found.