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

Refactor symbol doesn't work with @Builder annotation #3181

Closed
snjeza opened this issue Apr 23, 2022 · 2 comments · Fixed by #3198
Closed

Refactor symbol doesn't work with @Builder annotation #3181

snjeza opened this issue Apr 23, 2022 · 2 comments · Fixed by #3198
Milestone

Comments

@snjeza
Copy link

snjeza commented Apr 23, 2022

Steps to reproduce:

  • open the following file in Eclipse or VS Code
import lombok.Builder;
@Builder
public class Input {
	private String id;
}
  • select the id field
  • try to rename it
    You can also try to find its references.

The original issue: redhat-developer/vscode-java#2411

A potential patch:

diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index a2dd5057..6c6e50a2 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -983,7 +983,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
                                }
                                
                                if (field == null) {
-                                       FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName, 0, 0);
+                                       FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName.clone(), 0, 0);
                                        fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
                                        fd.modifiers = ClassFileConstants.AccPrivate;
                                        fd.type = copyType(bfd.type);
@@ -991,7 +991,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
                                        field = injectFieldAndMarkGenerated(job.builderType, fd);
                                }
                                if (setFlag == null && bfd.nameOfSetFlag != null) {
-                                       FieldDeclaration fd = new FieldDeclaration(bfd.nameOfSetFlag, 0, 0);
+                                       FieldDeclaration fd = new FieldDeclaration(bfd.nameOfSetFlag.clone(), 0, 0);
                                        fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
                                        fd.modifiers = ClassFileConstants.AccPrivate;
                                        fd.type = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);

  • Version: 1.8.24
  • Platform: all
@Rawi01
Copy link
Collaborator

Rawi01 commented May 5, 2022

In eclipse the rename action shows a red error message in the lower left but still works because it fallbacks to in file editing. The fix works, do you know why cloning the array helps?

@snjeza
Copy link
Author

snjeza commented May 19, 2022

do you know why cloning the array helps?

@Rawi01 JDT uses the reference equality when comparing a field name.
You may want to take a look at https://github.com/eclipse-jdt/eclipse.jdt.core/blob/master/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java#L1760

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

Successfully merging a pull request may close this issue.

3 participants