use of cn.taketoday.core.annotation.SynthesizingMethodParameter in project today-infrastructure by TAKETODAY.
the class ParameterResolutionDelegate method resolveDependency.
/**
* Resolve the dependency for the supplied {@link Parameter} from the
* supplied {@link AutowireCapableBeanFactory}.
* <p>Provides comprehensive autowiring support for individual method parameters
* on par with Framework's dependency injection facilities for autowired fields and
* methods, including support for {@link Autowired @Autowired},
* {@link Qualifier @Qualifier}, and {@link Value @Value} with support for property
* placeholders and EL expressions in {@code @Value} declarations.
* <p>The dependency is required unless the parameter is annotated or meta-annotated
* with {@link Autowired @Autowired} with the {@link Autowired#required required}
* flag set to {@code false}.
* <p>If an explicit <em>qualifier</em> is not declared, the name of the parameter
* will be used as the qualifier for resolving ambiguities.
*
* @param parameter the parameter whose dependency should be resolved (must not be
* {@code null})
* @param parameterIndex the index of the parameter in the constructor or method
* that declares the parameter
* @param containingClass the concrete class that contains the parameter; this may
* differ from the class that declares the parameter in that it may be a subclass
* thereof, potentially substituting type variables (must not be {@code null})
* @param beanFactory the {@code AutowireCapableBeanFactory} from which to resolve
* the dependency (must not be {@code null})
* @return the resolved object, or {@code null} if none found
* @throws BeansException if dependency resolution failed
* @see #isAutowirable
* @see Autowired#required
* @see SynthesizingMethodParameter#forExecutable(Executable, int)
* @see AutowireCapableBeanFactory#resolveDependency(DependencyDescriptor, String)
*/
@Nullable
public static Object resolveDependency(Parameter parameter, int parameterIndex, Class<?> containingClass, AutowireCapableBeanFactory beanFactory) throws BeansException {
Assert.notNull(parameter, "Parameter must not be null");
Assert.notNull(containingClass, "Containing class must not be null");
Assert.notNull(beanFactory, "AutowireCapableBeanFactory must not be null");
AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex);
Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter, Autowired.class);
boolean required = (autowired == null || autowired.required());
MethodParameter methodParameter = SynthesizingMethodParameter.forExecutable(parameter.getDeclaringExecutable(), parameterIndex);
DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required);
descriptor.setContainingClass(containingClass);
return beanFactory.resolveDependency(descriptor, null);
}
use of cn.taketoday.core.annotation.SynthesizingMethodParameter in project today-framework by TAKETODAY.
the class ModelAttributeMethodProcessorTests method setup.
@BeforeEach
public void setup() throws Throwable {
this.request = new ServletRequestContext(null, new MockHttpServletRequest(), null);
this.container = new BindingContext();
request.setBindingContext(container);
this.processor = new ModelAttributeMethodProcessor(false);
Method method = ModelAttributeHandler.class.getDeclaredMethod("modelAttribute", TestBean.class, Errors.class, int.class, TestBean.class, TestBean.class, TestBean.class, TestBeanWithConstructorArgs.class);
this.paramNamedValidModelAttr = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 0));
this.paramErrors = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 1));
this.paramInt = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 2));
this.paramModelAttr = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 3));
this.paramBindingDisabledAttr = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 4));
this.paramNonSimpleType = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 5));
this.beanWithConstructorArgs = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 6));
method = getClass().getDeclaredMethod("annotatedReturnValue");
this.returnParamNamedModelAttrHandler = new HandlerMethod(this, method);
method = getClass().getDeclaredMethod("notAnnotatedReturnValue");
this.returnParamNonSimpleTypeHandler = new HandlerMethod(this, method);
}
use of cn.taketoday.core.annotation.SynthesizingMethodParameter in project today-framework by TAKETODAY.
the class CookieMethodArgumentResolversTests method setUp.
@BeforeEach
public void setUp() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
CookieParameterResolver.register(strategies, context.getBeanFactory());
ServletParameterResolvers.register(strategies, servletContext);
Method method = getClass().getMethod("params", Cookie.class, String.class, String.class);
paramNamedCookie = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 0));
paramNamedDefaultValueString = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 1));
paramString = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 2));
request = new MockHttpServletRequest();
webRequest = new ServletRequestContext(null, request, new MockHttpServletResponse());
}
use of cn.taketoday.core.annotation.SynthesizingMethodParameter in project today-framework by TAKETODAY.
the class RequestHeaderMethodArgumentResolverTests method getParameter.
@NonNull
private SynthesizingMethodParameter getParameter(Method method, int parameterIndex) {
SynthesizingMethodParameter parameter = new SynthesizingMethodParameter(method, parameterIndex);
parameter.initParameterNameDiscovery(discoverer);
return parameter;
}
use of cn.taketoday.core.annotation.SynthesizingMethodParameter in project today-framework by TAKETODAY.
the class ResolvableParameterFactory method createArray.
@Nullable
public ResolvableMethodParameter[] createArray(Method method) {
final int length = method.getParameterCount();
if (length == 0) {
return null;
}
final ResolvableMethodParameter[] ret = new ResolvableMethodParameter[length];
for (int i = 0; i < length; i++) {
MethodParameter parameter = new SynthesizingMethodParameter(method, i);
parameter.initParameterNameDiscovery(parameterNameDiscoverer);
ret[i] = createParameter(parameter);
}
return ret;
}
Aggregations