google / auto

A collection of source code generators for Java.
Apache License 2.0
10.42k stars 1.2k forks source link

Feature request: to allow adding annotations on generated factories #1819

Closed azurvii closed 1 month ago

azurvii commented 1 month ago

Currently @AutoFactory supports implementing and extending. I suggest to add annotating, which should take a list of Class<?> (@interface to be exact, but I think java does not have a grammar to support this. Also, compiler should pick this up easily, if any class is not an annotation, so this should be no big issue). These should be annotated on the generated factories.

One use case is to cooperate with Quarkus, which requires a scope on the class to be injected. I think this could benefit other annotation processors as well.

eamonnmcmanus commented 1 month ago

Does AnnotationsToApply address your use case?

azurvii commented 1 month ago

Yes! Though it seems awkward to use. I guess it's how to accommodate annotations with values.

eamonnmcmanus commented 1 month ago

We spent a lot of time designing it. 🙂 This was the best compromise we could find between power and convenience.

azurvii commented 1 month ago

Thanks Éamonn! Sorry if I sounded negative. This is a "wow" I learn here. Got used to implementing and extending, I was expecting something similar.

Minor suggestion to put AnnotationsToApply in @see of implementing and extending to raise its visibility. Or maybe another better place. Though in the same file, the auto-complete-dependent me had not noticed this.