-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Emit @Generated("...")
with a link back to the generator on all top-level classes
#924
Comments
It's a tough problem, for sure. One problem with anything automatic here is how we gain access to the "who" of the generator. Each file spec is a value type, so there's no central factory or authority which represents all files in the compilation/generation unit to which we can register the "who". The library can also be used both from within an annotation processor but also standalone in a JVM tool or IntelliJ plugin to produce code making it harder to automatically infer anything. We could maybe stack walk up to the processor subtype for annotation processors, to then class containing the main method for the standalone tool, but I have no idea how reliable that would be and no idea what to do for IntelliJ plugins which have lots of entry points. A final hiccup about doing something automatically is that the I'm not sure if you've tried anything else yet, but there's definitely other places to potentially intercept this problem and trying to help fix it:
I'm sure there's others I'm not thinking of. Definitely open to other suggestions here, but I'm not seeing how we could easily do this automatically while also being so general-purpose as a tool. If we wanted to do something in JavaPoet, the best I can think of is registering an var file = FileSpec.builder(..)
.generatedTypeAnnotation(..)
.addType(..)
.build() You would still have to deny-list |
Very often it's hard to trace back from generated code to the codegen that produced it. At Google, codegens very often make up the "long tail" of any migration, so being able to easily identify where the code is being generated is hugely important. Thus, we're trying to enforce that all generated code is tagged with
@Generated
(specifically,javax.annotation.processing.Generated
), and includes a reference back to the generator that emitted it.Is it possible to have javapoet do this automatically for top-level classes?
The text was updated successfully, but these errors were encountered: