@@ -64,6 +64,8 @@ class VertxWebProcessor {
64
64
private static final DotName ROUTE = DotName .createSimple (Route .class .getName ());
65
65
private static final DotName ROUTES = DotName .createSimple (Route .Routes .class .getName ());
66
66
private static final DotName ROUTING_CONTEXT = DotName .createSimple (RoutingContext .class .getName ());
67
+ private static final DotName RX_ROUTING_CONTEXT = DotName
68
+ .createSimple (io .vertx .reactivex .ext .web .RoutingContext .class .getName ());
67
69
private static final DotName ROUTING_EXCHANGE = DotName .createSimple (RoutingExchange .class .getName ());
68
70
private static final String HANDLER_SUFFIX = "_RouteHandler" ;
69
71
@@ -93,13 +95,13 @@ public void validate(ValidationContext validationContext) {
93
95
List <AnnotationInstance > routes = new LinkedList <>();
94
96
AnnotationInstance routeAnnotation = annotationStore .getAnnotation (method , ROUTE );
95
97
if (routeAnnotation != null ) {
96
- validateMethodParameters (bean , method );
98
+ validateMethod (bean , method );
97
99
routes .add (routeAnnotation );
98
100
}
99
101
if (routes .isEmpty ()) {
100
102
AnnotationInstance routesAnnotation = annotationStore .getAnnotation (method , ROUTES );
101
103
if (routesAnnotation != null ) {
102
- validateMethodParameters (bean , method );
104
+ validateMethod (bean , method );
103
105
Collections .addAll (routes , routesAnnotation .value ().asNestedArray ());
104
106
}
105
107
}
@@ -169,12 +171,23 @@ public void transform(TransformationContext context) {
169
171
});
170
172
}
171
173
172
- private void validateMethodParameters (BeanInfo bean , MethodInfo method ) {
174
+ private void validateMethod (BeanInfo bean , MethodInfo method ) {
175
+ if (!method .returnType ().kind ().equals (Type .Kind .VOID )) {
176
+ throw new IllegalStateException (
177
+ String .format ("Route handler business method must return void [method: %s, bean: %s]" , method , bean ));
178
+ }
173
179
List <Type > params = method .parameters ();
174
- if (params .size () != 1
175
- || !(params .get (0 ).name ().equals (ROUTING_CONTEXT ) || params .get (0 ).name ().equals (ROUTING_EXCHANGE ))) {
180
+ boolean hasInvalidParam = true ;
181
+ if (params .size () == 1 ) {
182
+ DotName paramTypeName = params .get (0 ).name ();
183
+ if (ROUTING_CONTEXT .equals (paramTypeName ) || RX_ROUTING_CONTEXT .equals (paramTypeName )
184
+ || ROUTING_EXCHANGE .equals (paramTypeName )) {
185
+ hasInvalidParam = false ;
186
+ }
187
+ }
188
+ if (hasInvalidParam ) {
176
189
throw new IllegalStateException (String .format (
177
- "Route handler business method must accept exactly one parameter of type RoutingContext/RoutingExchange: %s [method: %s, bean:%s " ,
190
+ "Route handler business method must accept exactly one parameter of type RoutingContext/RoutingExchange: %s [method: %s, bean: %s] " ,
178
191
params , method , bean ));
179
192
}
180
193
}
@@ -223,6 +236,12 @@ private String generateHandler(BeanInfo bean, MethodInfo method, ClassOutput cla
223
236
paramHandle = invoke .getMethodParam (0 );
224
237
methodDescriptor = MethodDescriptor .ofMethod (bean .getImplClazz ().name ().toString (), method .name (), void .class ,
225
238
RoutingContext .class );
239
+ } else if (method .parameters ().get (0 ).name ().equals (RX_ROUTING_CONTEXT )) {
240
+ paramHandle = invoke .newInstance (
241
+ MethodDescriptor .ofConstructor (io .vertx .reactivex .ext .web .RoutingContext .class , RoutingContext .class ),
242
+ invoke .getMethodParam (0 ));
243
+ methodDescriptor = MethodDescriptor .ofMethod (bean .getImplClazz ().name ().toString (), method .name (), void .class ,
244
+ io .vertx .reactivex .ext .web .RoutingContext .class );
226
245
} else {
227
246
paramHandle = invoke .newInstance (MethodDescriptor .ofConstructor (RoutingExchangeImpl .class , RoutingContext .class ),
228
247
invoke .getMethodParam (0 ));
0 commit comments