googleapis / googleapis/google-cloud-java

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

Abierto
#12,468 2 comentarios 0 reacciones 0 asignados Ver en GitHub
priority: p2 type: feature request
Lenguaje dominante
Java
Estrellas
2.1k
Forks
1.2k
Merge medio
1 d 23 h
PR fusionados (30 d)
154

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.