From c27ab7d4723aa10e3e98c53895f5a7be6e41d383 Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Fri, 13 Sep 2024 11:58:30 -0400 Subject: [PATCH] Add 'organizeImports' to the cleanup settings. Signed-off-by: Roland Grunberg --- document/_java.learnMoreAboutCleanUps.md | 62 ++++++++++++++++++++++++ package.json | 3 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/document/_java.learnMoreAboutCleanUps.md b/document/_java.learnMoreAboutCleanUps.md index 4aeb2923bf..a6b8e3cbd6 100644 --- a/document/_java.learnMoreAboutCleanUps.md +++ b/document/_java.learnMoreAboutCleanUps.md @@ -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 (shift + alt + o). + +For example: + +```java +package test1; +public class A { + public void test() { + List a1; + Iterator a2; + Map a3; + Set 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 a1; + Iterator a2; + Map a3; + Set a4; + JarFile a5; + StringTokenizer a6; + Path a7; + URI a8; + HttpURLConnection a9; + InputStream a10; + Field a11; + Parser a12; + } +} +``` \ No newline at end of file diff --git a/package.json b/package.json index 589f2cc163..b51d982813 100644 --- a/package.json +++ b/package.json @@ -1280,7 +1280,8 @@ "lambdaExpression", "switchExpression", "tryWithResource", - "renameFileToType" + "renameFileToType", + "organizeImports" ] }, "default": [