use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ServletRequestMethodArgumentResolverTests method reader.
@Test
public void reader() throws Exception {
MethodParameter readerParameter = new MethodParameter(method, 6);
assertTrue("Reader not supported", resolver.supportsParameter(readerParameter));
Object result = resolver.resolveArgument(readerParameter, null, webRequest, null);
assertSame("Invalid result", webRequest.getRequest().getReader(), result);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ServletRequestMethodArgumentResolverTests method httpMethod.
@Test
public void httpMethod() throws Exception {
MethodParameter httpMethodParameter = new MethodParameter(method, 10);
assertTrue("HttpMethod not supported", resolver.supportsParameter(httpMethodParameter));
Object result = resolver.resolveArgument(httpMethodParameter, null, webRequest, null);
assertSame("Invalid result", HttpMethod.valueOf(webRequest.getRequest().getMethod()), result);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class Spr7538Tests method repro.
@Ignore
@Test
public void repro() throws Exception {
AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setTypeConverter(converter);
List<Foo> arguments = new ArrayList<>();
// !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
//arguments.add(new Foo());
List<TypeDescriptor> paramDescriptors = new ArrayList<>();
Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class);
paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0)));
List<TypeDescriptor> argumentTypes = new ArrayList<>();
argumentTypes.add(TypeDescriptor.forObject(arguments));
ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);
Object result = executor.execute(context, target, arguments);
System.out.println("Result: " + result);
}
use of org.springframework.core.MethodParameter in project java-chassis by ServiceComb.
the class ParamUtils method getParameterName.
public static String getParameterName(Method method, int paramIdx) {
MethodParameter methodParameter = new MethodParameter(method, paramIdx);
methodParameter.initParameterNameDiscovery(parameterNameDiscoverer);
String paramName = methodParameter.getParameterName();
if (paramName == null) {
// 小于jdk8的场景中,即使有debug参数,也无法对着interface获取参数名,此时直接使用arg + paramIndex来表示
paramName = "arg" + paramIdx;
}
return paramName;
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ModelFactory method findSessionAttributeArguments.
/**
* Find {@code @ModelAttribute} arguments also listed as {@code @SessionAttributes}.
*/
private List<String> findSessionAttributeArguments(HandlerMethod handlerMethod) {
List<String> result = new ArrayList<>();
for (MethodParameter parameter : handlerMethod.getMethodParameters()) {
if (parameter.hasParameterAnnotation(ModelAttribute.class)) {
String name = getNameForParameter(parameter);
Class<?> paramType = parameter.getParameterType();
if (this.sessionAttributesHandler.isHandlerSessionAttribute(name, paramType)) {
result.add(name);
}
}
}
return result;
}
Aggregations