|
|
@ -151,7 +151,7 @@ public class AnnotatedElementUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
return getMetaAnnotationTypes(element, element.getAnnotation(annotationType)); |
|
|
|
return getMetaAnnotationTypes(element, element.getAnnotation(annotationType)); |
|
|
|
} |
|
|
|
} |
|
|
@ -213,7 +213,7 @@ public class AnnotatedElementUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
return hasMetaAnnotationTypes(element, annotationType, null); |
|
|
|
return hasMetaAnnotationTypes(element, annotationType, null); |
|
|
|
} |
|
|
|
} |
|
|
@ -266,7 +266,7 @@ public class AnnotatedElementUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
// Shortcut: directly present on the element, with no processing needed?
|
|
|
|
// Shortcut: directly present on the element, with no processing needed?
|
|
|
|
if (element.isAnnotationPresent(annotationType)) { |
|
|
|
if (element.isAnnotationPresent(annotationType)) { |
|
|
@ -315,7 +315,7 @@ public class AnnotatedElementUtils { |
|
|
|
public static AnnotationAttributes getMergedAnnotationAttributes( |
|
|
|
public static AnnotationAttributes getMergedAnnotationAttributes( |
|
|
|
AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
AnnotationAttributes attributes = searchWithGetSemantics(element, annotationType, null, |
|
|
|
AnnotationAttributes attributes = searchWithGetSemantics(element, annotationType, null, |
|
|
|
new MergedAnnotationAttributesProcessor()); |
|
|
|
new MergedAnnotationAttributesProcessor()); |
|
|
|
AnnotationUtils.postProcessAnnotationAttributes(element, attributes, false, false); |
|
|
|
AnnotationUtils.postProcessAnnotationAttributes(element, attributes, false, false); |
|
|
@ -399,7 +399,7 @@ public class AnnotatedElementUtils { |
|
|
|
* @see AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement) |
|
|
|
* @see AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement element, Class<A> annotationType) { |
|
|
|
public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement element, Class<A> annotationType) { |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
// Shortcut: directly present on the element, with no merging needed?
|
|
|
|
// Shortcut: directly present on the element, with no merging needed?
|
|
|
|
if (!(element instanceof Class)) { |
|
|
|
if (!(element instanceof Class)) { |
|
|
@ -440,7 +440,7 @@ public class AnnotatedElementUtils { |
|
|
|
Class<A> annotationType) { |
|
|
|
Class<A> annotationType) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true); |
|
|
|
MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true); |
|
|
|
searchWithGetSemantics(element, annotationType, null, processor); |
|
|
|
searchWithGetSemantics(element, annotationType, null, processor); |
|
|
@ -507,7 +507,7 @@ public class AnnotatedElementUtils { |
|
|
|
Class<A> annotationType, Class<? extends Annotation> containerType) { |
|
|
|
Class<A> annotationType, Class<? extends Annotation> containerType) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
if (containerType == null) { |
|
|
|
if (containerType == null) { |
|
|
|
containerType = resolveContainerType(annotationType); |
|
|
|
containerType = resolveContainerType(annotationType); |
|
|
@ -593,7 +593,7 @@ public class AnnotatedElementUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
public static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType) { |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
// Shortcut: directly present on the element, with no processing needed?
|
|
|
|
// Shortcut: directly present on the element, with no processing needed?
|
|
|
|
if (element.isAnnotationPresent(annotationType)) { |
|
|
|
if (element.isAnnotationPresent(annotationType)) { |
|
|
@ -696,7 +696,7 @@ public class AnnotatedElementUtils { |
|
|
|
* @see #getMergedAnnotationAttributes(AnnotatedElement, Class) |
|
|
|
* @see #getMergedAnnotationAttributes(AnnotatedElement, Class) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) { |
|
|
|
public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) { |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
// Shortcut: directly present on the element, with no merging needed?
|
|
|
|
// Shortcut: directly present on the element, with no merging needed?
|
|
|
|
if (!(element instanceof Class)) { |
|
|
|
if (!(element instanceof Class)) { |
|
|
@ -736,7 +736,7 @@ public class AnnotatedElementUtils { |
|
|
|
Class<A> annotationType) { |
|
|
|
Class<A> annotationType) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true); |
|
|
|
MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true); |
|
|
|
searchWithFindSemantics(element, annotationType, null, processor); |
|
|
|
searchWithFindSemantics(element, annotationType, null, processor); |
|
|
@ -803,7 +803,7 @@ public class AnnotatedElementUtils { |
|
|
|
Class<A> annotationType, Class<? extends Annotation> containerType) { |
|
|
|
Class<A> annotationType, Class<? extends Annotation> containerType) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(element, "AnnotatedElement must not be null"); |
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
Assert.notNull(annotationType, "'annotationType' must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
if (containerType == null) { |
|
|
|
if (containerType == null) { |
|
|
|
containerType = resolveContainerType(annotationType); |
|
|
|
containerType = resolveContainerType(annotationType); |
|
|
@ -910,7 +910,7 @@ public class AnnotatedElementUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
AnnotationUtils.handleIntrospectionFailure(element, ex); |
|
|
|
AnnotationUtils.handleIntrospectionFailure(element, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1199,7 +1199,7 @@ public class AnnotatedElementUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
AnnotationUtils.handleIntrospectionFailure(element, ex); |
|
|
|
AnnotationUtils.handleIntrospectionFailure(element, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1241,7 +1241,7 @@ public class AnnotatedElementUtils { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return (A[]) AnnotationUtils.getValue(container); |
|
|
|
return (A[]) AnnotationUtils.getValue(container); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
AnnotationUtils.handleIntrospectionFailure(element, ex); |
|
|
|
AnnotationUtils.handleIntrospectionFailure(element, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
// Unable to read value from repeating annotation container -> ignore it.
|
|
|
|
// Unable to read value from repeating annotation container -> ignore it.
|
|
|
@ -1260,8 +1260,8 @@ public class AnnotatedElementUtils { |
|
|
|
Class<? extends Annotation> containerType = AnnotationUtils.resolveContainerAnnotationType(annotationType); |
|
|
|
Class<? extends Annotation> containerType = AnnotationUtils.resolveContainerAnnotationType(annotationType); |
|
|
|
if (containerType == null) { |
|
|
|
if (containerType == null) { |
|
|
|
throw new IllegalArgumentException( |
|
|
|
throw new IllegalArgumentException( |
|
|
|
"annotationType must be a repeatable annotation: failed to resolve container type for " |
|
|
|
"Annotation type must be a repeatable annotation: failed to resolve container type for " + |
|
|
|
+ annotationType.getName()); |
|
|
|
annotationType.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
return containerType; |
|
|
|
return containerType; |
|
|
|
} |
|
|
|
} |
|
|
@ -1283,15 +1283,15 @@ public class AnnotatedElementUtils { |
|
|
|
Class<?> returnType = method.getReturnType(); |
|
|
|
Class<?> returnType = method.getReturnType(); |
|
|
|
if (!returnType.isArray() || returnType.getComponentType() != annotationType) { |
|
|
|
if (!returnType.isArray() || returnType.getComponentType() != annotationType) { |
|
|
|
String msg = String.format( |
|
|
|
String msg = String.format( |
|
|
|
"Container type [%s] must declare a 'value' attribute for an array of type [%s]", |
|
|
|
"Container type [%s] must declare a 'value' attribute for an array of type [%s]", |
|
|
|
containerType.getName(), annotationType.getName()); |
|
|
|
containerType.getName(), annotationType.getName()); |
|
|
|
throw new AnnotationConfigurationException(msg); |
|
|
|
throw new AnnotationConfigurationException(msg); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
AnnotationUtils.rethrowAnnotationConfigurationException(ex); |
|
|
|
AnnotationUtils.rethrowAnnotationConfigurationException(ex); |
|
|
|
String msg = String.format("Invalid declaration of container type [%s] for repeatable annotation [%s]", |
|
|
|
String msg = String.format("Invalid declaration of container type [%s] for repeatable annotation [%s]", |
|
|
|
containerType.getName(), annotationType.getName()); |
|
|
|
containerType.getName(), annotationType.getName()); |
|
|
|
throw new AnnotationConfigurationException(msg, ex); |
|
|
|
throw new AnnotationConfigurationException(msg, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|