+
Skip to content

Use Generated Annotation on generated classes #491

@eeverman

Description

@eeverman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载