@Override public Collection<Annotation> getAnnotation(Class<?> annotationClass) { List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName())); ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size()); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); Annotation annotation = null; if (target instanceof MethodInfo) { MethodInfo m = (MethodInfo) target; List<String> parameterTypes = new ArrayList<String>(m.args().length); for (Type type : m.args()) { parameterTypes.add(type.toString()); } String declaringClass = m.declaringClass().name().toString(); annotation = new AnnotationImpl( declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass); } if (target instanceof FieldInfo) { FieldInfo f = (FieldInfo) target; String declaringClass = f.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass); } if (target instanceof ClassInfo) { ClassInfo c = (ClassInfo) target; annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass); } if (annotation != null) { annotations.add(annotation); } } annotations.trimToSize(); if (annotations.size() == 0) { return null; } else { return Collections.unmodifiableList(annotations); } }
private static Type getType(Class clazz) { return Type.create(DotName.createSimple(clazz.getName()), getTypeKind(clazz)); }