@@ -46,6 +46,7 @@ public class ServiceClientCheck extends AbstractCheck {
46
46
private static final String CLIENT = "Client" ;
47
47
private static final String IS_ASYNC = "isAsync" ;
48
48
private static final String CONTEXT = "Context" ;
49
+ private static final String REQUEST_OPTIONS = "RequestOptions" ;
49
50
50
51
private static final String RESPONSE_BRACKET = "Response<" ;
51
52
private static final String MONO_BRACKET = "Mono<" ;
@@ -78,7 +79,7 @@ public class ServiceClientCheck extends AbstractCheck {
78
79
private static final String ASYNC_CONTEXT_ERROR =
79
80
"Asynchronous method with annotation @ServiceMethod must not has ''%s'' as a method parameter." ;
80
81
private static final String SYNC_CONTEXT_ERROR =
81
- "Synchronous method with annotation @ServiceMethod must has ''%s'' as a method parameter." ;
82
+ "Synchronous method with annotation @ServiceMethod must has ''%s'' or ''%s'' as a method parameter." ;
82
83
83
84
// Add all imported classes into a map, key is the name of class and value is the full package path of class.
84
85
private final Map <String , String > simpleClassNameToQualifiedNameMap = new HashMap <>();
@@ -390,7 +391,7 @@ private void checkReturnTypeNamingPattern(DetailAST methodDefToken, String metho
390
391
}
391
392
392
393
/**
393
- * Checks the type Context should be in the right place. Context should be passed in as an argument to all public
394
+ * Checks the type Context should be in the right place. Context should be passed in as an argument to all public
394
395
* methods annotated with @ServiceMethod that return {@code Response<T>} in synchronous clients.
395
396
* Synchronous method with annotation @ServiceMethod has to have {@code Context} as a parameter.
396
397
* Asynchronous method with annotation @ServiceMethod must not has {@code Context} as a parameter.
@@ -413,17 +414,30 @@ private void checkContextInRightPlace(DetailAST methodDefToken) {
413
414
})
414
415
.isPresent ();
415
416
417
+ final boolean containsRequestOptionsParameter = TokenUtil .findFirstTokenByPredicate (parametersToken ,
418
+ parameterToken -> {
419
+ if (parameterToken .getType () != TokenTypes .PARAMETER_DEF ) {
420
+ return false ;
421
+ }
422
+ final DetailAST paramTypeIdentToken =
423
+ parameterToken .findFirstToken (TokenTypes .TYPE ).findFirstToken (TokenTypes .IDENT );
424
+ return paramTypeIdentToken != null && REQUEST_OPTIONS .equals (paramTypeIdentToken .getText ());
425
+ })
426
+ .isPresent ();
427
+
416
428
if (containsContextParameter ) {
417
429
// MONO and PagedFlux return type implies Asynchronous method
418
430
if (returnType .startsWith (MONO_BRACKET ) || returnType .startsWith (PAGED_FLUX_BRACKET )
419
431
|| returnType .startsWith (POLLER_FLUX_BRACKET )) {
420
432
log (methodDefToken , String .format (ASYNC_CONTEXT_ERROR , CONTEXT ));
421
433
}
422
434
} else {
423
- // Context should be passed in as an argument to all public methods annotated with @ServiceMethod that
424
- // return Response<T> in sync clients.
425
- if (returnType .startsWith (RESPONSE_BRACKET )) {
426
- log (methodDefToken , String .format (SYNC_CONTEXT_ERROR , CONTEXT ));
435
+ if (!containsRequestOptionsParameter ) {
436
+ // Context or RequestOptions should be passed in as an argument to all public methods
437
+ // annotated with @ServiceMethod that return Response<T> in sync clients.
438
+ if (returnType .startsWith (RESPONSE_BRACKET )) {
439
+ log (methodDefToken , String .format (SYNC_CONTEXT_ERROR , CONTEXT , REQUEST_OPTIONS ));
440
+ }
427
441
}
428
442
}
429
443
}
0 commit comments