Putting Generated on private Trait methods

Mattias Reichel <[email protected]> Tue, 28 Oct 2025 15:25:24 +0100
Newsgroups gmane.comp.lang.groovy.user
Message-ID <CAKxq+fAP537CP1N5LvhdRgRMDd+scu1Zhm8O9Z6m84rruXn9ZQ@mail.gmail.com>
We have recently merged a PR[1] in Grails that adds the
groovy.transform.Generated annotation to all Trait methods so that
they do not screw up test coverage statistics when they are added to
implementing classes.

I noticed that the PR also added the annotation to private methods in
the Traits and I am curious if this is necessary?

According to AI:
> A private method in a Groovy Trait is trait-private: it=E2=80=99s compile=
d into the trait=E2=80=99s helper class and used only by other methods in t=
he trait. It is not added to (or visible on) the implementing class, so you=
 can=E2=80=99t call it from the class (or from other traits).

> A trait-private method is already an internal implementation detail and w=
on=E2=80=99t be added to or visible on implementing classes. Annotating it =
with @Generated doesn=E2=80=99t change semantics or visibility.

Thanks for any wisdom on this!
/Mattias

[1] https://github.com/apache/grails-core/pull/15150