-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ast): extend support for annotation named parameters (#1012)
This change is to extend annotation arguments support. **Before**: Only one argument that consist of a single `String` can be added to annotation description. **After**: For single unnamed parameter/description, add support for `ValueExpr` and `VariableExpr` in addition to `String`. Also allow adding multiple named parameters of type `VariableExpr`. So that annotations like below can be generated: ``` @ConditionalOnClass(VisionServiceClient.class) @ConditionalOnProperty(value = "spring.cloud.gcp.vision.enabled", matchIfMissing = true) ``` this improvement is an addition and does not affect existing usage of `setDescription(String description)`. Added tests in [JavaWriterVisitorTest.java](https://github.com/googleapis/gapic-generator-java/pull/1012/files#diff-60163f71e845b4cc97f9ccd7101646aa243fa5317a77cd326a7f61143618f62f) also shows the new feature usages. Adding a small enhancement to this PR since it's related. In addition to previous changes, I added an optional field to VariableExpr allowing Annotations. Prior to this, only annotations on ClassDefinition and MethodDefinition are supported. With this addition, I will be able to generate code like: ``` @NestedConfigurationProperty private final Credentials credentials = new Credentials(); // or @Autowired private LanguageServiceClient autoClient; ``` Field annotations are pretty common in Spring syntax, this enhancement is needed to generate Spring autoconfig code as I planned. Note: Added a todo note in `VariableExpr` only as a nice to have feature for future, it's not blocking any use cases for now. But it seems reasonable to have target info in `AnnotationNode` and apply checks on it when adding annotation nodes.
- Loading branch information
Showing
5 changed files
with
315 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.