googleapis / googleapis/google-cloud-java

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

Offen
#12,468 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
priority: p2 type: feature request
Vorherrschende Sprache
Java
Sterne
2.1k
Forks
1.2k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
154

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.