Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Generated Annotation on generated classes #491

Closed
eeverman opened this issue May 31, 2021 · 1 comment
Closed

Use Generated Annotation on generated classes #491

eeverman opened this issue May 31, 2021 · 1 comment
Labels
bug JDK Version Support Support new or multiple JDKs

Comments

@eeverman
Copy link
Owner

eeverman commented May 31, 2021

Describe the bug
Currently the AndHowCompileProcessor does not generate code using the @Generated annotation. The template used for that is here - Its noted but commented out.

AndHow also generates warnings in IntelliJ that it has source files in target directories - perhaps the lack of the @Generated annotation is why?

A complication is the JDK8 uses javax.annotation.Generated while JDK9 and newer uses javax.annotation.processing.Generated. JDK9 & 10 seem to still include javax.annotation.Generated in the java.xml.ws.annotation module, but it disappears in JDK11.

To Reproduce
The annotation is not used, so its clearly not as generated code was intended to be.
If you compile a project in IntelliJ using AndHow, it will complain.

Additional context
To fix, I think the annotation processor needs to detect the target JVM version:
ProcessingEnv.getSourceVersion()
and out put the correct annotation based on that.

One key detail here: Both Generated annotations have Retention on `SOURCE' meaning that the annotation is only present in the source file and is removed by the compiler - It is not present at all at run time. So, as long as the generated class can compile, it will be OK at runtime.

It seems likely that the Generated annotation must be on the class path at compile time, even if it is ignored, however. Thus, it makes sense to determine which annotation to use based on the actual runtime version (which determines which Generated implementation is present), rather than the target version.

@eeverman
Copy link
Owner Author

eeverman commented Jun 2, 2021

'Fixed' this with merge request #494.
The fix adds the Generated annotation, but IntelliJ still generates warnings about the Output directory.
There is discussion of the IntelliJ issue here: https://youtrack.jetbrains.com/issue/IDEA-159676
I asked for help - Perhaps someone will reply.

@eeverman eeverman closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug JDK Version Support Support new or multiple JDKs
Projects
None yet
Development

No branches or pull requests

1 participant