Skip to content

Propagate @Deprecated (and its javadoc) from DTO, setters and constructor parameters to the generated builder #235

Description

@devin-ai-integration

Feature: propagate @Deprecated (and its javadoc) from the DTO to the generated builder

Problem

When a DTO, one of its setters, a field or a constructor parameter is marked @Deprecated, that information is currently (almost entirely) lost in the generated builder. A user of the builder gets no IDE strikethrough and no compiler warning, so it is invisible that the value should not be used anymore. The explanatory @deprecated javadoc text is not carried over either.

Current behavior

  • Only parameter-level / type-use annotations are extracted (FieldAnnotationExtractor.extractAnnotations(VariableElement, …), called from BuilderDefinitionCreator.createFieldDto), and they are applied to the parameter of the generated setter method:
    public ServiceBuilder name(@Deprecated String name) { … }
    (covered by AnnotationCopyTest.annotations_deprecatedCopied_suppressWarningsFiltered)
  • Nothing is read from the setter method element, the backing field, or the DTO type element — so @Deprecated on a setter, on a field, on a record component or on the DTO class itself does not reach the builder at all.
  • Only the @param text of the setter/constructor javadoc is extracted (JavaLangAnalyser.extractParamJavaDoc); the @deprecated javadoc tag is never picked up.

Expected behavior

  1. Deprecated field / setter / constructor parameter → every generated builder method for that field (basic setter, supplier, consumer, collection helpers, varargs, with…, …) is annotated with @Deprecated on the method itself, not just on the parameter.
  2. Deprecated DTO type → the generated builder class (and its factory methods) is annotated @Deprecated.
  3. Javadoc → the original @deprecated <text> javadoc tag is copied into the javadoc of the generated builder members, so the migration hint stays visible. If no explicit text exists, the member is still marked deprecated (annotation only).
  4. Detection should consider @Deprecated on all relevant elements of a property: constructor parameter, record component, backing field, setter method, and getter method.
  5. The generated builder itself must still compile without deprecation warnings where it legitimately calls the deprecated setter/constructor of the DTO (e.g. suppress inside build()), so users only see warnings for their own usage.

Notes / open points

  • @Deprecated(since = "…", forRemoval = true) attributes should be preserved.
  • Deprecating the whole builder class when the DTO is deprecated may be worth an explicit decision (could be noisy) — but it matches the "the DTO should not be used anymore" intent.
  • Should be covered by compile-testing cases in AnnotationCopyTest for: deprecated setter, deprecated field, deprecated record component, deprecated DTO class, and @deprecated javadoc text propagation.

Original request (DE)

Deprecated Annotationen an DTOs oder Settern oder Constructor-Parametern sollten auch Builder mit übernommen werden. Ansonsten ist bei Verwendung des Builders nicht sichtbar, dass diese eigentlich nicht mehr verwendet werden sollten. Ferner sollte dann auch der Javadoc-Eintrag übernommen werden.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions