Skip to content

Commit

Permalink
Custom CheckStyle: Batch 2, Rule #5 and #10; Batch 3, Rule #1 and #6 (A…
Browse files Browse the repository at this point in the history
…zure#4712)

Batch 2

Rule # 5
Service client methods: All methods that are in a class annotated with @ServiceClient, where the method has a @ServiceMethod annotation, should follow these rules:

Methods names should follow a common vocabulary. Refer to Java spec for this naming pattern https://azure.github.io/azure-sdk/java_design.html.
Method names imply certain rules around expected return type - these should all be validated.
Methods should not have 'Async' added to their method name.
Return types of async and sync clients should be as per guidelines: [this check will be ignored for now since I am still struggling on how to get the Reflection working in the code-quality-check]
Return type for async collection should be of type ? extends PagedFlux
Return type for async single value should be of type ? extends Mono
Return type for sync collection should be of type ? extends PagedIterable
Return type for sync single value should be of type ? extends Response
Rule # 10
'withResponse' naming pattern: All methods annotated with @ServiceMethod that return a Response (or Mono) must have their method name end with 'withResponse'. If the service method does not return a Response or Mono, it must not end with 'withResponse'.

Batch 3

Rule # 1
Context in all the right places: Context should be passed in as an argument to all public methods annotated with @ServiceMethod that return Response in sync clients.

Only in the sync case: E.g. we want this: Public Response getFooWithResponse(int x, int y, Context c)
In the async case, we should check to ensure we have no service methods that take Context!
Rule # 6
Async client should have async = true property set in @ServiceClient annotation

To validate this, if the class has @ServiceClient annotation and if the classname AsyncClient, verify that the async property of @ServiceClient annotation is set to true.
Similarly, if the class has @ServiceClient annotation and if the classname is Client, verify that the async property of @ServiceClient annotation is set to false
Change class Context to be final
  • Loading branch information
mssfang authored Aug 28, 2019
1 parent b7bf03b commit 66fd3cd
Show file tree
Hide file tree
Showing 6 changed files with 529 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ private boolean isFluentMethod(DetailAST methodDefToken) {
final DetailAST modifiersToken = methodDefToken.findFirstToken(TokenTypes.MODIFIERS);
// If no @Fluent annotated with this class, return false
return TokenUtil.findFirstTokenByPredicate(modifiersToken,
annotationToken -> annotationToken.getType() == TokenTypes.ANNOTATION
&& TokenUtil.findFirstTokenByPredicate(annotationToken,
identToken -> identToken.getType() == TokenTypes.IDENT &&
"Fluent".equals(identToken.getText())).isPresent())
annotationToken -> annotationToken.getType() == TokenTypes.ANNOTATION
&& TokenUtil.findFirstTokenByPredicate(annotationToken,
identToken -> identToken.getType() == TokenTypes.IDENT
&& "Fluent".equals(identToken.getText())).isPresent())
.isPresent();
}
}
Loading

0 comments on commit 66fd3cd

Please sign in to comment.