|
|
|
|
@@ -70,8 +70,8 @@ public abstract class AnnotationUtils {
|
|
|
|
|
* Get a single {@link Annotation} of {@code annotationType} from the supplied
|
|
|
|
|
* annotation: either the given annotation itself or a meta-annotation thereof.
|
|
|
|
|
* @param ann the Annotation to check
|
|
|
|
|
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
|
|
|
|
|
* @return the matching annotation or {@code null} if not found
|
|
|
|
|
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
|
|
|
|
|
* @return the matching annotation, or {@code null} if none found
|
|
|
|
|
* @since 4.0
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@@ -87,8 +87,8 @@ public abstract class AnnotationUtils {
|
|
|
|
|
* Method, Constructor or Field. Meta-annotations will be searched if the annotation
|
|
|
|
|
* is not declared locally on the supplied element.
|
|
|
|
|
* @param ae the Method, Constructor or Field from which to get the annotation
|
|
|
|
|
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
|
|
|
|
|
* @return the matching annotation or {@code null} if not found
|
|
|
|
|
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
|
|
|
|
|
* @return the matching annotation, or {@code null} if none found
|
|
|
|
|
* @since 3.1
|
|
|
|
|
*/
|
|
|
|
|
public static <T extends Annotation> T getAnnotation(AnnotatedElement ae, Class<T> annotationType) {
|
|
|
|
|
@@ -119,7 +119,7 @@ public abstract class AnnotationUtils {
|
|
|
|
|
* Get a single {@link Annotation} of {@code annotationType} from the supplied {@link Method}.
|
|
|
|
|
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
|
|
|
|
* @param method the method to look for annotations on
|
|
|
|
|
* @param annotationType the annotation class to look for
|
|
|
|
|
* @param annotationType the annotation type to look for
|
|
|
|
|
* @return the annotations found
|
|
|
|
|
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
|
|
|
|
*/
|
|
|
|
|
@@ -135,7 +135,7 @@ public abstract class AnnotationUtils {
|
|
|
|
|
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
|
|
|
|
* @param method the method to look for annotations on
|
|
|
|
|
* @param containerAnnotationType the class of the container that holds the annotations
|
|
|
|
|
* @param annotationType the annotation class to look for
|
|
|
|
|
* @param annotationType the annotation type to look for
|
|
|
|
|
* @return the annotations found
|
|
|
|
|
* @since 4.0
|
|
|
|
|
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
|
|
|
|
@@ -154,7 +154,7 @@ public abstract class AnnotationUtils {
|
|
|
|
|
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
|
|
|
|
* @param annotatedElement the element to look for annotations on
|
|
|
|
|
* @param containerAnnotationType the class of the container that holds the annotations
|
|
|
|
|
* @param annotationType the annotation class to look for
|
|
|
|
|
* @param annotationType the annotation type to look for
|
|
|
|
|
* @return the annotations found
|
|
|
|
|
* @since 4.0
|
|
|
|
|
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
|
|
|
|
@@ -170,13 +170,13 @@ public abstract class AnnotationUtils {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find a single {@link Annotation} of {@code annotationType} from the supplied
|
|
|
|
|
* {@link Method}, traversing its super methods (i.e., from super classes and
|
|
|
|
|
* {@link Method}, traversing its super methods (i.e., from superclasses and
|
|
|
|
|
* interfaces) if no annotation can be found on the given method itself.
|
|
|
|
|
* <p>Annotations on methods are not inherited by default, so we need to handle
|
|
|
|
|
* this explicitly.
|
|
|
|
|
* @param method the method to look for annotations on
|
|
|
|
|
* @param annotationType the annotation class to look for
|
|
|
|
|
* @return the annotation found, or {@code null} if none found
|
|
|
|
|
* @param annotationType the annotation type to look for
|
|
|
|
|
* @return the annotation found, or {@code null} if none
|
|
|
|
|
*/
|
|
|
|
|
public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) {
|
|
|
|
|
A annotation = getAnnotation(method, annotationType);
|
|
|
|
|
@@ -288,8 +288,7 @@ public abstract class AnnotationUtils {
|
|
|
|
|
}
|
|
|
|
|
for (Annotation ann : clazz.getDeclaredAnnotations()) {
|
|
|
|
|
if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) {
|
|
|
|
|
A annotation = findAnnotation(ann.annotationType(), annotationType,
|
|
|
|
|
visited);
|
|
|
|
|
A annotation = findAnnotation(ann.annotationType(), annotationType, visited);
|
|
|
|
|
if (annotation != null) {
|
|
|
|
|
return annotation;
|
|
|
|
|
}
|
|
|
|
|
@@ -312,8 +311,8 @@ public abstract class AnnotationUtils {
|
|
|
|
|
* <p>The standard {@link Class} API does not provide a mechanism for determining which class
|
|
|
|
|
* in an inheritance hierarchy actually declares an {@link Annotation}, so we need to handle
|
|
|
|
|
* this explicitly.
|
|
|
|
|
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
|
|
|
|
|
* @param clazz the class on which to check for the annotation, or {@code null}
|
|
|
|
|
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
|
|
|
|
|
* @param clazz the class on which to check for the annotation (may be {@code null})
|
|
|
|
|
* @return the first {@link Class} in the inheritance hierarchy of the specified {@code clazz}
|
|
|
|
|
* which declares an annotation for the specified {@code annotationType}, or {@code null}
|
|
|
|
|
* if not found
|
|
|
|
|
@@ -509,8 +508,7 @@ public abstract class AnnotationUtils {
|
|
|
|
|
Annotation[] realAnnotations = (Annotation[]) value;
|
|
|
|
|
AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
|
|
|
|
|
for (int i = 0; i < realAnnotations.length; i++) {
|
|
|
|
|
mappedAnnotations[i] = getAnnotationAttributes(
|
|
|
|
|
realAnnotations[i], classValuesAsString, true);
|
|
|
|
|
mappedAnnotations[i] = getAnnotationAttributes(realAnnotations[i], classValuesAsString, true);
|
|
|
|
|
}
|
|
|
|
|
attrs.put(method.getName(), mappedAnnotations);
|
|
|
|
|
}
|
|
|
|
|
@@ -634,7 +632,7 @@ public abstract class AnnotationUtils {
|
|
|
|
|
this.result.add((A) annotation);
|
|
|
|
|
}
|
|
|
|
|
else if (ObjectUtils.nullSafeEquals(this.containerAnnotationType, annotation.annotationType())) {
|
|
|
|
|
result.addAll(Arrays.asList(getValue(annotation)));
|
|
|
|
|
this.result.addAll(Arrays.asList(getValue(annotation)));
|
|
|
|
|
}
|
|
|
|
|
else if (!isInJavaLangAnnotationPackage(annotation)) {
|
|
|
|
|
process(annotation.annotationType());
|
|
|
|
|
@@ -651,8 +649,8 @@ public abstract class AnnotationUtils {
|
|
|
|
|
return (A[]) method.invoke(annotation);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
throw new IllegalStateException("Unable to read value from repeating annotation container "
|
|
|
|
|
+ this.containerAnnotationType.getName(), ex);
|
|
|
|
|
throw new IllegalStateException("Unable to read value from repeating annotation container " +
|
|
|
|
|
this.containerAnnotationType.getName(), ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|