Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
edefee0
model: rename ResolvedBuilder to ResolvedGeneratedType with generic v…
devin-ai-integration[bot] Oct 23, 2026
36a5379
model: rename BuilderInstantiation to TypeInstantiation with generic …
devin-ai-integration[bot] Oct 23, 2026
ba859ab
analysis: rename GeneratedBuilders to GeneratedTypes
devin-ai-integration[bot] Oct 23, 2026
bc8d08f
model/analysis: move builder conventions out of genericized types
devin-ai-integration[bot] Oct 23, 2026
cc54c59
model: restore buildMethodName/buildCall names, the terminal-method c…
devin-ai-integration[bot] Oct 23, 2026
04e04cd
model: fix stale resolved-builder javadoc on TypeName setter
devin-ai-integration[bot] Oct 23, 2026
0bb30ec
model: drop getGeneratedType sugar, call sites name their resolved ge…
devin-ai-integration[bot] Oct 23, 2026
007194a
analysis/model: resolve generated types via mapping context instead o…
devin-ai-integration[bot] Oct 23, 2026
6e69dce
analysis: keep empty-constructor guard inside setEmptyConstructorInfo
devin-ai-integration[bot] Oct 23, 2026
924d00f
processing: move TypeName resolution overload to BuilderProcessingCon…
devin-ai-integration[bot] Oct 23, 2026
ae43996
processing: name builder-scope TypeName resolution resolveBuilderType
devin-ai-integration[bot] Oct 23, 2026
5bcb22c
analysis/generators: name builder-holding variables resolvedBuilder/e…
devin-ai-integration[bot] Oct 23, 2026
7f311ee
generators: pass builder resolver into example value generation inste…
devin-ai-integration[bot] Oct 23, 2026
4d32749
model/processing: restore ResolvedBuilder name, the record is builder…
devin-ai-integration[bot] Oct 23, 2026
1d5f55f
model/analysis: name builder members funcForEmptyBuilder/funcForPrefi…
devin-ai-integration[bot] Oct 23, 2026
333a28c
analysis: revert gratuitous javadoc rewording in resolveByBuilderCont…
devin-ai-integration[bot] Oct 23, 2026
9d16848
model/generators: restore 1-arg ResolvedBuilder ctor, reuse at collec…
devin-ai-integration[bot] Oct 23, 2026
8df3b41
example: regenerate builders, element-type builder examples now emitted
devin-ai-integration[bot] Oct 23, 2026
19f26f3
analysis: drop unused retrieveTypeElementIfExists leftover from conte…
devin-ai-integration[bot] Oct 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
* .sponsoren(Set.of(SponsorDtoBuilder.create().build()))
* .sponsoren(() -> Set.of(SponsorDtoBuilder.create().build()))
* .sponsoren(t -> t.add(sponsorDtoBuilder -> sponsorDtoBuilder))
* .sponsoren(SponsorDtoBuilder.create().build(), SponsorDtoBuilder.create().build())
* .sponsorenUpdate(TreeSet::new)
* .add2Sponsoren(SponsorDtoBuilder.create().build())
* .build();
* }</pre>
*/
Expand Down Expand Up @@ -195,6 +197,12 @@ public MannschaftDtoBuilder nameUpdate(UnaryOperator<String> nameUpdater) {
* <p>
* Generated from setter {@link MannschaftDto#setSponsoren(Set) setSponsoren(Set<SponsorDto> sponsoren)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.add2Sponsoren(SponsorDtoBuilder.create().build());
* }</pre>
*
* @param element the element to add
* @return current instance of builder
*/
Expand All @@ -215,6 +223,12 @@ public MannschaftDtoBuilder add2Sponsoren(SponsorDto element) {
* <p>
* Generated from setter {@link MannschaftDto#setSponsoren(Set) setSponsoren(Set<SponsorDto> sponsoren)}
*
* <h4>Example:</h4>
*
* <pre>{@code
* builder.sponsoren(SponsorDtoBuilder.create().build(), SponsorDtoBuilder.create().build());
* }</pre>
*
* @param sponsoren sponsoren
* @return current instance of builder
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import javax.lang.model.util.Elements;
import org.javahelpers.simple.builders.processor.model.type.BuilderInstantiation.StaticFactoryCall;
import org.javahelpers.simple.builders.processor.model.type.ResolvedBuilder;
import org.javahelpers.simple.builders.processor.model.type.TypeInstantiation.StaticFactoryCall;
import org.javahelpers.simple.builders.processor.model.type.TypeName;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import org.javahelpers.simple.builders.core.annotations.Ignore4BuilderGeneration;
import org.javahelpers.simple.builders.processor.model.core.BuilderConfiguration;
import org.javahelpers.simple.builders.processor.model.core.PackageScopes;
import org.javahelpers.simple.builders.processor.model.type.BuilderInstantiation;
import org.javahelpers.simple.builders.processor.model.type.ResolvedBuilder;
import org.javahelpers.simple.builders.processor.model.type.TypeInstantiation;
import org.javahelpers.simple.builders.processor.model.type.TypeName;
import org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext;

Expand Down Expand Up @@ -79,7 +79,7 @@ private record ResolutionInputs(BuilderConfiguration configuration, String build
private ResolutionInputs cachedResolutionInputs;
private PackageScopes usagePackages = PackageScopes.unscoped();
private final Map<String, Optional<ResolvedBuilder>> resolvedBuilderTypes = new HashMap<>();
private final GeneratedBuilders generatedBuilders = new GeneratedBuilders();
private final GeneratedTypes generatedBuilders = new GeneratedTypes();

/**
* Creates a new resolver for the given processing context.
Expand Down Expand Up @@ -154,13 +154,13 @@ public Optional<ResolvedBuilder> resolveUsableBuilderType(TypeElement referenced
public Optional<ResolvedBuilder> resolveGeneratedBuilder(TypeElement referencedType) {
TypeName referencedTypeName = JavaLangMapper.mapToTypeName(referencedType, context);
return generatedBuilders
.findBuilder(referencedTypeName)
.findGenerated(referencedTypeName)
.map(
builder ->
new ResolvedBuilder(
builder,
new BuilderInstantiation.StaticFactoryCall(GENERATED_FACTORY_METHOD_NAME),
new BuilderInstantiation.ConstructorCall()));
new TypeInstantiation.StaticFactoryCall(GENERATED_FACTORY_METHOD_NAME),
new TypeInstantiation.ConstructorCall()));
}

/**
Expand Down Expand Up @@ -241,16 +241,16 @@ private Optional<ResolvedBuilder> resolve(TypeElement referencedType) {
// Types whose builders are generated in the current processing round are trusted
// immediately — our own generators always produce the builder contract, so no
// classpath lookup or contract check is needed.
Optional<TypeName> generatedBuilder = generatedBuilders.findBuilder(referencedTypeName);
Optional<TypeName> generatedBuilder = generatedBuilders.findGenerated(referencedTypeName);
if (generatedBuilder.isPresent()) {
// Our generators always emit a static create() and no create(T) - the empty path uses
// the factory, the copy path the constructor
return generatedBuilder.map(
builder ->
new ResolvedBuilder(
builder,
new BuilderInstantiation.StaticFactoryCall(GENERATED_FACTORY_METHOD_NAME),
new BuilderInstantiation.ConstructorCall()));
new TypeInstantiation.StaticFactoryCall(GENERATED_FACTORY_METHOD_NAME),
new TypeInstantiation.ConstructorCall()));
}

// Reusing builders not generated in this round - nested or anchored inside the referenced
Expand Down Expand Up @@ -300,13 +300,13 @@ private Optional<ResolvedBuilder> resolveByBuilderContract(
if (builderTypeElement == null) {
return Optional.empty();
}
Optional<BuilderInstantiation> funcForEmptyBuilder =
Optional<TypeInstantiation> funcForEmptyBuilder =
resolveFuncForEmptyBuilder(builderTypeElement);
Optional<ExecutableElement> buildMethod = findBuildMethod(builderTypeElement, expectedType);
if (funcForEmptyBuilder.isEmpty() || buildMethod.isEmpty()) {
return Optional.empty();
}
Optional<BuilderInstantiation> funcForPrefilledBuilder =
Optional<TypeInstantiation> funcForPrefilledBuilder =
resolveFuncForPrefilledBuilder(builderTypeElement, expectedType);
// the builder can be created empty but offers no prefilled path: try its field functions
if (funcForPrefilledBuilder.isEmpty()
Expand Down Expand Up @@ -349,12 +349,12 @@ private Optional<ResolvedBuilder> resolveByBuilderContract(
* @param funcForEmptyBuilder how the prefilling obtains the empty builder instance
* @return the prefilling instantiation to emit, or empty when the convention covers too little
*/
private Optional<BuilderInstantiation> resolveFieldFunctionPrefill(
private Optional<TypeInstantiation> resolveFieldFunctionPrefill(
TypeElement referencedType,
TypeElement builderElement,
TypeName builderTypeName,
TypeName referencedTypeName,
BuilderInstantiation funcForEmptyBuilder) {
TypeInstantiation funcForEmptyBuilder) {
List<JavaLangAnalyser.ReadableProperty> properties =
JavaLangAnalyser.findReadableProperties(referencedType, context);
if (properties.isEmpty()) {
Expand All @@ -379,20 +379,21 @@ prefix, collectPrefilledFields(properties, fieldFunctions, prefix)))
return Optional.empty();
}
return Optional.of(
new BuilderInstantiation.PrefillCall(
new TypeInstantiation.PrefillCall(
builderTypeName,
referencedTypeName,
funcForEmptyBuilder,
best.prefix(),
best.prefilledFields()));
best.prefilledFields(),
"prefill" + builderTypeName.getClassName()));
}

/**
* A naming convention paired with the prefilled fields the builder covers under it: the
* convention the most properties follow wins.
*/
private record ConventionCoverage(
String prefix, List<BuilderInstantiation.PrefillCall.Field> prefilledFields) {}
String prefix, List<TypeInstantiation.PrefillCall.Field> prefilledFields) {}

/**
* Candidate field-function prefixes: {@code ""} (fluent {@code name(v)}) and {@code set}
Expand Down Expand Up @@ -433,7 +434,7 @@ private List<String> candidatePrefixes(
* @param prefix the naming convention to try
* @return the prefilled fields in property order
*/
private List<BuilderInstantiation.PrefillCall.Field> collectPrefilledFields(
private List<TypeInstantiation.PrefillCall.Field> collectPrefilledFields(
List<JavaLangAnalyser.ReadableProperty> properties,
List<ExecutableElement> fieldFunctions,
String prefix) {
Expand All @@ -450,9 +451,9 @@ private List<BuilderInstantiation.PrefillCall.Field> collectPrefilledFields(
* @param property the readable property to prefill
* @return the prefilled field to emit
*/
private static BuilderInstantiation.PrefillCall.Field prefilledField(
private static TypeInstantiation.PrefillCall.Field prefilledField(
JavaLangAnalyser.ReadableProperty property) {
return new BuilderInstantiation.PrefillCall.Field(property.name(), property.accessor());
return new TypeInstantiation.PrefillCall.Field(property.name(), property.accessor());
}

/**
Expand Down Expand Up @@ -487,11 +488,10 @@ private Optional<ExecutableElement> findFieldFunction(
* @param builderTypeElement the candidate builder type to inspect
* @return the instantiation to emit, or empty when the builder offers neither
*/
private Optional<BuilderInstantiation> resolveFuncForEmptyBuilder(
TypeElement builderTypeElement) {
Optional<BuilderInstantiation> func = findStaticFactoryCall(builderTypeElement, List.of());
private Optional<TypeInstantiation> resolveFuncForEmptyBuilder(TypeElement builderTypeElement) {
Optional<TypeInstantiation> func = findStaticFactoryCall(builderTypeElement, List.of());
if (func.isEmpty() && JavaLangAnalyser.hasEmptyConstructor(builderTypeElement, context)) {
func = Optional.of(new BuilderInstantiation.ConstructorCall());
func = Optional.of(new TypeInstantiation.ConstructorCall());
}
return func;
}
Expand All @@ -505,13 +505,13 @@ private Optional<BuilderInstantiation> resolveFuncForEmptyBuilder(
* @param expectedType the referenced type to prefill the builder with
* @return the instantiation to emit, or empty when the builder offers neither
*/
private Optional<BuilderInstantiation> resolveFuncForPrefilledBuilder(
private Optional<TypeInstantiation> resolveFuncForPrefilledBuilder(
TypeElement builderTypeElement, TypeName expectedType) {
Optional<BuilderInstantiation> func =
Optional<TypeInstantiation> func =
findStaticFactoryCall(builderTypeElement, List.of(expectedType));
if (func.isEmpty()
&& JavaLangAnalyser.hasConstructorAccepting(builderTypeElement, expectedType, context)) {
func = Optional.of(new BuilderInstantiation.ConstructorCall());
func = Optional.of(new TypeInstantiation.ConstructorCall());
}
return func;
}
Expand Down Expand Up @@ -604,10 +604,10 @@ private Optional<ResolvedBuilder> resolveAnchoredBuilder(
if (!context.isMemberAccessibleFromBuilderPackage(builderElement) || buildMethod.isEmpty()) {
continue;
}
BuilderInstantiation funcForEmptyBuilder =
new BuilderInstantiation.AnchorFactoryCall(
TypeInstantiation funcForEmptyBuilder =
new TypeInstantiation.NestedFactoryCall(
referencedTypeName, factory.getSimpleName().toString());
Optional<BuilderInstantiation> funcForPrefilledBuilder =
Optional<TypeInstantiation> funcForPrefilledBuilder =
resolveAnchoredPrefilledBuilder(
referencedType, referencedTypeName, builderElement, funcForEmptyBuilder);
if (funcForPrefilledBuilder.isPresent()) {
Expand Down Expand Up @@ -635,13 +635,13 @@ private Optional<ResolvedBuilder> resolveAnchoredBuilder(
* prefilling
* @return the instantiation to emit, or empty when no prefilled path exists
*/
private Optional<BuilderInstantiation> resolveAnchoredPrefilledBuilder(
private Optional<TypeInstantiation> resolveAnchoredPrefilledBuilder(
TypeElement referencedType,
TypeName referencedTypeName,
TypeElement builderElement,
BuilderInstantiation funcForEmptyBuilder) {
TypeInstantiation funcForEmptyBuilder) {
TypeName builderTypeName = JavaLangMapper.mapToTypeName(builderElement, context);
Optional<BuilderInstantiation> func =
Optional<TypeInstantiation> func =
resolveFuncForPrefilledBuilder(builderElement, referencedTypeName);
if (func.isEmpty()) {
func = resolveAnchoredStaticFactory(referencedType, referencedTypeName, builderTypeName);
Expand Down Expand Up @@ -671,7 +671,7 @@ private Optional<BuilderInstantiation> resolveAnchoredPrefilledBuilder(
* @param builderTypeName the builder type the factory must return
* @return the instantiation calling the anchored factory, or empty
*/
private Optional<BuilderInstantiation> resolveAnchoredStaticFactory(
private Optional<TypeInstantiation> resolveAnchoredStaticFactory(
TypeElement referencedType, TypeName referencedTypeName, TypeName builderTypeName) {
return JavaLangAnalyser.findMethodsStatic(
referencedType, List.of(referencedTypeName), builderTypeName, context)
Expand All @@ -681,7 +681,7 @@ private Optional<BuilderInstantiation> resolveAnchoredStaticFactory(
method -> "builder".contentEquals(method.getSimpleName()) ? 0 : 1))
.map(
method ->
new BuilderInstantiation.AnchorFactoryCall(
new TypeInstantiation.NestedFactoryCall(
referencedTypeName, method.getSimpleName().toString()));
}

Expand All @@ -695,7 +695,7 @@ private Optional<BuilderInstantiation> resolveAnchoredStaticFactory(
* @param builderTypeName the builder type the method must return
* @return the instantiation calling the instance factory, or empty
*/
private Optional<BuilderInstantiation> resolveAnchoredInstanceFactory(
private Optional<TypeInstantiation> resolveAnchoredInstanceFactory(
TypeElement referencedType, TypeName referencedTypeName, TypeName builderTypeName) {
return JavaLangAnalyser.findMethods(referencedType, List.of(), builderTypeName, context)
.stream()
Expand All @@ -705,7 +705,7 @@ private Optional<BuilderInstantiation> resolveAnchoredInstanceFactory(
method -> "toBuilder".contentEquals(method.getSimpleName()) ? 0 : 1))
.map(
method ->
new BuilderInstantiation.ValueFactoryCall(
new TypeInstantiation.ValueFactoryCall(
referencedTypeName, method.getSimpleName().toString()));
}

Expand All @@ -718,7 +718,7 @@ private Optional<BuilderInstantiation> resolveAnchoredInstanceFactory(
* @param expectedParameterTypes the parameter types the factory must accept
* @return the instantiation calling the found factory, or empty when none exists
*/
private Optional<BuilderInstantiation> findStaticFactoryCall(
private Optional<TypeInstantiation> findStaticFactoryCall(
TypeElement builderTypeElement, List<TypeName> expectedParameterTypes) {
TypeName builderTypeName = JavaLangMapper.mapToTypeName(builderTypeElement, context);
return JavaLangAnalyser.findMethodsStatic(
Expand All @@ -729,9 +729,7 @@ private Optional<BuilderInstantiation> findStaticFactoryCall(
(ExecutableElement method) ->
preferredFactoryNameRank(method.getSimpleName().toString()))
.thenComparing(method -> method.getSimpleName().toString()))
.map(
method ->
new BuilderInstantiation.StaticFactoryCall(method.getSimpleName().toString()));
.map(method -> new TypeInstantiation.StaticFactoryCall(method.getSimpleName().toString()));
}

private static int preferredFactoryNameRank(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,41 @@
import org.javahelpers.simple.builders.processor.model.type.TypeName;

/**
* Registry of the builders generated in the current annotation-processing round.
* Registry of the types generated in the current annotation-processing round.
*
* <p>Maps each target type to the {@link TypeName} of the builder being generated for it. The
* builder name is stored explicitly because it cannot always be derived from the target type:
* {@code @SimpleBuilderFor} targets generate into the holder's package (and may use the holder's
* builder suffix), so the generated builder may live in a different package than the default naming
* <p>Maps each target type to the {@link TypeName} of the type being generated for it. The
* generated name is stored explicitly because it cannot always be derived from the target type:
* targets anchored on a holder type generate into the holder's package (and may follow the holder's
* naming convention), so the generated type may live in a different package than the default naming
* convention would suggest.
*/
public final class GeneratedBuilders {
private final Map<TypeName, TypeName> buildersByTarget = new HashMap<>();
public final class GeneratedTypes {
private final Map<TypeName, TypeName> typesByTarget = new HashMap<>();

/**
* Registers the builder generated in this round for the given target type.
* Registers the type generated in this round for the given target type.
*
* @param targetType the type a builder is generated for
* @param builderType the generated builder's type name
* @param targetType the type a generated type is produced for
* @param generatedType the generated type's name
* @return {@code true} if the target was not already registered, {@code false} if a previous
* registration was replaced
*/
public boolean add(TypeName targetType, TypeName builderType) {
return buildersByTarget.put(targetType, builderType) == null;
public boolean add(TypeName targetType, TypeName generatedType) {
return typesByTarget.put(targetType, generatedType) == null;
}

/**
* Returns the builder registered for the referenced type.
* Returns the generated type registered for the referenced type.
*
* @param referencedType the referenced type a builder may exist for
* @return the generated builder's type name, or empty if the type is not generated this round
* @param referencedType the referenced type a generated type may exist for
* @return the generated type's name, or empty if the type is not generated this round
*/
public Optional<TypeName> findBuilder(TypeName referencedType) {
return Optional.ofNullable(buildersByTarget.get(referencedType));
public Optional<TypeName> findGenerated(TypeName referencedType) {
return Optional.ofNullable(typesByTarget.get(referencedType));
}

/** Drops all registrations, e.g. at the start of a new processing round. */
public void clear() {
buildersByTarget.clear();
typesByTarget.clear();
}
}
Loading
Loading