|
18 | 18 |
|
19 | 19 | import java.lang.annotation.Annotation;
|
20 | 20 | import java.lang.reflect.AnnotatedElement;
|
21 |
| -import java.lang.reflect.Method; |
22 | 21 | import java.lang.reflect.Parameter;
|
23 | 22 | import java.util.Optional;
|
24 | 23 |
|
|
31 | 30 | import org.springframework.context.ApplicationContext;
|
32 | 31 | import org.springframework.core.MethodParameter;
|
33 | 32 | import org.springframework.core.annotation.AnnotatedElementUtils;
|
| 33 | +import org.springframework.core.annotation.SynthesizingMethodParameter; |
34 | 34 |
|
35 | 35 | /**
|
36 | 36 | * Collection of utilities related to autowiring of individual method parameters.
|
37 | 37 | *
|
38 | 38 | * @author Sam Brannen
|
39 | 39 | * @since 5.0
|
40 |
| - * @see MethodParameterFactory |
41 | 40 | * @see #isAutowirable(Parameter)
|
42 | 41 | * @see #resolveDependency(Parameter, Class, ApplicationContext)
|
43 | 42 | */
|
@@ -86,25 +85,18 @@ static boolean isAutowirable(Parameter parameter) {
|
86 | 85 | * @throws BeansException if dependency resolution failed
|
87 | 86 | * @see #isAutowirable(Parameter)
|
88 | 87 | * @see Autowired#required
|
89 |
| - * @see MethodParameterFactory#createSynthesizingMethodParameter(Parameter) |
| 88 | + * @see SynthesizingMethodParameter#forParameter(Parameter) |
90 | 89 | * @see AutowireCapableBeanFactory#resolveDependency(DependencyDescriptor, String)
|
91 | 90 | */
|
92 |
| - static Object resolveDependency(Parameter parameter, Class<?> containingClass, |
93 |
| - ApplicationContext applicationContext) { |
94 |
| - |
| 91 | + static Object resolveDependency(Parameter parameter, Class<?> containingClass, ApplicationContext applicationContext) { |
95 | 92 | boolean required = findMergedAnnotation(parameter, Autowired.class).map(Autowired::required).orElse(true);
|
96 |
| - MethodParameter methodParameter = (parameter.getDeclaringExecutable() instanceof Method |
97 |
| - ? MethodParameterFactory.createSynthesizingMethodParameter(parameter) |
98 |
| - : MethodParameterFactory.createMethodParameter(parameter)); |
| 93 | + MethodParameter methodParameter = SynthesizingMethodParameter.forParameter(parameter); |
99 | 94 | DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required);
|
100 | 95 | descriptor.setContainingClass(containingClass);
|
101 |
| - |
102 | 96 | return applicationContext.getAutowireCapableBeanFactory().resolveDependency(descriptor, null);
|
103 | 97 | }
|
104 | 98 |
|
105 |
| - private static <A extends Annotation> Optional<A> findMergedAnnotation(AnnotatedElement element, |
106 |
| - Class<A> annotationType) { |
107 |
| - |
| 99 | + private static <A extends Annotation> Optional<A> findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) { |
108 | 100 | return Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(element, annotationType));
|
109 | 101 | }
|
110 | 102 |
|
|
0 commit comments