-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Related issues/PRs:
- [java] LocalVariableCouldBeFinal false-positive with lombok.val #5079
- [java] UnusedPrivateMethod false positives with lombok.val #5369
- Fix #5369: [java] Consider that lombok.val and var are inferred #5554
- Fix #5079: [java] LocalVariableCouldBeFinal false-positive with lombok.val #5600
- [java] InvalidLogMessageFormat: Lombok @Slf4j annotation is not interpreted by PMD #5702
- [java] InvalidLogMessageFormat: false positive with lombok @Value generated methods #5787
- Support
@Data,@EqualsAndHashCode(https://projectlombok.org/features/EqualsAndHashCode)
Many rules have some form of "lombok awareness", in that they ignore some constructs if they have lombok annotations. But PMD does not really handle the desugaring that lombok performs in a way, that all rules can benefit transparently.
The main issues are:
-
lombok.valshould be treated like thevarkeyword of java 10. [java] UnusedPrivateMethod false positive when passing in lombok.val as argument #3118, [java] UseDiamondOperator false positive with var initializer #1624, [java] UseDiamondOperator false-positive with Lombok val initializer #2710 -
Type resolution in PMD 7 uses the AST as a source of symbols (methods, etc) to perform eg overload resolution. Those symbols are implicit when you use lombok. (eg
@Getterdeclares a getter method), and for now are not picked up. This means, that type resolution will be much more patchy on lombok codebases, in the current state. A nice solution, would be to generate some of the symbols that correspond to annotations (the same way we add a generated symbol for egEnum.valueOfin enum declarations). I think fully replicating the lombok desugaring is too complicated and is a non-goal. We should only generate symbols that are usable from the source language.For instance, the
@Synchronizedannotation generates a private lock field. Generating a symbol for this field is a non-goal, because it's an internal detail. It cannot mess up type resolution as it's not used in the source we're processing, only in the modified AST that lombok generates. Same thing for all annotations that just alter the AST locally, like@Cleanup.OTOH,
@Getteris something we could care about, because some dependent code may be using the getter method. If we're not aware of this, then that dependent code will be mistyped.
I think that second item may only be implemented in PMD 7. The first item could also be implemented in pmd 6 by a motivated person.