code: @SuppressWarnings("unchecked")
      private static List<Class> resolveRootTypes(final List<Class> roots, final Class type) {
          roots.add(type);
          if (type == Configuration.class) {
              return roots;
          }
          for (Class iface : type.getInterfaces()) {
              if (isInStopPackage(iface)) {
                  continue;
              }
              roots.add(iface);
          }
          return resolveRootTypes(roots, type.getSuperclass());
      }
docs: Analyze configuration class structure to extract all classes in hierarchy with all custom
  interfaces (ignoring, for example Serializable or something like this).
  
  @param roots all collected types so far
  @param type  type to analyze
  @return all collected types