private static <T extends Annotation> void addEffectiveClassAnnotations(Class<?> type, Class<T> annotation, ImmutableSet.Builder<T> builder) { if (type.isAnnotationPresent(annotation)) { builder.add(type.getAnnotation(annotation)); return; } if (type.getSuperclass() != null) { addEffectiveClassAnnotations(type.getSuperclass(), annotation, builder); } for (Class<?> anInterface : type.getInterfaces()) { addEffectiveClassAnnotations(anInterface, annotation, builder); } }
private static <T extends Annotation> void addEffectiveClassAnnotations(Class<?> type, Class<T> annotation, ImmutableSet.Builder<T> builder) { if (type.isAnnotationPresent(annotation)) { builder.add(type.getAnnotation(annotation)); return; } if (type.getSuperclass() != null) { addEffectiveClassAnnotations(type.getSuperclass(), annotation, builder); } for (Class<?> anInterface : type.getInterfaces()) { addEffectiveClassAnnotations(anInterface, annotation, builder); } }
public static <T extends Annotation> Set<T> getEffectiveClassAnnotations(Class<?> type, Class<T> annotation) { // if the class is directly annotated, it is considered the only annotation if (type.isAnnotationPresent(annotation)) { return ImmutableSet.of(type.getAnnotation(annotation)); } // otherwise find all annotations from all super classes and interfaces ImmutableSet.Builder<T> builder = ImmutableSet.builder(); addEffectiveClassAnnotations(type, annotation, builder); return builder.build(); }
public static <T extends Annotation> Set<T> getEffectiveClassAnnotations(Class<?> type, Class<T> annotation) { // if the class is directly annotated, it is considered the only annotation if (type.isAnnotationPresent(annotation)) { return ImmutableSet.of(type.getAnnotation(annotation)); } // otherwise find all annotations from all super classes and interfaces ImmutableSet.Builder<T> builder = ImmutableSet.builder(); addEffectiveClassAnnotations(type, annotation, builder); return builder.build(); }