Spring Framework MethodParameter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MethodParameter class.

This code example shows how to use the following methods:getParameterName, getParameterType
 
	/** 
	 * Obtain the named value for the given method parameter. 
	 */ 
	private NamedValueInfo getNamedValueInfo(MethodParameter parameter) {
		NamedValueInfo namedValueInfo = this.namedValueInfoCache.get(parameter);
		if (namedValueInfo == null) {
			namedValueInfo = createNamedValueInfo(parameter);
			namedValueInfo = updateNamedValueInfo(parameter, namedValueInfo);
			this.namedValueInfoCache.put(parameter, namedValueInfo);
		} 
		return namedValueInfo;
	} 
 
	/** 
	 * Create the {@link NamedValueInfo} object for the given method parameter. Implementations typically 
	 * retrieve the method annotation by means of {@link MethodParameter#getParameterAnnotation(Class)}. 
	 * @param parameter the method parameter 
	 * @return the named value information 
	 */ 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
	// SPR-8983 
 
	public void servletResponseNoMavContainer() throws Exception { 
		MethodParameter servletResponseParameter = new MethodParameter(method, 0); 
		assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter)); 
 
		Object result = resolver.resolveArgument(servletResponseParameter, null, webRequest, null); 
		assertSame("Invalid result", servletResponse, result); 
	} 
 
	@Test 
	public void outputStream() throws Exception { 
		MethodParameter outputStreamParameter = new MethodParameter(method, 1); 
 
		assertTrue("OutputStream not supported", resolver.supportsParameter(outputStreamParameter)); 
 
		Object result = resolver.resolveArgument(outputStreamParameter, mavContainer, webRequest, null); 
		assertSame("Invalid result", servletResponse.getOutputStream(), result); 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getGenericParameterType, getMethod, getParameterName, getParameterType
			return new HttpEntity<Object>(body, inputMessage.getHeaders());
		} 
	} 
 
	private Type getHttpEntityType(MethodParameter parameter) {
		Assert.isAssignable(HttpEntity.class, parameter.getParameterType());
		Type parameterType = parameter.getGenericParameterType();
		if (parameterType instanceof ParameterizedType) {
			ParameterizedType type = (ParameterizedType) parameterType;
			if (type.getActualTypeArguments().length != 1) {
				throw new IllegalArgumentException("Expected single generic parameter on '" +
						parameter.getParameterName() + "' in method " + parameter.getMethod());
			} 
			return type.getActualTypeArguments()[0];
		} 
		else if (parameterType instanceof Class) {
			return Object.class;
		} 
		throw new IllegalArgumentException("HttpEntity parameter '" + parameter.getParameterName() +
				"' in method " + parameter.getMethod() + " is not parameterized");

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		resolvers.add(new RequestParamMethodArgumentResolver(true));
 
		Method method = ClassUtils.getMethod(this.getClass(), "handleRequest", String.class, String.class, String.class);
 
		CompositeUriComponentsContributor contributor = new CompositeUriComponentsContributor(resolvers);
		assertTrue(contributor.supportsParameter(new MethodParameter(method, 0)));
		assertTrue(contributor.supportsParameter(new MethodParameter(method, 1)));
		assertFalse(contributor.supportsParameter(new MethodParameter(method, 2)));
	} 
 
 
	@SuppressWarnings("unused") 
	public void handleRequest(@RequestParam String p1, String p2, @RequestHeader String h) {
	} 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
	@Test
	public void resolvePayloadTypeExactType() throws Exception {
		Message<Integer> message = MessageBuilder.withPayload(123).build();
		MethodParameter parameter = new MethodParameter(this.method, 1);
 
		assertTrue("Parameter '" + parameter + "' should be supported", this.resolver.supportsParameter(parameter));
		assertSame(message, this.resolver.resolveArgument(parameter, message));
	} 
 
	@Test
	public void resolvePayloadTypeSubClass() throws Exception {
		Message<Integer> message = MessageBuilder.withPayload(123).build();
		MethodParameter parameter = new MethodParameter(this.method, 2);
 
		assertTrue("Parameter '" + parameter + "' should be supported", this.resolver.supportsParameter(parameter));
		assertSame(message, this.resolver.resolveArgument(parameter, message));
	} 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMethod, getParameterType
	 */ 
	@Override 
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
 
		Class<?> paramType = parameter.getParameterType();
		Object result = this.adaptee.resolveArgument(parameter, webRequest);
		if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
			throw new IllegalStateException(
					"Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
					"resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
					"]. Consider declaring the argument type in a less specific fashion."); 
		} 
		return result;
	} 
 
 
	/** 
	 * Required for access to NativeWebRequest in {@link #supportsParameter}. 
	 */ 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMethodAnnotation
	} 
 
 
	@Override 
	public boolean supportsReturnType(MethodParameter returnType) {
		return (returnType.getMethodAnnotation(SubscribeMapping.class) != null &&
				returnType.getMethodAnnotation(SendTo.class) == null &&
				returnType.getMethodAnnotation(SendToUser.class) == null);
	} 
 
	@Override 
	public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception {
		if (returnValue == null) {
			return; 
		} 
 
		MessageHeaders headers = message.getHeaders();
		String destination = SimpMessageHeaderAccessor.getDestination(headers);
		String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
		String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConstructor, getContainingClass, getDeclaringClass, getMethod, getParameterIndex
	 * eagerly resolving potential target beans for type matching 
	 */ 
	public DependencyDescriptor(MethodParameter methodParameter, boolean required, boolean eager) {
		Assert.notNull(methodParameter, "MethodParameter must not be null");
		this.methodParameter = methodParameter;
		this.declaringClass = methodParameter.getDeclaringClass();
		this.containingClass = methodParameter.getContainingClass();
		if (this.methodParameter.getMethod() != null) {
			this.methodName = methodParameter.getMethod().getName();
			this.parameterTypes = methodParameter.getMethod().getParameterTypes();
		} 
		else { 
			this.parameterTypes = methodParameter.getConstructor().getParameterTypes();
		} 
		this.parameterIndex = methodParameter.getParameterIndex();
		this.required = required;
		this.eager = eager;
	} 
 
	/** 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getParameterType
This code example shows how to use the following methods:
		this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); 
	} 
 
	@Test 
	public void supportsReturnType() throws Exception { 
		assertTrue(this.handler.supportsReturnType(createReturnValueParam("view"))); 
	} 
 
	@Test 
	public void returnView() throws Exception { 
		InternalResourceView view = new InternalResourceView("testView"); 
		this.handler.handleReturnValue(view, createReturnValueParam("view"), this.mavContainer, this.webRequest); 
 
		assertSame(view, this.mavContainer.getView()); 
	} 
 
	@Test 
	public void returnViewRedirect() throws Exception { 
		RedirectView redirectView = new RedirectView("testView"); 
		ModelMap redirectModel = new RedirectAttributesModelMap(); 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework MethodParameter Methods: