Split between basic MethodParameter and SynthesizingMethodParameter
This split avoids a package tangle (between core and core.annotation) and also allows for selective use of raw annotation exposure versus synthesized annotations, with the latter primarily applicable to web and message handler processing at this point. Issue: SPR-13153
This commit is contained in:
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -258,7 +259,7 @@ public class HandlerMethod {
|
||||
/**
|
||||
* A MethodParameter with HandlerMethod-specific behavior.
|
||||
*/
|
||||
protected class HandlerMethodParameter extends MethodParameter {
|
||||
protected class HandlerMethodParameter extends SynthesizingMethodParameter {
|
||||
|
||||
public HandlerMethodParameter(int index) {
|
||||
super(HandlerMethod.this.bridgedMethod, index);
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
@@ -62,16 +63,17 @@ public class HeaderMethodArgumentResolverTests {
|
||||
|
||||
Method method = getClass().getDeclaredMethod("handleMessage",
|
||||
String.class, String.class, String.class, String.class, String.class);
|
||||
this.paramRequired = new MethodParameter(method, 0);
|
||||
this.paramNamedDefaultValueStringHeader = new MethodParameter(method, 1);
|
||||
this.paramSystemProperty = new MethodParameter(method, 2);
|
||||
this.paramNotAnnotated = new MethodParameter(method, 3);
|
||||
this.paramNativeHeader = new MethodParameter(method, 4);
|
||||
this.paramRequired = new SynthesizingMethodParameter(method, 0);
|
||||
this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 1);
|
||||
this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
|
||||
this.paramNotAnnotated = new SynthesizingMethodParameter(method, 3);
|
||||
this.paramNativeHeader = new SynthesizingMethodParameter(method, 4);
|
||||
|
||||
this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
|
||||
GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
assertTrue(resolver.supportsParameter(paramNamedDefaultValueStringHeader));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,12 +30,12 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.converter.MessageConversionException;
|
||||
import org.springframework.messaging.converter.StringMessageConverter;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -80,14 +80,14 @@ public class PayloadArgumentResolverTests {
|
||||
this.payloadMethod = PayloadArgumentResolverTests.class.getDeclaredMethod("handleMessage",
|
||||
String.class, String.class, Locale.class, String.class, String.class, String.class, String.class);
|
||||
|
||||
this.paramAnnotated = getMethodParameter(this.payloadMethod, 0);
|
||||
this.paramAnnotatedNotRequired = getMethodParameter(this.payloadMethod, 1);
|
||||
this.paramAnnotatedRequired = getMethodParameter(payloadMethod, 2);
|
||||
this.paramWithSpelExpression = getMethodParameter(payloadMethod, 3);
|
||||
this.paramValidated = getMethodParameter(this.payloadMethod, 4);
|
||||
this.paramAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 0);
|
||||
this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(this.payloadMethod, 1);
|
||||
this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
|
||||
this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
|
||||
this.paramValidated = new SynthesizingMethodParameter(this.payloadMethod, 4);
|
||||
this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
|
||||
this.paramValidatedNotAnnotated = getMethodParameter(this.payloadMethod, 5);
|
||||
this.paramNotAnnotated = getMethodParameter(this.payloadMethod, 6);
|
||||
this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 5);
|
||||
this.paramNotAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 6);
|
||||
}
|
||||
|
||||
|
||||
@@ -204,10 +204,6 @@ public class PayloadArgumentResolverTests {
|
||||
};
|
||||
}
|
||||
|
||||
private MethodParameter getMethodParameter(Method method, int index) {
|
||||
Assert.notNull(method, "Method must be set");
|
||||
return new MethodParameter(method, index);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void handleMessage(
|
||||
|
||||
@@ -16,20 +16,17 @@
|
||||
|
||||
package org.springframework.messaging.simp.annotation.support;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Principal;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.security.auth.Subject;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -37,6 +34,7 @@ import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -56,7 +54,7 @@ import org.springframework.util.MimeType;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER;
|
||||
import static org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.*;
|
||||
import static org.springframework.messaging.support.MessageHeaderAccessor.*;
|
||||
|
||||
/**
|
||||
@@ -95,7 +93,6 @@ public class SendToMethodReturnValueHandlerTests {
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
|
||||
@@ -108,31 +105,31 @@ public class SendToMethodReturnValueHandlerTests {
|
||||
this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);
|
||||
|
||||
Method method = this.getClass().getDeclaredMethod("handleNoAnnotations");
|
||||
this.noAnnotationsReturnType = new MethodParameter(method, -1);
|
||||
this.noAnnotationsReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendToDefaultDestination");
|
||||
this.sendToDefaultDestReturnType = new MethodParameter(method, -1);
|
||||
this.sendToDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendTo");
|
||||
this.sendToReturnType = new MethodParameter(method, -1);
|
||||
this.sendToReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendToWithPlaceholders");
|
||||
this.sendToWithPlaceholdersReturnType = new MethodParameter(method, -1);
|
||||
this.sendToWithPlaceholdersReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendToUser");
|
||||
this.sendToUserReturnType = new MethodParameter(method, -1);
|
||||
this.sendToUserReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendToUserSingleSession");
|
||||
this.sendToUserSingleSessionReturnType = new MethodParameter(method, -1);
|
||||
this.sendToUserSingleSessionReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendToUserDefaultDestination");
|
||||
this.sendToUserDefaultDestReturnType = new MethodParameter(method, -1);
|
||||
this.sendToUserDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendToUserDefaultDestinationSingleSession");
|
||||
this.sendToUserSingleSessionDefaultDestReturnType = new MethodParameter(method, -1);
|
||||
this.sendToUserSingleSessionDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
|
||||
method = this.getClass().getDeclaredMethod("handleAndSendToJsonView");
|
||||
this.jsonViewReturnType = new MethodParameter(method, -1);
|
||||
this.jsonViewReturnType = new SynthesizingMethodParameter(method, -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user