From 1dff81a0e0841f15a6ba805e022eb668e07335b4 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Sun, 22 Apr 2018 23:43:13 +0200 Subject: @SuperBuilder documentation for website --- .../features/experimental/SuperBuilder.html | 69 ++++++++++++++++++++++ website/templates/features/experimental/index.html | 4 ++ 2 files changed, 73 insertions(+) create mode 100644 website/templates/features/experimental/SuperBuilder.html diff --git a/website/templates/features/experimental/SuperBuilder.html b/website/templates/features/experimental/SuperBuilder.html new file mode 100644 index 00000000..a1e8cb4d --- /dev/null +++ b/website/templates/features/experimental/SuperBuilder.html @@ -0,0 +1,69 @@ +<#import "_features.html" as f> + +<@f.scaffold title="@SuperBuilder" logline="Bob now knows his ancestors: Builders with fields from superclasses, too. "> + <@f.history> +

+ @SuperBuilder was introduced as experimental feature in lombok v0.16.21. +

+ + + <@f.overview> +

+ The @SuperBuilder annotation produces complex builder APIs for your classes. + In contrast to @Builder, @SuperBuilder also works with fields from superclasses. + However, it only works for types, and cannot be customized by providing a partial builder implementation. + Most importantly, it requires that all superclasses also have the @SuperBuilder annotation. +

+ @SuperBuilder lets you automatically produce the code required to have your class be instantiable with code such as:
+ Person.builder().name("Adam Savage").city("San Francisco").job("Mythbusters").job("Unchained Reaction").build(); +

+ @SuperBuilder can generate so-called 'singular' methods for collection parameters/fields. For details, see the @Singular documentation in @Builder. +

+ As lombok has no access to the fields of superclasses when generating the builder code, the methods for setting those superclass fields can only be in the builder of the superclass. + Therefore, a @SuperBuilder must extend the @SuperBuilder of the superclass in order to include those methods. + Furthermore, the generated builder code heavily relies on generics to avoid class casting when using the builder. + @SuperBuilder generates a private constructor on the class that takes a builder instances as a parameter. This constructor sets the fields of the new instance to the values from the builder. +

+ To ensure type-safety, @SuperBuilder generates two inner builder classes for each annotated class, one abstract and one concrete class named FoobarBuilder and FoobarBuilderImpl (where Foobar is the name of the annotated class). +

+ The configurable aspects of builder are: +

+ Example usage where all options are changed from their defaults:
+ @SuperBuilder(buildMethodName = "execute", builderMethodName = "helloWorld")
+

+ + + <@f.snippets name="Builder" /> + + <@f.confKeys> +
+ lombok.builder.flagUsage = [warning | error] (default: not set) +
+ Lombok will flag any usage of @SuperBuilder as a warning or error if configured. +
+ lombok.singular.useGuava = [true | false] (default: false) +
+ If true, lombok will use guava's ImmutableXxx builders and types to implement java.util collection interfaces, instead of creating implementations based on Collections.unmodifiableXxx. You must ensure that guava is actually available on the classpath and buildpath if you use this setting. Guava is used automatically if your field/parameter has one of the guava ImmutableXxx types. +
+ lombok.singular.auto = [true | false] (default: true) +
+ If true (which is the default), lombok automatically tries to singularize your identifier name by assuming that it is a common english plural. If false, you must always explicitly specify the singular name, and lombok will generate an error if you don't (useful if you write your code in a language other than english). +
+ + + <@f.smallPrint> +

+ @Singular support for java.util.NavigableMap/Set only works if you are compiling with JDK1.8 or higher. +

+ The sorted collections (java.util: SortedSet, NavigableSet, SortedMap, NavigableMap and guava: ImmutableSortedSet, ImmutableSortedMap) require that the type argument of the collection has natural order (implements java.util.Comparable). There is no way to pass an explicit Comparator to use in the builder. +

+ An ArrayList is used to store added elements as call methods of a @Singular marked field, if the target collection is from the java.util package, even if the collection is a set or map. Because lombok ensures that generated collections are compacted, a new backing instance of a set or map must be constructed anyway, and storing the data as an ArrayList during the build process is more efficient that storing it as a map or set. This behaviour is not externally visible, an implementation detail of the current implementation of the java.util recipes for @Singular. +

+ + diff --git a/website/templates/features/experimental/index.html b/website/templates/features/experimental/index.html index 21e8fceb..309303a0 100644 --- a/website/templates/features/experimental/index.html +++ b/website/templates/features/experimental/index.html @@ -62,6 +62,10 @@ <@main.feature title="@Helper" href="Helper"> With a little help from my friends... Helper methods for java. + + <@main.feature title="@SuperBuilder" href="SuperBuilder"> + Bob now knows his ancestors: Builders with fields from superclasses, too. + <@f.confKeys> -- cgit