googleapis / googleapis/google-cloud-java

[sdk-platform-java] Support a return expression with a dynamic type

Aperta
#12,468 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
priority: p2 type: feature request
Lingua principale
Java
Stelle
2.1k
Fork
1.2k
Merge medio
1g 23h
PR unite (30g)
154

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.