private static void collectClasses(Class<?> clazz, ImmutableList.Builder<Class<?>> collector,
                                       boolean collectSuperClassesFirst) {
        final Class<?> superClass = clazz.getSuperclass();
        final Class<?>[] superInterfaces = clazz.getInterfaces();

        if (!collectSuperClassesFirst) {
            collector.add(clazz);
        }
        if (superInterfaces.length > 0) {
            Arrays.stream(superInterfaces)
                  .forEach(superInterface -> collectClasses(
                          superInterface, collector, collectSuperClassesFirst));
        }
        if (superClass != null && superClass != Object.class) {
            collectClasses(superClass, collector, collectSuperClassesFirst);
        }
        if (collectSuperClassesFirst) {
            collector.add(clazz);
        }
    }
Collects the list of {@link AnnotatedElement}s which are to be used to find annotations.
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotationUtil.java