in xbean-finder/src/main/java/org/apache/xbean/finder/MetaAnnotatedElement.java [145:203]
private static Collection<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> clazz) {
Map<Class, Annotation> map = new HashMap<Class, Annotation>();
// pull in the annotations declared on this annotation
for (Annotation annotation : clazz.getDeclaredAnnotations()) {
map.put(annotation.annotationType(), annotation);
}
List<Annotation[]> groups = new ArrayList<Annotation[]>();
Class<? extends Annotation> metatype = getMetatype(clazz);
if (metatype != null) {
try {
Class<?> def = clazz.getClassLoader().loadClass(clazz.getName() + "$$");
List<AnnotatedElement> elements = new ArrayList<AnnotatedElement>();
elements.addAll(asList(def.getDeclaredFields()));
elements.addAll(asList(def.getDeclaredConstructors()));
elements.addAll(asList(def.getDeclaredMethods()));
for (Method method : def.getDeclaredMethods()) {
for (Annotation[] array : method.getParameterAnnotations()) {
groups.add(array);
}
}
for (Constructor constructor : def.getDeclaredConstructors()) {
for (Annotation[] array : constructor.getParameterAnnotations()) {
groups.add(array);
}
}
for (AnnotatedElement element : elements) {
groups.add(element.getDeclaredAnnotations());
}
for (Annotation[] annotations : groups) {
if (contains(annotations, clazz)) {
for (Annotation annotation : annotations) {
map.put(annotation.annotationType(), annotation);
}
}
}
} catch (ClassNotFoundException e) {
// inner class is optional
}
}
map.remove(Target.class);
map.remove(Retention.class);
map.remove(Documented.class);
map.remove(metatype);
map.remove(clazz);
return map.values();
}