Repository navigation
[java] Fix #6731: Support lombok.Builder (fix UnnecessaryFullyQualifiedName false positive) - #7198
Conversation
14047df to
da2e150
Compare
|
Thanks for the review @oowekyala, that makes sense. I reworked the PR accordingly:
Tests: the #6731 cases in |
adangel
left a comment
There was a problem hiding this comment.
Thanks for the PR!
I think we should address the following points (see also the individual comments):
- Add a comment in
SymbolTableResolverexplaining why the generated builder class is added to the scope of the class's own annotations. Java scoping doesn't do this; the reason is a Lombok restriction. Since Lombok 1.18.48,@Builder(builderClassName = "Builder")must be written as@lombok.Builder. Also consider moving this block into a separate private method (e.g.addBuildersToAnnotationScope), so thatdesugarLombokMembersstays easy to read. - Fix the generated builder class name for
@Builderon methods. Lombok names it after the method's return type, not the enclosing type (e.g.Bar$FooBuilderforstatic Foo create()inBar). Please add a test for this. - Update the release notes: please remove the "New and Changed Rules" section. This is a bug fix, so the entry under "Fixed Issues" is enough.
fdec473 to
e0760e4
Compare
UnnecessaryFullyQualifiedName reported lombok.Builder when the generated builder class was named Builder. Add that static nested class to the enclosing type's symbol, as with other Lombok members, instead of special-casing the rule. The default name is <TypeName>Builder; builderClassName overrides it, and an existing nested class of that name is kept. Fixes pmd#6731
Address review feedback. Explain the Lombok annotation-scope restriction, return the synthetic builder classes that were added, and name @builder on a method after its return type (Desk$BookBuilder for static Book book()).
e0760e4 to
6a3fe12
Compare
|
Compared to main: (comment created at 2026-11-12 12:27:07+00:00 for b550479) |
Resolve the conflicts with pmd#7198, which added the (empty) builder class of lombok.Builder. Build on that implementation instead of duplicating it: - keep the builder class of pmd#7198, including builders of constructors and methods, the '*' wildcard of builderClassName and the annotation scope - add the members for @builder on a non-generic class: the methods of the builder class, builder() and toBuilder() - honor the access attribute for the builder class - a handwritten builder class gets the methods it does not declare Builders of generic classes, constructors and methods stay empty classes. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01MTr23wWTVcrESgpWPAS9iR
Describe the PR
UnnecessaryFullyQualifiedNamereports@lombok.Builderand@lombok.Builder.Defaultwhenlombok.Builderis already in scope. That is wrong whenbuilderClassNameis"Builder": Lombok generates a nested class of that name, so the simple nameBuilderno longer refers to the annotation. Since Lombok 1.18.48,@Builder(builderClassName = "Builder")is a compile error and the fully qualified annotation is required. The same clash makes@lombok.Builder.Defaultnecessary inside the type.Other builder class names are still reported.
This PR adds support for Lombok's Builder annotation.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)