gapic-generator-java icon indicating copy to clipboard operation
gapic-generator-java copied to clipboard

Support a return expression with a dynamic type

Open arpan14 opened this issue 2 years ago • 2 comments

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?

arpan14 avatar Oct 14 '23 11:10 arpan14

Would you add the URL of your requirements doc as a "go" link in this ticket too?

suztomo avatar Oct 24 '23 13:10 suztomo

Got the document.

suztomo avatar Nov 27 '23 15:11 suztomo