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

Add @Generated annotation on generated code #763

Closed
wants to merge 25 commits into from

Conversation

regisd
Copy link
Member

@regisd regisd commented May 12, 2020

@regisd regisd requested a review from lsf37 as a code owner May 12, 2020 18:38
@regisd regisd added this to the 1.9.0 milestone May 12, 2020
@regisd
Copy link
Member Author

regisd commented May 12, 2020

I bet Maven tests will not pass.

@regisd regisd added the enhancement Feature requests label May 12, 2020
@regisd regisd self-assigned this May 12, 2020
@regisd regisd marked this pull request as draft May 12, 2020 18:41
@regisd regisd marked this pull request as ready for review May 12, 2020 20:59
@regisd regisd requested a review from sarowe as a code owner May 12, 2020 20:59
https://mvnrepository.com/artifact/javax.annotation/jsr250-api indicates that this artifact has moved to javax.annotation » javax.annotation-api
@lsf37
Copy link
Member

lsf37 commented May 13, 2020

To be honest, seeing the impact it has just on our examples and testing infrastructure, I don't think any more that adding @Generated and requiring a runtime dependency for it is a good idea, at least not as a default.

Would it make sense to provide it as an option instead?

I haven't checked the placement, so this might not work, but could it actually even just go at the end of the user header code as a user-provided annotation?

@thc202
Copy link

thc202 commented May 14, 2020

One of the fall through comments has a typo:

println(" } // fall though");

(Might it explain the Error Prone errors that were still happening? #222 (comment))

Why not add the warning suppression to the generated methods (e.g. yylex)?

@lsf37
Copy link
Member

lsf37 commented May 15, 2020

Oh, well spotted! That is indeed worth investigating.

@oowekyala
Copy link

Maybe I'm missing something, but why is @SuppressWarnings("fallthrough") not enough? I don't think requiring users to add a dependency just to ignore some warnings (that they may not have even enabled) is a great idea...

@lsf37
Copy link
Member

lsf37 commented Aug 26, 2020

Why not add the warning suppression to the generated methods (e.g. yylex)?

The generated method also contains user code, for which you might want the warning.

@lsf37
Copy link
Member

lsf37 commented Aug 26, 2020

I don't think requiring users to add a dependency just to ignore some warnings (that they may not have even enabled) is a great idea...

I agree with that.

@thc202
Copy link

thc202 commented Aug 26, 2020

The generated method also contains user code, for which you might want the warning.

I thought the idea was to suppress them anyway since it is/was being added to the whole class, but that's a good reason not to.

@regisd
Copy link
Member Author

regisd commented Oct 19, 2020

The generated method also contains user code, for which you might want the warning.

I thought the idea was to suppress them anyway since it is/was being added to the whole class, but that's a good reason not to.

Yes, this PR removes the @SupressWarnings because user-header could perfectly have it too.
And it adds as @Generated annotation instead, which has the same effect for linters, but has no reason to be in user-generated code.

Even though I agree that this is impactful for existing projects, I think it is the proper fix.

@reinhapa
Copy link

reinhapa commented Dec 15, 2020

@regisd adding @Generated should be handled with care as due to the transaction of JavaEE to JakartaEE the import will change from javax.annotation.Generated to jakarta.annotation.Generated that has to taken into account though. I personally add this annotation within the .jflex file already as well as the @SuppressWarnings

@regisd
Copy link
Member Author

regisd commented Dec 17, 2020 via email

@regisd
Copy link
Member Author

regisd commented Dec 20, 2020

At the same time, the existing javax.annotation.Generated will keep existing as it was published, and error-prone will need to keep special treatment for it. I don't expect any new feature on such an annotation. Is there any drawback infusing it, if we it's deprecated?

@reinhapa
Copy link

@regisd the problem is that adding this annotation is not future prove, as the package will change in the future (a major breaking change on the JakarteEE side due to the transition from Oracle to the Eclipse Foundation, the Eclipse guys had to change the namespace). I would prefer to add this annotation by the end user itself not by the generation in the first place, so that I'm able to switch the annotation import as soon as I will need it. Also adding the annotation dependency will break my code in case I want to stay on the old namespace a longer if my customers or other dependencies require it...

@regisd
Copy link
Member Author

regisd commented Jan 2, 2021

@regisd the problem is that adding this annotation is not future prove, as the package will change in the future (a major breaking change on the JakarteEE side due to the transition from Oracle to the Eclipse Foundation, the Eclipse guys had to change the namespace).

Isn't javax.annotation.processing.Generated (which is added in Java 11) the future-proof version?

@reinhapa
Copy link

reinhapa commented Jan 3, 2021

Isn't javax.annotation.processing.Generated (which is added in Java 11) the future-proof version?

If you use javax.annotation.processing.Generated instead of javax.annotation.Generated for code used in Java 11 and later it should be fine. The only question is if the annotation could be disabled if someone will need to generate code compatible with previous versions...

@lsf37 lsf37 removed this from the 1.9.0 milestone Dec 30, 2022
@lsf37
Copy link
Member

lsf37 commented Jan 6, 2023

Closing this in favour of #1027. Users can still add their own @Generated annotation, so there is no need to force an additional runtime dependency on all users, and #764 was already fixed separately in the meantime.

@lsf37 lsf37 closed this Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests
Projects
None yet
5 participants