Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2196f9c
Adding a testclass with expectations of the result
AndreasIgel Apr 23, 2026
4af38e4
Finalizing 1st implementation of javadoc generation
AndreasIgel Apr 28, 2026
e682566
Using exampleChainFragment for JavaDoc-Example of method and class
AndreasIgel May 5, 2026
773442f
Improving code which adds exampleCodeFragment by doing it with Method…
AndreasIgel May 5, 2026
09fc62a
Improving handling of templates in generation of example values
AndreasIgel May 5, 2026
ea59804
Adding generation of example blocks
AndreasIgel Jul 31, 2026
4906a64
Extending documentations in helper functions of builders
AndreasIgel Jul 31, 2026
7f39eff
Extending example code to be generated for non-default classes too. F…
AndreasIgel Jul 31, 2026
8f35c46
Refactoring code structure to have specific classes for builder- and …
AndreasIgel Aug 2, 2026
e4801eb
Adding source documentation in javadoc
AndreasIgel Aug 2, 2026
5ad9d79
Refactoring conflict resolution, it is done now primary in BuilderDef…
AndreasIgel Aug 2, 2026
7aafa51
Code-quality cleanup: Locale.ROOT, remove dead mapper method, dedupe …
devin-ai-integration[bot] Aug 2, 2026
66c7273
Merge upstream/main into feature/code-example
devin-ai-integration[bot] Aug 2, 2026
a5adac9
Address SonarCloud MAJOR issues: delegate duplicate getters (S4144), …
devin-ai-integration[bot] Aug 2, 2026
0f89a1a
Increase new-code coverage: remove dead example helper, test Map exam…
devin-ai-integration[bot] Aug 2, 2026
9a3e308
Remove unused testName param: use Named.of for parameterized case lab…
devin-ai-integration[bot] Aug 2, 2026
a8d224b
docs: document generated JavaDoc usage examples in Features
devin-ai-integration[bot] Aug 2, 2026
14a4efc
Encapsulate mutable model getters: unmodifiable views + explicit muta…
devin-ai-integration[bot] Aug 2, 2026
2afa116
Add Optional.of(...) JavaDoc example value; regenerate example builder
devin-ai-integration[bot] Aug 2, 2026
10f7cfd
Generalize Map example value: use example values for both key and value
devin-ai-integration[bot] Aug 2, 2026
4ea085e
docs: fix stale MethodDto references to BuilderMethodDto in MethodGen…
devin-ai-integration[bot] Aug 2, 2026
4b820fc
Simplify JavadocDto: single exampleUsageCodeBlock field instead of co…
devin-ai-integration[bot] Aug 2, 2026
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Value semantics (`equals`, `hashCode`, `toString`) and generating brand-new immu
- **Annotation Preservation**: Validation annotations are automatically copied to builder methods
- **With Interface Pattern**: Type-safe object modifications using generated With interfaces
- **Jackson Support**: Supporting Jackson deserialization via `@JsonPOJOBuilder` and optional generation of `SimpleModule`s (one per package) (both need to be enabled)
- **JavaDoc Usage Examples**: Generated builder methods include auto-generated usage examples in their JavaDoc (per-method fluent snippets plus a class-level example), so IDE tooltips show exactly how to use each builder

## Requirements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.javahelpers.simple.builders.processor.model.core.FieldDto;
import org.javahelpers.simple.builders.processor.model.method.MethodDto;
import org.javahelpers.simple.builders.processor.model.method.BuilderMethodDto;
import org.javahelpers.simple.builders.processor.model.type.TypeName;
import org.javahelpers.simple.builders.processor.model.javadoc.JavadocDto;
import org.javahelpers.simple.builders.processor.generators.MethodGenerator;
Expand Down Expand Up @@ -66,7 +66,7 @@ public boolean appliesTo(FieldDto field, TypeName dtoType, ProcessingContext con
}

