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

Add 'organizeImports' to the cleanup settings. #3764

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions document/_java.learnMoreAboutCleanUps.md
Original file line number Diff line number Diff line change
@@ -344,3 +344,65 @@ Cleans up lambda expression wherever possible in the following ways:
```java
ArrayList::new;
```

### `organizeImports`

Performs the "Organize Imports" operation.

**Note** : Since clean ups are meant to be applied without user feedback (eg. prompts about ambiguous types), this may leave some types unresolved. To properly resolve these ambiguous types, one can do so manually (code actions, source actions), or by calling "Organize Imports" through the command palette / key binding (<kbd>shift</kbd> + <kbd>alt</kbd> + <kbd>o</kbd>).

For example:

```java
package test1;
public class A {
public void test() {
List<String> a1;
Iterator<String> a2;
Map<String, String> a3;
Set<String> a4;
JarFile a5;
StringTokenizer a6;
Path a7;
URI a8;
HttpURLConnection a9;
InputStream a10;
Field a11;
Parser a12;
}
}
```

becomes:

```java
package test1;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.jar.JarFile;

public class A {
public void test() {
List<String> a1;
Iterator<String> a2;
Map<String, String> a3;
Set<String> a4;
JarFile a5;
StringTokenizer a6;
Path a7;
URI a8;
HttpURLConnection a9;
InputStream a10;
Field a11;
Parser a12;
}
}
```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1280,7 +1280,8 @@
"lambdaExpression",
"switchExpression",
"tryWithResource",
"renameFileToType"
"renameFileToType",
"organizeImports"
]
},
"default": [