From 518c85b1077e34b63d17dfbf5d0149bb7c764f00 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 29 May 2015 22:48:55 +0200 Subject: [PATCH] Support synthesized annotations in MethodParameter --- .../java/org/springframework/core/MethodParameter.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 368d4c48f2..6a0137aa57 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -26,6 +26,7 @@ import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.util.Assert; /** @@ -36,6 +37,7 @@ import org.springframework.util.Assert; * @author Juergen Hoeller * @author Rob Harrop * @author Andy Clement + * @author Sam Brannen * @since 2.0 * @see GenericCollectionTypeResolver */ @@ -386,7 +388,7 @@ public class MethodParameter { * Return the annotations associated with the target method/constructor itself. */ public Annotation[] getMethodAnnotations() { - return getAnnotatedElement().getAnnotations(); + return AnnotationUtils.synthesizeAnnotationArray(getAnnotatedElement().getAnnotations(), getAnnotatedElement()); } /** @@ -395,7 +397,8 @@ public class MethodParameter { * @return the annotation object, or {@code null} if not found */ public T getMethodAnnotation(Class annotationType) { - return getAnnotatedElement().getAnnotation(annotationType); + AnnotatedElement element = getAnnotatedElement(); + return AnnotationUtils.synthesizeAnnotation(element.getAnnotation(annotationType), element); } /** @@ -406,7 +409,8 @@ public class MethodParameter { Annotation[][] annotationArray = (this.method != null ? this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations()); if (this.parameterIndex >= 0 && this.parameterIndex < annotationArray.length) { - this.parameterAnnotations = annotationArray[this.parameterIndex]; + this.parameterAnnotations = AnnotationUtils.synthesizeAnnotationArray( + annotationArray[this.parameterIndex], getAnnotatedElement()); } else { this.parameterAnnotations = new Annotation[0];