@Override
public List<MethodDto> generateMethods(FieldDto field, TypeName builderType, ProcessingContext context) {
public List<BuilderMethodDto> generateMethods(FieldDto field, TypeName builderType, ProcessingContext context) {
String fieldInDto = field.getOriginalFieldName();
String fieldInBuilder = field.getFieldNameInBuilder();
String methodName = "validate" + StringUtils.capitalize(fieldInDto);
Expand All @@ -79,7 +79,7 @@ public List<MethodDto> generateMethods(FieldDto field, TypeName builderType, Pro
fieldInBuilder, fieldInBuilder, StringUtils.capitalize(fieldInDto)
);

MethodDto validationMethod = new MethodDto(methodName, builderType);
BuilderMethodDto validationMethod = new BuilderMethodDto(methodName, builderType);
validationMethod.setCode(methodBody);
validationMethod.setJavadoc(
new JavadocDto("Validates that the " + fieldInDto + " field is not null or empty.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@
* This builder provides a fluent API for creating instances of org.javahelpers.simple.builders.example.BookDto with
* method chaining and validation. Use the static {@code create()} method to obtain a new builder instance, configure
* the desired properties using the setter methods, and then call {@code build()} to create the final DTO.
*
* <h4>Example:</h4>
*
* <pre>{@code
* BookDto result = BookDtoBuilder.create()
* .author("example value")
* .available(true)
* .category('x')
* .discount(3.14f)
* .exactPrice(BigDecimal.valueOf(3.14))
* .genres(Set.of("example value"))
* .isbn("example value")
* .lastUpdated(LocalDateTime.now())
* .metadata(Map.of("example value", "example value"))
* .pages(42)
* .price(3.14)
* .publishDate(LocalDate.now())
* .publisher(PersonDtoBuilder.create().build())
* .salesCount(42L)
* .subtitle(Optional.of("example value"))
* .tags(List.of("example value"))
* .title("example value")
* .build();
* }</pre>
*/
public class BookDtoBuilder {

Expand Down Expand Up @@ -136,6 +160,12 @@ public BookDtoBuilder(BookDto instance) {
/**
* Creating a new builder for {@code org.javahelpers.simple.builders.example.BookDto}.
*
* <h4>Example:</h4>
*
* <pre>{@code
* BookDtoBuilder builder = BookDtoBuilder.create();
* }</pre>
*
* @return builder for {@code org.javahelpers.simple.builders.example.BookDto}
*/
public static BookDtoBuilder create() {
Expand All @@ -144,6 +174,14 @@ public static BookDtoBuilder create() {

/**
* Sets the value for <code>author</code>.
* <p>
* Generated from setter {@link BookDto#setAuthor(String) setAuthor(String author)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.author("example value");
* }</pre>
*
* @param author the book author to set
* @return current instance of builder
Expand All @@ -155,6 +193,14 @@ public BookDtoBuilder author(String author) {

/**
* Sets the value for <code>available</code>.
* <p>
* Generated from setter {@link BookDto#setAvailable(boolean) setAvailable(boolean available)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.available(true);
* }</pre>
*
* @param available true if available, false otherwise
* @return current instance of builder
Expand All @@ -166,6 +212,14 @@ public BookDtoBuilder available(boolean available) {

/**
* Sets the value for <code>category</code>.
* <p>
* Generated from setter {@link BookDto#setCategory(char) setCategory(char category)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.category('x');
* }</pre>
*
* @param category the category code to set
* @return current instance of builder
Expand All @@ -177,6 +231,14 @@ public BookDtoBuilder category(char category) {

/**
* Sets the value for <code>discount</code>.
* <p>
* Generated from setter {@link BookDto#setDiscount(float) setDiscount(float discount)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.discount(3.14f);
* }</pre>
*
* @param discount the discount percentage to set
* @return current instance of builder
Expand All @@ -188,6 +250,8 @@ public BookDtoBuilder discount(float discount) {

/**
* Sets the value for <code>edition</code>.
* <p>
* Generated from setter {@link BookDto#setEdition(short) setEdition(short edition)}
*
* @param edition the edition number to set
* @return current instance of builder
Expand All @@ -199,6 +263,14 @@ public BookDtoBuilder edition(short edition) {

/**
* Sets the value for <code>exactPrice</code>.
* <p>
* Generated from setter {@link BookDto#setExactPrice(BigDecimal) setExactPrice(BigDecimal exactPrice)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.exactPrice(BigDecimal.valueOf(3.14));
* }</pre>
*
* @param exactPrice the exact book price to set
* @return current instance of builder
Expand All @@ -210,6 +282,14 @@ public BookDtoBuilder exactPrice(BigDecimal exactPrice) {

/**
* Sets the value for <code>genres</code>.
* <p>
* Generated from setter {@link BookDto#setGenres(Set) setGenres(Set<String> genres)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.genres(Set.of("example value"));
* }</pre>
*
* @param genres the set of genres to set
* @return current instance of builder
Expand All @@ -221,6 +301,14 @@ public BookDtoBuilder genres(Set<String> genres) {

/**
* Sets the value for <code>isbn</code>.
* <p>
* Generated from setter {@link BookDto#setIsbn(String) setIsbn(String isbn)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.isbn("example value");
* }</pre>
*
* @param isbn the ISBN to set
* @return current instance of builder
Expand All @@ -232,6 +320,14 @@ public BookDtoBuilder isbn(String isbn) {

/**
* Sets the value for <code>lastUpdated</code>.
* <p>
* Generated from setter {@link BookDto#setLastUpdated(LocalDateTime) setLastUpdated(LocalDateTime lastUpdated)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.lastUpdated(LocalDateTime.now());
* }</pre>
*
* @param lastUpdated the last update timestamp to set
* @return current instance of builder
Expand All @@ -243,6 +339,14 @@ public BookDtoBuilder lastUpdated(LocalDateTime lastUpdated) {

/**
* Sets the value for <code>metadata</code>.
* <p>
* Generated from setter {@link BookDto#setMetadata(Map) setMetadata(Map<String, String> metadata)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.metadata(Map.of("example value", "example value"));
* }</pre>
*
* @param metadata the metadata map to set
* @return current instance of builder
Expand All @@ -254,6 +358,14 @@ public BookDtoBuilder metadata(Map<String, String> metadata) {

/**
* Sets the value for <code>pages</code>.
* <p>
* Generated from setter {@link BookDto#setPages(int) setPages(int pages)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.pages(42);
* }</pre>
*
* @param pages the page count to set
* @return current instance of builder
Expand All @@ -265,6 +377,14 @@ public BookDtoBuilder pages(int pages) {

/**
* Sets the value for <code>price</code>.
* <p>
* Generated from setter {@link BookDto#setPrice(double) setPrice(double price)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.price(3.14);
* }</pre>
*
* @param price the book price to set
* @return current instance of builder
Expand All @@ -276,6 +396,14 @@ public BookDtoBuilder price(double price) {

/**
* Sets the value for <code>publishDate</code>.
* <p>
* Generated from setter {@link BookDto#setPublishDate(LocalDate) setPublishDate(LocalDate publishDate)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.publishDate(LocalDate.now());
* }</pre>
*
* @param publishDate the publication date to set
* @return current instance of builder
Expand All @@ -287,6 +415,14 @@ public BookDtoBuilder publishDate(LocalDate publishDate) {

/**
* Sets the value for <code>publisher</code>.
* <p>
* Generated from setter {@link BookDto#setPublisher(PersonDto) setPublisher(PersonDto publisher)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.publisher(PersonDtoBuilder.create().build());
* }</pre>
*
* @param publisher the publisher to set
* @return current instance of builder
Expand All @@ -298,6 +434,8 @@ public BookDtoBuilder publisher(PersonDto publisher) {

/**
* Sets the value for <code>rating</code>.
* <p>
* Generated from setter {@link BookDto#setRating(byte) setRating(byte rating)}
*
* @param rating the book rating to set
* @return current instance of builder
Expand All @@ -309,6 +447,14 @@ public BookDtoBuilder rating(byte rating) {

/**
* Sets the value for <code>salesCount</code>.
* <p>
* Generated from setter {@link BookDto#setSalesCount(long) setSalesCount(long salesCount)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.salesCount(42L);
* }</pre>
*
* @param salesCount the sales count to set
* @return current instance of builder
Expand All @@ -320,6 +466,14 @@ public BookDtoBuilder salesCount(long salesCount) {

/**
* Sets the value for <code>subtitle</code>.
* <p>
* Generated from setter {@link BookDto#setSubtitle(Optional) setSubtitle(Optional<String> subtitle)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.subtitle(Optional.of("example value"));
* }</pre>
*
* @param subtitle an Optional containing the subtitle to set
* @return current instance of builder
Expand All @@ -331,6 +485,14 @@ public BookDtoBuilder subtitle(Optional<String> subtitle) {

/**
* Sets the value for <code>tags</code>.
* <p>
* Generated from setter {@link BookDto#setTags(List) setTags(List<String> tags)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.tags(List.of("example value"));
* }</pre>
*
* @param tags the list of tags to set
* @return current instance of builder
Expand All @@ -342,6 +504,14 @@ public BookDtoBuilder tags(List<String> tags) {

/**
* Sets the value for <code>title</code>.
* <p>
* Generated from setter {@link BookDto#setTitle(String) setTitle(String title)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.title("example value");
* }</pre>
*
* @param title the book title to set
* @return current instance of builder
Expand All @@ -353,6 +523,8 @@ public BookDtoBuilder title(String title) {

/**
* Validates that the author field is not null or empty.
* <p>
* Generated from setter {@link BookDto#setAuthor(String) setAuthor(String author)}
*
* @return this builder instance for chaining
* @throws IllegalArgumentException if author is null or empty
Expand All @@ -366,6 +538,8 @@ BookDtoBuilder validateAuthor() {

/**
* Validates that the isbn field is not null or empty.
* <p>
* Generated from setter {@link BookDto#setIsbn(String) setIsbn(String isbn)}
*
* @return this builder instance for chaining
* @throws IllegalArgumentException if isbn is null or empty
Expand All @@ -379,6 +553,8 @@ BookDtoBuilder validateIsbn() {

/**
* Validates that the title field is not null or empty.
* <p>
* Generated from setter {@link BookDto#setTitle(String) setTitle(String title)}
*
* @return this builder instance for chaining
* @throws IllegalArgumentException if title is null or empty
Expand All @@ -392,6 +568,12 @@ BookDtoBuilder validateTitle() {

/**
* Builds the configured DTO instance.
*
* <h4>Example:</h4>
*
* <pre>{@code
* BookDto result = builder.build();
* }</pre>
*/
public BookDto build() {
if (this.available.isSet() && this.available.value() == null) {
Expand Down
Loading
Loading