diff options
Diffstat (limited to 'website/templates/features/experimental/SuperBuilder.html')
-rw-r--r-- | website/templates/features/experimental/SuperBuilder.html | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/website/templates/features/experimental/SuperBuilder.html b/website/templates/features/experimental/SuperBuilder.html index 8189a254..26f0a949 100644 --- a/website/templates/features/experimental/SuperBuilder.html +++ b/website/templates/features/experimental/SuperBuilder.html @@ -4,6 +4,8 @@ <@f.history> <p> <code>@SuperBuilder</code> was introduced as experimental feature in lombok v1.18.2. + </p><p> + <code>@SuperBuilder</code>'s <code>toBuilder</code> feature and limited support for customization was added with lombok v1.18.4. </p> </@f.history> @@ -11,7 +13,7 @@ <p> The <code>@SuperBuilder</code> annotation produces complex builder APIs for your classes. In contrast to <a href="/features/Builder"><code>@Builder</code></a>, <code>@SuperBuilder</code> also works with fields from superclasses. - However, it only works for types, and cannot be customized by providing a partial builder implementation. + However, it only works for types, and customization possibilities are limited. Most importantly, it requires that <em>all superclasses</em> also have the <code>@SuperBuilder</code> annotation. </p><p> <code>@SuperBuilder</code> lets you automatically produce the code required to have your class be instantiable with code such as:<br /> @@ -23,18 +25,25 @@ </p><p> <code>@SuperBuilder</code> is not compatible with <code>@Builder</code>. </p><p> + You can use <code>@SuperBuilder(toBuilder = true)</code> to also generate an instance method in your class called <code>toBuilder()</code>; it creates a new builder that starts out with all the values of this instance. You can put the <code>@Builder.ObtainVia</code> annotation on the fields to indicate alternative means by which the value for that field/parameter is obtained from this instance. For example, you can specify a method to be invoked: <code>@Builder.ObtainVia(method = "calculateFoo")</code>. + </p><p> To ensure type-safety, <code>@SuperBuilder</code> generates two inner builder classes for each annotated class, one abstract and one concrete class named <code><em>Foobar</em>Builder</code> and <code><em>Foobar</em>BuilderImpl</code> (where <em>Foobar</em> is the name of the annotated class). </p><p> + Customizing the code generated by <code>@SuperBuilder</code> is limited to adding new methods or annotations to the builder classes, and providing custom implementations of <code>builder()</code> and <code>build()</code>. + You have to make sure that the builder class declaration headers match those that would have been generated by lombok. Due to the heavy generics usage, we strongly advice to copy the builder class definition header from the uncustomized delomboked code. + </p><p> The configurable aspects of builder are: <ul> <li> The <em>build()</em> method's name (default: <code>"build"</code>) </li><li> The <em>builder()</em> method's name (default: <code>"builder"</code>) + </li><li> + If you want <code>toBuilder()</code> (default: no) </li> </ul> Example usage where all options are changed from their defaults:<br /> - <code>@SuperBuilder(buildMethodName = "execute", builderMethodName = "helloWorld")</code><br /> + <code>@SuperBuilder(buildMethodName = "execute", builderMethodName = "helloWorld", toBuilder = true)</code><br /> </p> </@f.overview> |