Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* MIT License
*
* Copyright (c) 2026 Andreas Igel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.javahelpers.simple.builders.core.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.javahelpers.simple.builders.core.enums.OptionState;

/**
* Built-in minimal builder template annotation.
*
* <p>Generates the smallest possible fluent builder by disabling all optional features. Use this
* when you only need {@code create()}, field setters and {@code build()} without suppliers,
* consumers, varargs, collection helpers, {@code With} interface, Jackson integration or generated
* annotations.
*
* <p>This annotation is implemented purely as a {@link SimpleBuilder.Template} with every optional
* feature set to {@link OptionState#DISABLED}. Because the template is {@link Inherited},
* subclasses of an annotated type also receive a minimal builder unless explicitly excluded by
* {@link Ignore4BuilderGeneration}.
*
* <p>Example:
*
* <pre>{@code
* @SimpleMinimalBuilder
* public class PersonDto {
* private String name;
*
* public String getName() { return name; }
* public void setName(String name) { this.name = name; }
* }
* }</pre>
*
* <p>Generated builder usage:
*
* <pre>{@code
* PersonDto person = PersonDtoBuilder.create()
* .name("John")
* .build();
* }</pre>
*
* @see SimpleBuilder
* @see SimpleBuilder.Template
* @see SimpleBuilder.Options
* @see Ignore4BuilderGeneration
*/
@SimpleBuilder.Template(
options =
@SimpleBuilder.Options(
generateFieldSupplier = OptionState.DISABLED,
generateFieldConsumer = OptionState.DISABLED,
generateBuilderConsumer = OptionState.DISABLED,
generateConditionalHelper = OptionState.DISABLED,
generateVarArgsHelpers = OptionState.DISABLED,
generateStringFormatHelpers = OptionState.DISABLED,
generateAddToCollectionHelpers = OptionState.DISABLED,
generateUnboxedOptional = OptionState.DISABLED,
generateWithInterface = OptionState.DISABLED,
usingArrayListBuilder = OptionState.DISABLED,
usingArrayListBuilderWithElementBuilders = OptionState.DISABLED,
usingHashSetBuilder = OptionState.DISABLED,
usingHashSetBuilderWithElementBuilders = OptionState.DISABLED,
usingHashMapBuilder = OptionState.DISABLED,
usingGeneratedAnnotation = OptionState.DISABLED,
usingBuilderImplementationAnnotation = OptionState.DISABLED,
usingJacksonDeserializerAnnotation = OptionState.DISABLED,
generateJacksonModule = OptionState.DISABLED,
copyTypeAnnotations = OptionState.DISABLED,
implementsBuilderBase = OptionState.DISABLED,
builderSuffix = "Builder",
setterSuffix = ""))
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
@Inherited
public @interface SimpleMinimalBuilder {}
44 changes: 15 additions & 29 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ public class PersonDto {
| Need | Use |
|------|-----|
| Generate a builder for a single class/record | `@SimpleBuilder` on the class/record |
| Generate a minimal builder (no optional features) | `@SimpleMinimalBuilder` on the class/record |
| Share the same configuration across many classes | `@SimpleBuilder.Template` on a custom `@interface`, then the custom annotation on each class |

Create reusable configuration presets with custom template annotations:
Create reusable configuration presets with custom template annotations. The built-in `@SimpleMinimalBuilder` already disables every optional feature; use the following pattern only when you need a differently named or customized template:

```java
@SimpleBuilder.Template(options = @SimpleBuilder.Options(
Expand All @@ -109,7 +110,8 @@ Create reusable configuration presets with custom template annotations:
usingGeneratedAnnotation = OptionState.DISABLED,
usingBuilderImplementationAnnotation = OptionState.DISABLED,
implementsBuilderBase = OptionState.DISABLED,
usingJacksonDeserializerAnnotation = OptionState.DISABLED
usingJacksonDeserializerAnnotation = OptionState.DISABLED,
generateJacksonModule = OptionState.DISABLED
))
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
Expand Down Expand Up @@ -903,40 +905,23 @@ reported as warnings so compilation can continue.

### Minimal Builder

Generate only essential builder methods:
Use the built-in `@SimpleMinimalBuilder` template to generate only essential builder methods with a single annotation:

```java
@SimpleBuilder(
options = @SimpleBuilder.Options(
generateFieldSupplier = OptionState.DISABLED,
generateFieldConsumer = OptionState.DISABLED,
generateBuilderConsumer = OptionState.DISABLED,
generateConditionalHelper = OptionState.DISABLED,
generateVarArgsHelpers = OptionState.DISABLED,
generateStringFormatHelpers = OptionState.DISABLED,
generateAddToCollectionHelpers = OptionState.DISABLED,
generateUnboxedOptional = OptionState.DISABLED,
copyTypeAnnotations = OptionState.DISABLED,
usingArrayListBuilder = OptionState.DISABLED,
usingArrayListBuilderWithElementBuilders = OptionState.DISABLED,
usingHashSetBuilder = OptionState.DISABLED,
usingHashSetBuilderWithElementBuilders = OptionState.DISABLED,
usingHashMapBuilder = OptionState.DISABLED,
generateWithInterface = OptionState.DISABLED,
usingGeneratedAnnotation = OptionState.DISABLED,
usingBuilderImplementationAnnotation = OptionState.DISABLED,
implementsBuilderBase = OptionState.DISABLED,
usingJacksonDeserializerAnnotation = OptionState.DISABLED
)
import org.javahelpers.simple.builders.core.annotations.SimpleMinimalBuilder;

@SimpleMinimalBuilder
public class MinimalDto {
private String name;

public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
```

**Generated**: Only basic builder methods (`create()`, field setters, `build()`)
**Generated**: Only basic builder methods (`create()`, field setters, `build()`).

If you need a different name or extra customization, you can still build a custom `@SimpleBuilder.Template` with all optional features disabled.

### Internal API Builder

Expand Down Expand Up @@ -993,7 +978,7 @@ TeamDto team = TeamDtoBuilder.create()

### Minimal Builder Template

Create a reusable template for lightweight builders:
The built-in `@SimpleMinimalBuilder` is the simplest way to get a lightweight builder. If you need a differently named template or want to build your own preset, create a custom annotation meta-annotated with `@SimpleBuilder.Template`:

```java
@SimpleBuilder.Template(options = @SimpleBuilder.Options(
Expand All @@ -1015,7 +1000,8 @@ Create a reusable template for lightweight builders:
usingGeneratedAnnotation = OptionState.DISABLED,
usingBuilderImplementationAnnotation = OptionState.DISABLED,
implementsBuilderBase = OptionState.DISABLED,
usingJacksonDeserializerAnnotation = OptionState.DISABLED
usingJacksonDeserializerAnnotation = OptionState.DISABLED,
generateJacksonModule = OptionState.DISABLED
))
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
Expand Down
Loading