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

Better infer extracted method name based on context #2011

Closed
fbricon opened this issue Jul 2, 2021 · 2 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2670
Closed

Better infer extracted method name based on context #2011

fbricon opened this issue Jul 2, 2021 · 2 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2670

Comments

@fbricon
Copy link
Collaborator

fbricon commented Jul 2, 2021

When refactoring > extract to a method..., the default method name is extracted. In similar situations, Intellij IDEA is smarter and can propose a method name based on context.

In this exemple:

var parts = new String[]{"Hello", "Java", "16"};

// start selecting line from below
var greeting = new StringBuilder();
for(int i = 0; i < parts.length; i++) {
    var part = parts[i];
    if (i >0) {
        greeting.append(" ");
    }
    greeting.append(part);
}
// end selection including previous closing bracket
System.out.println(greeting);

In vscode-java, extraction will create:

var greeting = extracted(parts);

in IntelliJ, you'll get the choice between getStringBuilder, getBuilder, getGreeting by default.

I don't think we can propose several names in vscode-java, but it'd be nice to, at least in that case, propose getGreeting by default.

cc @maxandersen

@fbricon
Copy link
Collaborator Author

fbricon commented Jul 2, 2021

Found upstream bug opened by @maxandersen : https://bugs.eclipse.org/bugs/show_bug.cgi?id=570785

@rgrunber
Copy link
Member

@JessicaJHee , I started something with rgrunber/eclipse.jdt.ls@cc7273d . If it makes sense, you should make a PR with that and then add tests / react in ExtractMethodTest .

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

Successfully merging a pull request may close this issue.

3 participants