2626import java .util .HashMap ;
2727import java .util .Map ;
2828
29- import org .springframework .core .annotation .AnnotationUtils ;
3029import org .springframework .util .Assert ;
3130
3231/**
3332 * Helper class that encapsulates the specification of a method parameter, i.e.
3433 * a Method or Constructor plus a parameter index and a nested type index for
3534 * a declared generic type. Useful as a specification object to pass along.
3635 *
36+ * <p>As of 4.2, there is a {@link org.springframework.core.annotation.SynthesizingMethodParameter}
37+ * subclass available which synthesizes annotations based on overridden annotation attributes.
38+ * That subclass is being used for web and message endpoint processing, in particular.
39+ *
3740 * @author Juergen Hoeller
3841 * @author Rob Harrop
3942 * @author Andy Clement
@@ -388,17 +391,16 @@ public Type getNestedGenericParameterType() {
388391 * Return the annotations associated with the target method/constructor itself.
389392 */
390393 public Annotation [] getMethodAnnotations () {
391- return AnnotationUtils . synthesizeAnnotationArray (getAnnotatedElement ().getAnnotations (), getAnnotatedElement ());
394+ return adaptAnnotationArray (getAnnotatedElement ().getAnnotations ());
392395 }
393396
394397 /**
395398 * Return the method/constructor annotation of the given type, if available.
396399 * @param annotationType the annotation type to look for
397400 * @return the annotation object, or {@code null} if not found
398401 */
399- public <T extends Annotation > T getMethodAnnotation (Class <T > annotationType ) {
400- AnnotatedElement element = getAnnotatedElement ();
401- return AnnotationUtils .synthesizeAnnotation (element .getAnnotation (annotationType ), element );
402+ public <A extends Annotation > A getMethodAnnotation (Class <A > annotationType ) {
403+ return adaptAnnotation (getAnnotatedElement ().getAnnotation (annotationType ));
402404 }
403405
404406 /**
@@ -409,8 +411,7 @@ public Annotation[] getParameterAnnotations() {
409411 Annotation [][] annotationArray = (this .method != null ?
410412 this .method .getParameterAnnotations () : this .constructor .getParameterAnnotations ());
411413 if (this .parameterIndex >= 0 && this .parameterIndex < annotationArray .length ) {
412- this .parameterAnnotations = AnnotationUtils .synthesizeAnnotationArray (
413- annotationArray [this .parameterIndex ], getAnnotatedElement ());
414+ this .parameterAnnotations = adaptAnnotationArray (annotationArray [this .parameterIndex ]);
414415 }
415416 else {
416417 this .parameterAnnotations = new Annotation [0 ];
@@ -480,6 +481,31 @@ public String getParameterName() {
480481 }
481482
482483
484+ /**
485+ * A template method to post-process a given annotation instance before
486+ * returning it to the caller.
487+ * <p>The default implementation simply returns the given annotation as-is.
488+ * @param annotation the annotation about to be returned
489+ * @return the post-processed annotation (or simply the original one)
490+ * @since 4.2
491+ */
492+ protected <A extends Annotation > A adaptAnnotation (A annotation ) {
493+ return annotation ;
494+ }
495+
496+ /**
497+ * A template method to post-process a given annotation array before
498+ * returning it to the caller.
499+ * <p>The default implementation simply returns the given annotation array as-is.
500+ * @param annotations the annotation array about to be returned
501+ * @return the post-processed annotation array (or simply the original one)
502+ * @since 4.2
503+ */
504+ protected Annotation [] adaptAnnotationArray (Annotation [] annotations ) {
505+ return annotations ;
506+ }
507+
508+
483509 @ Override
484510 public boolean equals (Object other ) {
485511 if (this == other ) {
0 commit comments