gapic-generator-java
gapic-generator-java copied to clipboard
Support a return expression with a dynamic type
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
MaxBatchingDelayMsOptionis a dynamically created TypeNode. It implementsOptions.TransactionOption. I have created aClassDefinitionfor this. But I don't think there is a way to pass a reference of aClassDefinitioninto aTypeNode- For the method
maxBatchingDelayMs, the return type isOptions.TransactionOption. It would have been much easier to specify a return expression if it wasMaxBatchingDelayMsOptionbut it's supposed to beOptions.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?
Would you add the URL of your requirements doc as a "go" link in this ticket too?
Got the document.