googleapis / googleapis/google-cloud-java

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

Open
#12,468 2 comments 0 reactions 0 assignees View on GitHub
priority: p2 type: feature request
Dominant language
Java
Stars
2.1k
Forks
1.2k
Avg merge
1d 23h
Merged PRs (30d)
154

Description

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.