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

Allow custom annotations on generated class files #116

Open
Serranya opened this issue Jul 22, 2019 · 4 comments
Open

Allow custom annotations on generated class files #116

Serranya opened this issue Jul 22, 2019 · 4 comments

Comments

@Serranya
Copy link
Contributor

Serranya commented Jul 22, 2019

I am using jacoco to measure the test coverage in my projects.

Jacoco excludes classes from analysis that have a @Generated annotation with a retention of at least CLASS. The package of the annotation does not matter. Just the name and the retention.

I suggest that we add the possibility to annotate classes generated by rocker like this.

I see the following three options:

Rocker provides its own annotation
Create an @com.fizzed.rocker.Generated annotation and add that to all generated classes.
The user already has to include a rocker runtime dependency. Alternatively rocker could emit the source for the annotation as part of it's source generation.

Rocker uses an established annotation
Rocker could provide support for some established @Generated annotations. AFAIK there are none. Rocker could also try some fancy classpath scanning and search for @Generated annotations.

Rocker provides a facillity to let the user provide its own Annotation(s)
Rocker could provide the user with an option to let them specify (a list) of annotations to add. This way each project could provide its own @Generated annotation or reuse a third party @Generated annotation if they so desire.

@jjlauer and others,
what do you think? I would be willing to work on a PR. Which option do you prefer?

Edit:
I tried to add my own @Generated annotation via post-processing. Sadly the template model does not seem to expose the possibility to add annotations.

@Serranya
Copy link
Contributor Author

I just noticed that I did not write which solution I prefer.

I would be in favor Solution 1 (Rocker provides its own annotation) where Rocker provides the annotation in its runtime.

@bendem
Copy link
Contributor

bendem commented Aug 1, 2019

The @javax.annotation.Generated option was added a while ago and subsequently removed because it is part of a broken jigsaw module. If you wanted to add it back (not using the javax annotation but a custom rocker one), you would add it here:

tab(w, indent).append("@SuppressWarnings(\"unused\")")

I'm sure a PR would be accepted if you opened it.

@jjlauer
Copy link
Member

jjlauer commented Aug 1, 2019 via email

@Serranya
Copy link
Contributor Author

Serranya commented Aug 1, 2019

@bendem @javax.annotation.Generated is not what I am looking for. The annotation needs at least a retention of CLASS so that jacoco can pick it up.

@jjlauer great. I will prepare a PR. I agree about making the annotation optional.

jjlauer added a commit that referenced this issue Sep 10, 2019
Mark generated classes as generated #116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants