-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rosetta): fix usage of Builders in Java (#3058)
Fixes two issues: ## Builders were never used for structs It's required to use builders to instantiate structs -- the code we generated would generate: ```java new MyStruct().setter(1).setter(2) ``` But the actual required syntax is ```java MyStruct.builder().setter(1).setter(2).build(); ``` This was caused because there's a confusion: the structs jsii generates have a builder. *However*, we also support declaring classes and structs *inline* in the example, and to not muck up the example too much we don't generate builders for those. Since it's probably desirable to show the definition of some constructs (like stacks) and some props types in examples, we can't get rid of that capability. So instead, check if the struct/class we're referencing actually comes from jsii or not, and use a builder if it does. ## Classes never use the combined class+struct builder Classes with a struct argument can be instantiated in two ways: ```java new MyClass(1, 2, MyStruct.builder() .setter(1) .setter(2)) .build()); ``` As well as: ``` MyClass.Builder.create(1, 2) .setter(1) .setter(2) .build(); ``` Prefer the second style as it's less noisy. Relates to #2984. This PR also switches off the `consistent-return` eslint warning, as it hurts more than helps when we have TypeScript available. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information
Showing
19 changed files
with
247 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.