Java Transpiled Builder classes to have a method or way to copy the instance
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
Description
### Describe the feature
When transpiling from typescript interfaces to java, Jsii creates builder classes for the interface to. We have places in our library where we want to take in an existing pre-built instance of the interface and be able to copy the existing state and make some overrides. Right now it seems the only way is to manually copy all of the existing stateful members of the class into a new builder.
```JsiiClassProps props;
JsiiClassProps newProps = new JsiiClassBuilder()
// call all setting methods to copy state like so .myJsiiInterfaceMember(props.getMyJsiiInterfaceMember())
.build();
```
versus something like this where the builder can just take the state of the existing inteface object as a common pattern w/ a constructor param
```JsiiClassProps props;
JsiiClassProps newProps = new JsiiClassBuilder(props)
.myJsiiInterfaceMemberToOverride(props.getMyJsiiInterfaceMemberToOverride())
.build();
```
whereas in typescript this can be easily accomplished already w/ the spread operator on instantiation
### Use Case
See description, we regularly need to perform some overrides on an existing base level instance, having to override everything using all of the base level instance member getters is tedious, verbose, and error prone.
### Proposed Solution
Have an additional constructor on the builder that takes in an existing instance of the built type T class and creates the initial state of the builder
```JsiiClassProps props;
JsiiClassProps newProps = new JsiiClassBuilder(props)
.myJsiiInterfaceMemberToOverride(props.getMyJsiiInterfaceMemberToOverride())
.build();
```
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.162.1
### Environment details (OS name and version, etc.)
MacOS
Contributor guide
Research direction
The issue names no source files or tests. Start by tracing the TypeScript-interface-to-Java builder generation and the existing generated builder construction path; compare the generated API with the proposed constructor. Done means an existing instance's state can be retained while selected values are overridden, with coverage for the generated behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- compilers, developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100