-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add @SimpleBuilderFor for generating builders of external types (#293) #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
igel-devin-ai
wants to merge
18
commits into
java-helpers:main
Choose a base branch
from
igel-devin-ai:devin/simple-builder-for-external-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
aecb5ae
feat: add @SimpleBuilderFor for generating builders of external types…
devin-ai-integration[bot] b9d1ac1
revert example pom surefire fix (moved to separate PR)
devin-ai-integration[bot] 341b812
refactor: address review - split round-start log lines, derive builde…
devin-ai-integration[bot] 2dd5a39
refactor: fix sonar findings - dedupe message literal, split loop exi…
devin-ai-integration[bot] b9d0ff9
refactor: extract per-element planning to reduce cognitive complexity
devin-ai-integration[bot] f49d03e
refactor: move conditional inside getPackageName call (sonar S9358)
devin-ai-integration[bot] bea5d4c
feat: allow @SimpleBuilderFor on package-info.java
devin-ai-integration[bot] e22d638
fix: keep builderUsagePackages filter ahead of generated-builder lookup
devin-ai-integration[bot] a7f82e6
refactor: address review - package-info examples, explicit declaratio…
devin-ai-integration[bot] 6ab16b2
refactor: TypeName returns and drop redundant empty-round log line
devin-ai-integration[bot] bf41a4e
refactor: group per-target state into ProcessingTarget record
devin-ai-integration[bot] 8d9fea9
refactor: move generated-builder registrations into GeneratedBuilders…
devin-ai-integration[bot] 9dc5de6
refactor: review follow-ups on naming, attribute reading, and registr…
devin-ai-integration[bot] e632b57
fix: address Sonar findings
devin-ai-integration[bot] f1a683a
refactor: follow-up on review comments
devin-ai-integration[bot] 411f5ad
refactor: address remaining review comments
devin-ai-integration[bot] ffb812a
docs: link CONFIGURATION.md sections from javadoc
devin-ai-integration[bot] 834969f
fix: rebase onto upstream main and restore example test harness
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
core/src/main/java/org/javahelpers/simple/builders/core/annotations/SimpleBuilderFor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /* | ||
| * 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.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Annotation to generate builders for types that cannot or should not be modified, such as classes | ||
| * from third-party libraries. | ||
| * | ||
| * <p>Place this annotation on a dedicated holder class or on the package itself (in {@code | ||
| * package-info.java}) and list the external types in {@link #value()}. For every listed type a | ||
| * builder is generated following the same naming and generation conventions as for {@link | ||
| * SimpleBuilder} annotated classes, without changing the target type and without runtime | ||
| * reflection. | ||
| * | ||
| * <p>The generated builder is placed in the package of the class or package carrying this | ||
| * annotation. Only members of the target type that are accessible from that package (e.g. public | ||
| * constructors and setters, or package-visible members when the holder shares the target's package) | ||
| * are used for builder generation. If no suitable construction mechanism is available, generation | ||
| * fails with a compile-time error. The target type's own annotations are not consulted - the | ||
| * explicit declaration wins, so even an {@link Ignore4BuilderGeneration} on the target does not | ||
| * suppress generation. This annotation is intentionally not {@code @Inherited}: it declares | ||
| * generation for exactly the types listed on the annotated element. | ||
| * | ||
| * <p>See also the <a | ||
| * href="https://github.com/java-helpers/simple-builders/blob/main/docs/CONFIGURATION.md#generating-builders-for-external-types"> | ||
| * Generating Builders for External Types section in CONFIGURATION.md</a>. | ||
| * | ||
| * <p>Example, declared on the package in {@code package-info.java} (generates the builder into | ||
| * {@code com.example}): | ||
| * | ||
| * <pre>{@code | ||
| * @SimpleBuilderFor(ExternalUser.class) | ||
| * package com.example; | ||
| * }</pre> | ||
| * | ||
| * <p>or on a dedicated provider class: | ||
| * | ||
| * <pre>{@code | ||
| * @SimpleBuilderFor(ExternalUser.class) | ||
| * public class ExternalBuildersProvider { | ||
| * } | ||
| * | ||
| * // Generated usage: | ||
| * ExternalUser user = ExternalUserBuilder.create() | ||
| * .name("Ada") | ||
| * .email("ada@example.com") | ||
| * .build(); | ||
| * }</pre> | ||
| * | ||
| * <p>Multiple external types can be listed in a single annotation and {@link #options()} may be | ||
| * omitted, in which case the compiler defaults apply: | ||
| * | ||
| * <pre>{@code | ||
| * @SimpleBuilderFor({ExternalUser.class, ExternalOrder.class}) | ||
| * public class ExternalBuildersProvider { | ||
| * } | ||
| * }</pre> | ||
| * | ||
| * <p>Configuration uses the existing {@link SimpleBuilder.Options} model and may be overridden via | ||
| * compiler options: | ||
| * | ||
| * <pre>{@code | ||
| * @SimpleBuilderFor( | ||
| * value = ExternalUser.class, | ||
| * options = @SimpleBuilder.Options( | ||
| * builderSuffix = "Factory" | ||
| * ) | ||
| * ) | ||
| * public class ExternalBuildersProvider { | ||
| * } | ||
| * }</pre> | ||
| * | ||
| * @see SimpleBuilder | ||
| * @see SimpleBuilder.Options | ||
| * @see Ignore4BuilderGeneration | ||
| */ | ||
| @Target({ElementType.TYPE, ElementType.PACKAGE}) | ||
| @Retention(RetentionPolicy.CLASS) | ||
| public @interface SimpleBuilderFor { | ||
|
|
||
| /** | ||
| * The types for which builders are generated. Every listed type must be resolvable on the | ||
| * classpath or in the current compilation and must be constructible through accessible Java APIs | ||
| * (e.g. an accessible constructor). At least one type is required. | ||
| * | ||
| * @return the external types to generate builders for | ||
| */ | ||
| Class<?>[] value(); | ||
|
|
||
| /** | ||
| * Configuration options for the generated builders, reusing the {@link SimpleBuilder.Options} | ||
| * model. When omitted, all members keep their {@code UNSET} default, so each option resolves as | ||
| * documented for the corresponding {@link SimpleBuilder.Options} member — falling back to the | ||
| * {@code -Asimplebuilder.*} compiler argument and then to the built-in default listed there. See | ||
| * the <a | ||
| * href="https://github.com/java-helpers/simple-builders/blob/main/docs/CONFIGURATION.md#compiler-options"> | ||
| * Compiler Options section in CONFIGURATION.md</a>. | ||
| * | ||
| * @return the configuration options, defaulting to all members {@code UNSET} | ||
| */ | ||
| SimpleBuilder.Options options() default @SimpleBuilder.Options; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.