26
26
import java .util .HashMap ;
27
27
import java .util .Map ;
28
28
29
- import org .springframework .core .annotation .AnnotationUtils ;
30
29
import org .springframework .util .Assert ;
31
30
32
31
/**
33
32
* Helper class that encapsulates the specification of a method parameter, i.e.
34
33
* a Method or Constructor plus a parameter index and a nested type index for
35
34
* a declared generic type. Useful as a specification object to pass along.
36
35
*
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
+ *
37
40
* @author Juergen Hoeller
38
41
* @author Rob Harrop
39
42
* @author Andy Clement
@@ -388,17 +391,16 @@ public Type getNestedGenericParameterType() {
388
391
* Return the annotations associated with the target method/constructor itself.
389
392
*/
390
393
public Annotation [] getMethodAnnotations () {
391
- return AnnotationUtils . synthesizeAnnotationArray (getAnnotatedElement ().getAnnotations (), getAnnotatedElement ());
394
+ return adaptAnnotationArray (getAnnotatedElement ().getAnnotations ());
392
395
}
393
396
394
397
/**
395
398
* Return the method/constructor annotation of the given type, if available.
396
399
* @param annotationType the annotation type to look for
397
400
* @return the annotation object, or {@code null} if not found
398
401
*/
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 ));
402
404
}
403
405
404
406
/**
@@ -409,8 +411,7 @@ public Annotation[] getParameterAnnotations() {
409
411
Annotation [][] annotationArray = (this .method != null ?
410
412
this .method .getParameterAnnotations () : this .constructor .getParameterAnnotations ());
411
413
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 ]);
414
415
}
415
416
else {
416
417
this .parameterAnnotations = new Annotation [0 ];
@@ -480,6 +481,31 @@ public String getParameterName() {
480
481
}
481
482
482
483
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
+
483
509
@ Override
484
510
public boolean equals (Object other ) {
485
511
if (this == other ) {
0 commit comments