code: static Class<?>[] getAncestors(Class<?> clazz) {
          Set<Class<?>> classes = new HashSet<Class<?>>();
          while (clazz != null) {
              classes.add(clazz);
              if (clazz.getSuperclass() != null) {
                  classes.add(clazz.getSuperclass());
              }
              classes.addAll(Arrays.asList(clazz.getInterfaces()));
              for (Class<?> interfaze : clazz.getInterfaces()) {
                  classes.addAll(Arrays.asList(getAncestors(interfaze)));
              }
  
              clazz = clazz.getSuperclass();
          }
  
          return classes.toArray(new Class<?>[classes.size()]);
      }
docs: Get all subclasses and interfaces in whole class hierarchy