@@ -218,6 +218,32 @@ public Boolean process(AnnotatedElement annotatedElement, Annotation annotation,
218
218
}));
219
219
}
220
220
221
+ /**
222
+ * Get the first annotation of the specified {@code annotationType} within
223
+ * the annotation hierarchy <em>above</em> the supplied {@code element},
224
+ * merge that annotation's attributes with <em>matching</em> attributes from
225
+ * annotations in lower levels of the annotation hierarchy, and synthesize
226
+ * the result back into an annotation of the specified {@code annotationType}.
227
+ *
228
+ * <p>{@link AliasFor @AliasFor} semantics are fully supported, both
229
+ * within a single annotation and within the annotation hierarchy.
230
+ *
231
+ * <p>This method delegates to {@link #getAnnotationAttributes(AnnotatedElement, Class)}
232
+ * and {@link AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement)}.
233
+ *
234
+ * @param element the annotated element; never {@code null}
235
+ * @param annotationType the annotation type to find; never {@code null}
236
+ * @return the merged {@code AnnotationAttributes}, or {@code null} if not found
237
+ * @since 4.2
238
+ * @see #getAnnotationAttributes(AnnotatedElement, Class)
239
+ * @see #findAnnotation(AnnotatedElement, Class)
240
+ * @see AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement)
241
+ */
242
+ public static <A extends Annotation > A getAnnotation (AnnotatedElement element , Class <A > annotationType ) {
243
+ AnnotationAttributes attributes = getAnnotationAttributes (element , annotationType );
244
+ return ((attributes != null ) ? AnnotationUtils .synthesizeAnnotation (attributes , annotationType , element ) : null );
245
+ }
246
+
221
247
/**
222
248
* Get the first annotation of the specified {@code annotationType} within
223
249
* the annotation hierarchy <em>above</em> the supplied {@code element} and
@@ -232,9 +258,10 @@ public Boolean process(AnnotatedElement annotatedElement, Annotation annotation,
232
258
* @param element the annotated element; never {@code null}
233
259
* @param annotationType the annotation type to find; never {@code null}
234
260
* @return the merged {@code AnnotationAttributes}, or {@code null} if not found
261
+ * @since 4.2
235
262
* @see #getAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
236
- * @see #getAllAnnotationAttributes(AnnotatedElement, String)
237
263
* @see #findAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
264
+ * @see #getAnnotation(AnnotatedElement, Class)
238
265
* @see #findAnnotation(AnnotatedElement, Class)
239
266
*/
240
267
public static AnnotationAttributes getAnnotationAttributes (AnnotatedElement element ,
@@ -945,8 +972,9 @@ public final void postProcess(AnnotatedElement annotatedElement, Annotation anno
945
972
* target annotation during the {@link #process} phase and then merges
946
973
* annotation attributes from lower levels in the annotation hierarchy
947
974
* during the {@link #postProcess} phase.
948
- * @see AnnotationUtils#getAnnotationAttributes(Annotation)
949
975
* @since 4.2
976
+ * @see AnnotationUtils#getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean, boolean)
977
+ * @see AnnotationUtils#postProcessAnnotationAttributes
950
978
*/
951
979
private static class MergedAnnotationAttributesProcessor implements Processor <AnnotationAttributes > {
952
980
0 commit comments