Skip to content

Derive String example values in generated Javadoc from the field name #412

Description

@igel-devin-ai

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 include setterPrefix (e.g. withName).
  • The addExampleChainFragment* helpers in MethodGeneratorUtil and their callers in generators/field/* (plus UpdateHelperGenerator, which calls getExampleValue directly) 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, DefaultValueTest and 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.

Activity

  1. added
    enhancement
    on Nov 16, 2026
  2. added this to the v0.7.0 milestone on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions