Java Code Examples for org.springframework.core.MethodParameter#forParameter()

The following examples show how to use org.springframework.core.MethodParameter#forParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringMvcContract.java    From spring-cloud-openfeign with Apache License 2.0 6 votes vote down vote up
private static TypeDescriptor createTypeDescriptor(Method method, int paramIndex) {
	Parameter parameter = method.getParameters()[paramIndex];
	MethodParameter methodParameter = MethodParameter.forParameter(parameter);
	TypeDescriptor typeDescriptor = new TypeDescriptor(methodParameter);

	// Feign applies the Param.Expander to each element of an Iterable, so in those
	// cases we need to provide a TypeDescriptor of the element.
	if (typeDescriptor.isAssignableTo(ITERABLE_TYPE_DESCRIPTOR)) {
		TypeDescriptor elementTypeDescriptor = getElementTypeDescriptor(
				typeDescriptor);

		checkState(elementTypeDescriptor != null,
				"Could not resolve element type of Iterable type %s. Not declared?",
				typeDescriptor);

		typeDescriptor = elementTypeDescriptor;
	}
	return typeDescriptor;
}
 
Example 2
Source File: AnyOsFileValueProviderTest.java    From ssh-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
void testSupport() throws Exception {
    AnyOsFileValueProvider providerForAll = new AnyOsFileValueProvider(true);

    Method method = TestCommand.class.getDeclaredMethod("test", File.class, File.class, String.class);

    MethodParameter paramFileWithProvider = MethodParameter.forParameter(method.getParameters()[0]);
    MethodParameter paramWithoutProvider = MethodParameter.forParameter(method.getParameters()[1]);
    MethodParameter paramNotFile = MethodParameter.forParameter(method.getParameters()[2]);

    assertTrue(providerForAll.supports(paramFileWithProvider, null));
    assertTrue(providerForAll.supports(paramWithoutProvider, null));
    assertFalse(providerForAll.supports(paramNotFile, null));

    AnyOsFileValueProvider providerForDeclaredOnly = new AnyOsFileValueProvider(false);
    assertTrue(providerForDeclaredOnly.supports(paramFileWithProvider, null));
    assertFalse(providerForDeclaredOnly.supports(paramWithoutProvider, null));
    assertFalse(providerForDeclaredOnly.supports(paramNotFile, null));
}