diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java index e5410e859c..c38deb7480 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java @@ -180,6 +180,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable * @param beanName the bean name, as a candidate result for this dependency * @param beanFactory the associated factory * @return the bean instance (never {@code null}) + * @since 4.3 * @see BeanFactory#getBean(String) */ public Object resolveCandidate(String beanName, BeanFactory beanFactory) { @@ -278,6 +279,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable Type[] args = ((ParameterizedType) type).getActualTypeArguments(); type = args[args.length - 1]; } + // TODO: Object.class if unresolvable } if (type instanceof Class) { return (Class) type; 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 8d37976279..db46782c5a 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -406,6 +406,7 @@ public class MethodParameter { Integer index = getTypeIndexForLevel(i); type = args[index != null ? index : args.length - 1]; } + // TODO: Object.class if unresolvable } if (type instanceof Class) { return (Class) type; @@ -462,6 +463,16 @@ public class MethodParameter { return adaptAnnotation(getAnnotatedElement().getAnnotation(annotationType)); } + /** + * Return whether the method/constructor is annotated with the given type. + * @param annotationType the annotation type to look for + * @since 4.3 + * @see #getMethodAnnotation(Class) + */ + public boolean hasMethodAnnotation(Class annotationType) { + return getAnnotatedElement().isAnnotationPresent(annotationType); + } + /** * Return the annotations associated with the specific method/constructor parameter. */ @@ -480,32 +491,36 @@ public class MethodParameter { } /** - * Return the parameter annotation of the given type, if available. - * @param annotationType the annotation type to look for - * @return the annotation object, or {@code null} if not found - */ - @SuppressWarnings("unchecked") - public T getParameterAnnotation(Class annotationType) { - Annotation[] anns = getParameterAnnotations(); - for (Annotation ann : anns) { - if (annotationType.isInstance(ann)) { - return (T) ann; - } - } - return null; - } - - /** - * Return true if the parameter has at least one annotation, false if it has none. + * Return {@code true} if the parameter has at least one annotation, + * {@code false} if it has none. + * @see #getParameterAnnotations() */ public boolean hasParameterAnnotations() { return (getParameterAnnotations().length != 0); } /** - * Return true if the parameter has the given annotation type, and false if it doesn't. + * Return the parameter annotation of the given type, if available. + * @param annotationType the annotation type to look for + * @return the annotation object, or {@code null} if not found */ - public boolean hasParameterAnnotation(Class annotationType) { + @SuppressWarnings("unchecked") + public A getParameterAnnotation(Class annotationType) { + Annotation[] anns = getParameterAnnotations(); + for (Annotation ann : anns) { + if (annotationType.isInstance(ann)) { + return (A) ann; + } + } + return null; + } + + /** + * Return whether the parameter is declared with the given annotation type. + * @param annotationType the annotation type to look for + * @see #getParameterAnnotation(Class) + */ + public boolean hasParameterAnnotation(Class annotationType) { return (getParameterAnnotation(annotationType) != null); }