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

Organize Imports should resolve static imports as well #1386

Closed
anthonyvdotbe opened this issue Apr 13, 2020 · 6 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#1415
Closed

Comments

@anthonyvdotbe
Copy link

When doing Organize Imports, static imports should be resolved as well by using the setting java.completion.favoriteStaticMembers.
The editor already "knows" what I want, because when I press Ctrl+. on one of the unresolved static imports, it proposes to Add static import for ... So I'd like for Organize Imports to go over any remaining syntax errors in the file, and see if it could be resolved by doing a static import of one of my configured favorites.

Environment
  • Operating System: Windows 10
  • JDK version: 14
  • Visual Studio Code version: 1.44.0
  • Java extension version: 0.59.1
Steps To Reproduce
  1. configure java.completion.favoriteStaticMembers as follows:
"java.completion.favoriteStaticMembers": ["java.util.stream.Collectors.*"]
  1. create a file App.java as below
  2. do Organize Imports
import java.util.List;

class App {
    public void foo() {
        return List.of(1).stream().collect(toList());
    }
}
Current Result

No changes are made.

Expected Result

The following import is added automatically:

import static java.util.stream.Collectors.toList;

@snjeza snjeza self-assigned this Apr 13, 2020
@snjeza
Copy link
Contributor

snjeza commented Apr 13, 2020

The issue can be reproduced in Eclipse. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=283287

@fbricon
Copy link
Collaborator

fbricon commented Apr 13, 2020

@snjeza do you think it would be possible for jdt.ls to be able to easily compute autimports based on java.completion.favoriteStaticMembers, until this is fixed upstream?

@snjeza
Copy link
Contributor

snjeza commented Apr 13, 2020

@fbricon Yes, I do. I will check.

@N-benitha
Copy link

N-benitha commented Apr 4, 2024

hey! can you help me, I want to import a static member 'of' from the package 'java.util.List' but i don't know how to insert it in "java.completion.favoriteStaticMembers": [...] . i'm using vscode

@fbricon
Copy link
Collaborator

fbricon commented Apr 4, 2024

For some reason java.util.List.* doesn't work, but java.util.List.of does:

"java.completion.favoriteStaticMembers": [
"java.util.List.of",
...
]

Screenshot 2024-04-05 at 00 34 46

@N-benitha
Copy link

I figured, thank you

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

Successfully merging a pull request may close this issue.

4 participants