-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Exclude from a report methods annotated by "lombok/Generated" #495
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
Conversation
|
pull request for #15 |
|
@t1 first of all - thank you for your contribution! 👍 Referring to #15 (comment): "works out of the box" - is a good approach in general. However: I'm not sure that enough to exclude only annotated methods, in particular I'm thinking about https://projectlombok.org/features/Cleanup.html and maybe there are others, but can't tell for sure due to lack of tests and experience with Lombok on our side. And the message that will be delivered to community by addition of built-in exclusion for Lombok annotation might lead to a question why not all code that Lombok generates is excluded. By saying this, I'm not against such change, just want to make sure that will not be introduced something what will be hard to maintain (including answers on questions in mailing list and so on) in a long run. @marchof WDYT? P.S. commit message requires change, because #15 is a bigger story - for example also about Java 7 |
|
@Godin: You are completely right: This fixes only a subset of the code that Lombok can generate (and of course doesn't fix most of what has to be done for #15). And I must admit that I hadn't thought of this before. Let's take a look at all lombok features:
Features that add methods get the Leaving us with four Lombok features that add branches: We heavily use Lombok in our team, but we've never used When I look at our tests for code with OTOH do you have any idea of how this could be fixed? We could try to de-lombok the code ourselves, but changes in Lombok would require an update to JaCoCo. Even finding out which version of Lombok actually produced that code may not be very easy... as well as figuring out, if this code actually did come from Lombok and is not in the source code. I'd say this is not feasible. What do you think? Is it sufficient to cleanly document that only the methods and constructors annotated as |
|
@t1 first of all - thank you very much for such detailed comment! 👍
So reworded commit message to not cause automatic close of #15. Also rebased on top of master.
Filtering on a level lower than classes/methods, i.e. on a level of bytecode instructions is difficult to implement even in case of bytecode that only Java compiler generates. Each "third" comment of #15 among variety of "plus ones" and "whens" tries to explain exactly this to the users - see for example #15 (comment) or #15 (comment) Attempts to also put on a table instructions (and not just methods) generated by Lombok or JVM-based languages other than Java (Scala, Kotlin, etc) only complicate this story. And exactly from here question arises - whether it is sufficient to exclude only methods for Lombok.
Based on your description, I'm fine to give it a try. But anyway would like to hear opinion of @marchof . So @marchof WDYT? |
|
Some additional thoughts from a non-Lombok-user: Assuming that getters and setters are used by other code, they supposed to be covered indirectly, and if they are not used, then why do they exist? 😜 so can missing coverage be an indicator of unused code? if so, then maybe the fact that filter can't be disabled might be challenged. Was always wondering about this, but never had an access to experienced Lombok user, @t1 😉 Also in contrast for example to Also filtering of getters and setters generated by Lombok might cause a logical question - why handwritten getters and setters are not filtered? 😉 Aren't we vendor-neutral, @marchof ? 😆 P.S. in the lights of restrictions that modularity in Java 9 will bring, the fact that Lombok hacks into internals of compiler to do its job looks quite interesting... |
|
@Godin When code is handwritten unit tests are required. If code is generated there is no need for unit tests for the generated code (given that someone else tested the generator for us). |
@marchof maybe, however
|
|
As a Lombok user, the methods I'm eager to filter from Jacoco (and sonarqube) reports are equals() and hashcode(). They are complex and difficult to get full branch coverage. I trust the generated code and don't need to get int every nook and cranny. |
|
@Godin The new API already works for this purpose! You have all information at hand in MethodNode. I agree that there is a faster way than filtering all instructions from the generated method, but this performance issue only applies to actually filtered methods. I would prefer to integrate this feature with the new API and also move existing filters soon. I can prepare PRs for this. |
Fair enough.
@marchof I also can do this, while definitely can't review my own changes 😝 what about deal to do a review of filter for
Given a fair statement about performance and upcoming refactoring of existing filters, now this looks reasonable and convincing. @t1 will you have time and wish to work on this? |
|
This comment is "just" for motivation and encouragement purposes. You deserve some credit! @t1 thank you so much for that amazing pull-request. My dev-team and I at Otto (GmbH & Co. KG) would love to have this feature. We are lombok-powerusers. |
Godin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use new filtering API.
|
@Godin To get this contribution in I can adjust it to the new API and do the paperwork. |
|
@t1 Is there a reason for closing this PR? Any objections that we include your contributions based of the new filtering API? |
|
Sorry for not replying earlier. I was extremely busy last week. |
|
@marchof i think you are corrent. the annotation is runtime invisible. there is an option to write findbugsannotations next to the generated annotation. the findbugsannotation is runtime visible though :) |
|
@Godin If you give me a few minutes I could build a demo with gradle. |
|
@BeneStem take your time, example with Gradle will be useful! But anyway I would really love to see how to make it work with Maven too 😉 |
|
@Godin I'll do it with maven than. |
|
@Godin Ok. You can use this one: https://github.com/BeneStem/iaa-lecture. If you have any questions feel free to ask :) |
|
@BeneStem sorry, but first of all I wouldn't call it "minimalistic example" 😉 secondly and most importantly: I don't see annotation |
|
@Godin Lombok should add the annotations without setting any properties. Look at the bottom of this page: https://projectlombok.org/features/configuration.html. There is stated that you have to disable it manually if you don't want it. "Lombok normally adds @javax.annotation.Generated annotations to all generated nodes where possible. You can stop this with: lombok.addGeneratedAnnotation = false lombok.extern.findbugs.addSuppressFBWarnings = true" |
|
@BeneStem here is my point: import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@MyAnnotation
class Fun {
}
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.CLASS)
@interface MyAnnotation {
}then I can clearly see but I don't see |
|
Moreover as well as projectlombok/lombok@70f77f9 state that generation of this annotation is off by default. |
|
@Godin You are correct. I added another dependency and activated FindbugsAnnotation to see if this one is set. I will try activating the generated annotation now... |
|
@Godin I tried activating "lombok.addGeneratedAnnotation=true" the annotation. But was not able to find it in the class file... But the FB annotation is there. |
|
@BeneStem I managed to configure my own example - was using wrong name of configuration property and the correct one is |
|
@Godin Ahh, thank you. Now it is working in my example as well. Thank you and sorry for the confusion! |
|
@Godin I stated an issue at lomboks repostiory to document the property. |
No description provided.