@Value can be used as aliased meta-annotation

Issue: SPR-13603
This commit is contained in:
Juergen Hoeller
2015-12-29 18:02:16 +01:00
parent 3242ad8fc4
commit 4f955932a7
3 changed files with 123 additions and 13 deletions

View File

@@ -97,6 +97,35 @@ public class AnnotatedElementUtils {
private static final Boolean CONTINUE = null;
/**
* Build an adapted {@link AnnotatedElement} for the given annotations,
* typically for use with other methods on {@link AnnotatedElementUtils}.
* @param annotations the annotations to expose through the {@code AnnotatedElement}
* @since 4.3
*/
public static AnnotatedElement forAnnotations(final Annotation... annotations) {
return new AnnotatedElement() {
@Override
@SuppressWarnings("unchecked")
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
for (Annotation ann : annotations) {
if (ann.annotationType() == annotationClass) {
return (T) ann;
}
}
return null;
}
@Override
public Annotation[] getAnnotations() {
return annotations;
}
@Override
public Annotation[] getDeclaredAnnotations() {
return annotations;
}
};
}
/**
* Get the fully qualified class names of all meta-annotation types
* <em>present</em> on the annotation (of the specified {@code annotationType})