googleapis / googleapis/google-cloud-java
[sdk-platform-java] Support a return expression with a dynamic type
- Ngôn ngữ chính
- Java
- Star
- 2.1k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 154
Mô tả
I was exploring to use the java auto-generator for generating some of Cloud Spanner Java Client Library. Below is some code which I was trying to auto-generate.
```
public static Options.TransactionOption maxBatchingDelayMs(int maxBatchingDelayMs) {
return new MaxBatchingDelayMsOption(maxBatchingDelayMs);
}
static final class MaxBatchingDelayMsOption extends InternalOption
implements Options.TransactionOption {
final int maxBatchingDelayMs;
MaxBatchingDelayMsOption(int maxBatchingDelayMs) {
this.maxBatchingDelayMs = maxBatchingDelayMs;
}
}
```
I have been able to write a composer and auto-generate most of this code. The part which I am struggling with is generating the method return expression - `return new MaxBatchingDelayMsOption(maxBatchingDelayMs)` . The challenge here is
* `MaxBatchingDelayMsOption` is a dynamically created TypeNode. It implements `Options.TransactionOption`. I have created a `ClassDefinition` for this. But I don't think there is a way to pass a reference of a `ClassDefinition` into a `TypeNode`
* For the method `maxBatchingDelayMs`, the return type is `Options.TransactionOption`. It would have been much easier to specify a return expression if it was `MaxBatchingDelayMsOption` but it's supposed to be `Options.TransactionOption`. I have tried a few things but it fails the type check since the return type and return expression have a type mismatch.
Can I get some assistance on how this method can be defined? Or if this is unsupported with the framework?
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.