Skip to content

Commit

Permalink
Add 'organizeImports' to the cleanup settings.
Browse files Browse the repository at this point in the history
Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Sep 13, 2024
1 parent 8923a98 commit c27ab7d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
62 changes: 62 additions & 0 deletions document/_java.learnMoreAboutCleanUps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -1280,7 +1280,8 @@
"lambdaExpression",
"switchExpression",
"tryWithResource",
"renameFileToType"
"renameFileToType",
"organizeImports"
]
},
"default": [
Expand Down

0 comments on commit c27ab7d

Please sign in to comment.