Skip to content

feat: derive String Javadoc example values from field names (#412) - #428

Merged
AndreasIgel merged 14 commits into
java-helpers:mainfrom
igel-devin-ai:feat/issue-412-field-name-examples
Nov 23, 2026
Merged

AndreasIgel merged 14 commits into
java-helpers:mainfrom
igel-devin-ai:feat/issue-412-field-name-examples

Conversation

@igel-devin-ai

@igel-devin-ai igel-devin-ai commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #412.

Generated Javadoc String examples now derive from the field name (.category("example category")) instead of the single "example value" constant — the prefixed variant from the issue's open point. Types with a resolved builder now render a builder-backed example (.sponsor(SponsorDtoBuilder.create().build())).

Changes

  • JavadocExampleValues moved to codegen-core (org.javahelpers.codegen.util, next to ImportCollector): getExampleValue(TypeName, String fieldName, Function<TypeName, Optional<String>> exampleResolver) — only the String case uses the name; nested cases (List/Set/array elements, Optional inner, Map value — not the key) pass it through; null/blank falls back to "example value"; resolveCustomExample is the terminal fallback.
  • Processor call sites use MethodGeneratorUtil.builderBackedExampleResolver(builderResolver); UpdateHelperGenerator passes context::resolveBuilderType as a method reference.
  • addExampleChainFragment* overloads and their callers in generators/field/* receive field.getOriginalFieldName() (not the builder method name, so setterPrefix is not included).
  • Static of() factories on the TypeName model: TypeNameList.of, TypeNameSet.of, TypeNameMap.of, TypeNameGeneric.of, TypeNameArray.of (Class and/or TypeName overloads); matching constructor call sites switched to them. The former constructors stay — JavaLangMapper needs them to build from the mirror's raw type, and raw/unparameterized cases can't be expressed through of.
  • Meaningful existing examples unchanged ("Hello %s", "World", sb.append("text"), Map key "key").
  • JavadocExampleValuesTest covers every supported value kind — all primitives/wrappers, common JDK types, List/Set/Map/array/Optional, empty-constructor and builder-backed — plus negative cases.
  • Committed example/generated-example-builder/ tree regenerated.

Verified: mvn clean verify passes; generated tree is in sync.

@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Parameterize over all primitives, wrappers, common JDK types, collection,
map, array, Optional, empty-constructor and builder-backed examples, plus
the unsupported-type cases.
Decouples the example-value resolver from processor types: the builder
resolver now yields the snippet String directly instead of a
ResolvedBuilder, so the class fits the generic codegen util package.
The processor call sites adapt their ResolvedBuilder resolvers via
MethodGeneratorUtil.builderBackedExample.
…t/Generic and inline builderBackedExample

- TypeNameList.of / TypeNameSet.of for single element types (TypeName and Class overloads)
- TypeNameGeneric.of for Class and TypeName varargs
- JavadocExampleValuesTest uses the factories instead of private helpers
- builderBackedExample inlined into builderBackedExampleResolver
@sonarqubecloud

Copy link
Copy Markdown

@AndreasIgel
AndreasIgel merged commit 3cb0776 into java-helpers:main Nov 23, 2026
6 of 7 checks passed
devin-ai-integration Bot added a commit to igel-devin-ai/simple-builders-devin-fork that referenced this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Derive String example values in generated Javadoc from the field name

4 participants