Skip to content

Commit c5b318a

Browse files
committed
Revised 4.3 signatures for MethodParameter/DependencyDescriptor
Issue: SPR-13440
1 parent 9af12d2 commit c5b318a

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public Object resolveNotUnique(Class<?> type, Map<String, Object> matchingBeans)
180180
* @param beanName the bean name, as a candidate result for this dependency
181181
* @param beanFactory the associated factory
182182
* @return the bean instance (never {@code null})
183+
* @since 4.3
183184
* @see BeanFactory#getBean(String)
184185
*/
185186
public Object resolveCandidate(String beanName, BeanFactory beanFactory) {
@@ -278,6 +279,7 @@ public Class<?> getDependencyType() {
278279
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
279280
type = args[args.length - 1];
280281
}
282+
// TODO: Object.class if unresolvable
281283
}
282284
if (type instanceof Class) {
283285
return (Class<?>) type;

spring-core/src/main/java/org/springframework/core/MethodParameter.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ public Class<?> getNestedParameterType() {
406406
Integer index = getTypeIndexForLevel(i);
407407
type = args[index != null ? index : args.length - 1];
408408
}
409+
// TODO: Object.class if unresolvable
409410
}
410411
if (type instanceof Class) {
411412
return (Class<?>) type;
@@ -462,6 +463,16 @@ public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType) {
462463
return adaptAnnotation(getAnnotatedElement().getAnnotation(annotationType));
463464
}
464465

466+
/**
467+
* Return whether the method/constructor is annotated with the given type.
468+
* @param annotationType the annotation type to look for
469+
* @since 4.3
470+
* @see #getMethodAnnotation(Class)
471+
*/
472+
public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType) {
473+
return getAnnotatedElement().isAnnotationPresent(annotationType);
474+
}
475+
465476
/**
466477
* Return the annotations associated with the specific method/constructor parameter.
467478
*/
@@ -479,33 +490,37 @@ public Annotation[] getParameterAnnotations() {
479490
return this.parameterAnnotations;
480491
}
481492

493+
/**
494+
* Return {@code true} if the parameter has at least one annotation,
495+
* {@code false} if it has none.
496+
* @see #getParameterAnnotations()
497+
*/
498+
public boolean hasParameterAnnotations() {
499+
return (getParameterAnnotations().length != 0);
500+
}
501+
482502
/**
483503
* Return the parameter annotation of the given type, if available.
484504
* @param annotationType the annotation type to look for
485505
* @return the annotation object, or {@code null} if not found
486506
*/
487507
@SuppressWarnings("unchecked")
488-
public <T extends Annotation> T getParameterAnnotation(Class<T> annotationType) {
508+
public <A extends Annotation> A getParameterAnnotation(Class<A> annotationType) {
489509
Annotation[] anns = getParameterAnnotations();
490510
for (Annotation ann : anns) {
491511
if (annotationType.isInstance(ann)) {
492-
return (T) ann;
512+
return (A) ann;
493513
}
494514
}
495515
return null;
496516
}
497517

498518
/**
499-
* Return true if the parameter has at least one annotation, false if it has none.
500-
*/
501-
public boolean hasParameterAnnotations() {
502-
return (getParameterAnnotations().length != 0);
503-
}
504-
505-
/**
506-
* Return true if the parameter has the given annotation type, and false if it doesn't.
519+
* Return whether the parameter is declared with the given annotation type.
520+
* @param annotationType the annotation type to look for
521+
* @see #getParameterAnnotation(Class)
507522
*/
508-
public <T extends Annotation> boolean hasParameterAnnotation(Class<T> annotationType) {
523+
public <A extends Annotation> boolean hasParameterAnnotation(Class<A> annotationType) {
509524
return (getParameterAnnotation(annotationType) != null);
510525
}
511526

0 commit comments

Comments
 (0)