diff options
author | Arne H Juul <arnej@yahooinc.com> | 2021-12-09 12:17:22 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2021-12-09 12:17:22 +0000 |
commit | 0a2b3ad8b43546c891b1a4e3e4850448fd936768 (patch) | |
tree | 61a84dbef13884108275ee0ef615ffefcb089de6 /configgen | |
parent | 800c53c580717f7f1d8bcc02d31235ac6d3673d2 (diff) |
add extra convenience method to generated builder
* takes a lambda that gets a builder to modify
* makes it possible to get rid of some boilerplate code
as you don't have to "new" the inner builder on the outside.
Diffstat (limited to 'configgen')
-rw-r--r-- | configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java | 12 | ||||
-rw-r--r-- | configgen/src/test/resources/allfeatures.reference | 36 |
2 files changed, 48 insertions, 0 deletions
diff --git a/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java b/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java index 548bd14ccb3..bbbb8676e3f 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java @@ -157,6 +157,18 @@ public class BuilderGenerator { "}\n" + // "\n" + // "/**\n" + // + " * Make a new builder and run the supplied function on it before adding it to the list\n" + // + " * @param __func lambda that modifies the given builder\n" + // + " * @return this builder\n" + // + " */\n" + // + "public Builder " + n.getName() + "(java.util.function.Consumer<" + builderType(n) + "> __func) {\n" + // + " " + builderType(n) + " __inner = new " + builderType(n) +"();\n" + // + " __func.accept(__inner);\n" + // + " " + n.getName() + ".add(__inner);\n" + // + " return this;\n" + // + "}\n" + // + "\n" + // + "/**\n" + // " * Set the given list as this builder's list of " + nodeClass(n) + " builders\n" + // " * @param __builders a list of builders\n" + // " * @return this builder\n" + // diff --git a/configgen/src/test/resources/allfeatures.reference b/configgen/src/test/resources/allfeatures.reference index e0b6176efa2..08d8aa122c9 100644 --- a/configgen/src/test/resources/allfeatures.reference +++ b/configgen/src/test/resources/allfeatures.reference @@ -582,6 +582,18 @@ public final class AllfeaturesConfig extends ConfigInstance { } /** + * Make a new builder and run the supplied function on it before adding it to the list + * @param __func lambda that modifies the given builder + * @return this builder + */ + public Builder myArray(java.util.function.Consumer<MyArray.Builder> __func) { + MyArray.Builder __inner = new MyArray.Builder(); + __func.accept(__inner); + myArray.add(__inner); + return this; + } + + /** * Set the given list as this builder's list of MyArray builders * @param __builders a list of builders * @return this builder @@ -1616,6 +1628,18 @@ public final class AllfeaturesConfig extends ConfigInstance { } /** + * Make a new builder and run the supplied function on it before adding it to the list + * @param __func lambda that modifies the given builder + * @return this builder + */ + public Builder anotherArray(java.util.function.Consumer<AnotherArray.Builder> __func) { + AnotherArray.Builder __inner = new AnotherArray.Builder(); + __func.accept(__inner); + anotherArray.add(__inner); + return this; + } + + /** * Set the given list as this builder's list of AnotherArray builders * @param __builders a list of builders * @return this builder @@ -1914,6 +1938,18 @@ public final class AllfeaturesConfig extends ConfigInstance { } /** + * Make a new builder and run the supplied function on it before adding it to the list + * @param __func lambda that modifies the given builder + * @return this builder + */ + public Builder anotherArray(java.util.function.Consumer<AnotherArray.Builder> __func) { + AnotherArray.Builder __inner = new AnotherArray.Builder(); + __func.accept(__inner); + anotherArray.add(__inner); + return this; + } + + /** * Set the given list as this builder's list of AnotherArray builders * @param __builders a list of builders * @return this builder |