Repository navigation
Labels
enhancementNew feature or capability that did not exist before
Milestone
Description
Problem
Generated Javadoc examples use the same String value for every field, regardless of what the field means:
* .name("example value")
* .category("example value")
* .category(() -> "example value")
* builder.category("example value").categoryUpdate(String::trim);The value comes from one constant, STRING_EXAMPLE = "\"example value\"", in JavadocExampleValues. getExampleValue(TypeName) only knows the type, not the field. The committed example builders contain 101 such lines (e.g. ProductWithDefaultsBuilder).
Proposal
Base String example values on the field name so that examples match the field, e.g. .category("example category").
- Add an overload
JavadocExampleValues.getExampleValue(TypeName, String fieldName). Only the String case uses the name; all other types keep their current examples. - Pass the name through the nested cases (List, Set, array, Optional, Map value), e.g.
List<String> tags→List.of("example tags"). - Use the field's original name (
FieldDto.getOriginalFieldName()), not the builder method name, which may includesetterPrefix(e.g.withName). - The
addExampleChainFragment*helpers inMethodGeneratorUtiland their callers ingenerators/field/*(plusUpdateHelperGenerator, which callsgetExampleValuedirectly) receive the field name. - Keep
"example value"as the fallback when no field name is available. - Leave examples that are already meaningful unchanged:
"Hello %s", "World"(StringFormatHelperGenerator),sb.append("text")(StringBuilderConsumerGenerator), and the Map key"key"(VarArgsHelperGenerator).
Open point: format
For fields title and salesCategory:
| Variant | title |
salesCategory |
|---|---|---|
| Plain field name | "title" |
"salesCategory" |
| Prefixed | "example title" |
"example salesCategory" |
Prefixed, split into words (StringUtils.splitByCharacterTypeCamelCase) |
"example title" |
"example sales category" |
Notes
- Tests asserting generated Javadoc with
"example value"need updating (BuilderProcessorTest,DefaultValueTestand others). - Regenerate the committed
example/generated-example-builder/tree (mvn -pl example clean compile) or the CI check for out-of-date generated builders fails.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or capability that did not exist before
Activity
feat: derive String Javadoc example values from field names (#412) (#428