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

Using the "Extract as a local variable (replacing all occurrences)" feature changes only one to a variable #3860

Open
khpark0203 opened this issue Nov 15, 2024 · 9 comments

Comments

@khpark0203
Copy link

khpark0203 commented Nov 15, 2024

There seems to be no difference between the functionality of "Extract as a local variable" and the functionality of "Extract as a local variable (replacing all occurrences)."
If you use this feature in a common way as a variable, only one selected location will be changed.
I hope all the places written in common will be changed collectively.
I love vscode, but I hope this feature works well in intelij works well in vscode java as well.

  • before select extract menu
    Image

  • after select extract menu
    Image

@rgrunber
Copy link
Member

I have seen the behaviour you're referring to just trying things out on a simple examples, but when I reverse engineered what you posted in the screenshots, it does seem to work as expected :

Screencast.from.2024-11-15.11-28-52.mp4

There might be some cases that aren't being properly handled so I'll have to look deeper.

@khpark0203
Copy link
Author

It’s really amazing.
I also confirmed that my other code for testing does not work.
Is it irrelevant to JDK's version? I'm using version 21.

2024-11-18.000435.mp4

@snjeza
Copy link
Contributor

snjeza commented Nov 17, 2024

This is an upstream Eclipse jdt.ui/Lombok issue.
I can reproduce it in Eclipse, too.

Test class

package com.example;
import lombok.AllArgsConstructor;
import lombok.Data;
public class Main {
    public void test() {
        Person p = new Person(10, "abc");
        System.out.println(p.getAge() + p.getName());
        System.out.println(p.getAge() + p.getName());
        System.out.println(p.getAge() + p.getName());
    }
    @Data
    @AllArgsConstructor
    class Person {
        private Integer age;
        private String name;
    }
}
inline.mp4

Related jdt ui code: https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/2886912fd00e7d4f0dc50af8ff17cbde0007a382/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/corext/refactoring/util/SideEffectChecker.java#L160-L169

@khpark0203
Copy link
Author

Oh thank you!! As a result of the test, this is what happens when converting classes with @getter from Lombok.

When implementing Getter methods directly, the entire variable is well transformed.

Can you modify this so that it can work the same even if you have a Getter in Lombok?

@snjeza
Copy link
Contributor

snjeza commented Nov 18, 2024

@khpark0203 Could you create a new Lombok issue? - https://github.com/projectlombok/lombok/issues/new/

@khpark0203
Copy link
Author

khpark0203 commented Nov 18, 2024

@snjeza, I posted the issue on the GitHub you told me about. projectlombok/lombok#3783

@khpark0203
Copy link
Author

@rgrunber I found the cause of this issue. I would appreciate it if you could help me solve it. (Lombok @getter Issue)

@rgrunber
Copy link
Member

Is there some piece of information that Lombok should provide that is lacking for JDT to do this correctly ? Why is Lombok to blame here ?

@snjeza
Copy link
Contributor

snjeza commented Nov 19, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants