GH-2908: Publisher: synthesize anns for @AliasFor
Fixes https://github.com/spring-projects/spring-integration/issues/2908 * make sure the attribute is taken into account in @Header annotation * remove useless spaces according to checkstyle rules * make sure the expression attribute is taken into account as well in @Payload annotation
This commit is contained in:
committed by
Artem Bilan
parent
36c33bb5ab
commit
b069780381
@@ -44,6 +44,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Artem Bilan
|
||||
* @author Gareth Chapman
|
||||
* @author Cameron Mayfield
|
||||
* @author Chengchen Ji
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -114,7 +115,7 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
"@Payload can be used at most once on a @Publisher method, " +
|
||||
"either at method-level or on a single parameter");
|
||||
|
||||
Assert.state("".equals(AnnotationUtils.getValue(currentAnnotation)),
|
||||
Assert.state("".equals(AnnotationUtils.getValue(AnnotationUtils.synthesizeAnnotation(currentAnnotation, null))),
|
||||
"@Payload on a parameter for a @Publisher method may not contain an expression");
|
||||
|
||||
payloadExpression =
|
||||
@@ -204,8 +205,10 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getAnnotationValue(Annotation annotation, String attributeName, Class<T> expectedType) {
|
||||
T value = null;
|
||||
Object valueAsObject = (attributeName == null) ? AnnotationUtils.getValue(annotation)
|
||||
: AnnotationUtils.getValue(annotation, attributeName);
|
||||
Object valueAsObject = (attributeName == null) ?
|
||||
AnnotationUtils.getValue(AnnotationUtils.synthesizeAnnotation(annotation, null)) :
|
||||
AnnotationUtils.getValue(annotation, attributeName);
|
||||
|
||||
if (valueAsObject != null) {
|
||||
if (expectedType.isAssignableFrom(valueAsObject.getClass())) {
|
||||
value = (T) valueAsObject;
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Cameron Mayfield
|
||||
* @author Chengchen Ji
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -116,6 +117,18 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
assertThat(payloadExpression).isEqualTo("#args[0]");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void voidReturnAndParameterPayloadAnnotationWithExpression() {
|
||||
Method method = getMethod("methodWithVoidReturnAndParameterPayloadAnnotationWithExpression", String.class);
|
||||
source.getExpressionForPayload(method).getExpressionString();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void voidReturnAndParameterPayloadAnnotationWithValue() {
|
||||
Method method = getMethod("methodWithVoidReturnAndParameterPayloadAnnotationWithValue", String.class);
|
||||
source.getExpressionForPayload(method).getExpressionString();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void voidReturnAndNoPayloadAnnotation() {
|
||||
Method method = getMethod("methodWithVoidReturnAndNoPayloadAnnotation", String.class);
|
||||
@@ -182,13 +195,21 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
|
||||
@Publisher
|
||||
@Payload("testExpression2")
|
||||
public void methodWithHeaderAnnotations(String arg1, @Header("foo") String h1, @Header("bar") String h2) {
|
||||
public void methodWithHeaderAnnotations(String arg1, @Header("foo") String h1, @Header(name = "bar") String h2) {
|
||||
}
|
||||
|
||||
@Publisher
|
||||
public void methodWithVoidReturnAndParameterPayloadAnnotation(@Payload String payload) {
|
||||
}
|
||||
|
||||
@Publisher
|
||||
public void methodWithVoidReturnAndParameterPayloadAnnotationWithExpression(@Payload(expression = "foo") String payload) {
|
||||
}
|
||||
|
||||
@Publisher
|
||||
public void methodWithVoidReturnAndParameterPayloadAnnotationWithValue(@Payload("foo") String payload) {
|
||||
}
|
||||
|
||||
@Publisher
|
||||
public void methodWithVoidReturnAndNoPayloadAnnotation(String payload) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user