From 266ecbe49c11ebb2dd030e091db6d127efb41c95 Mon Sep 17 00:00:00 2001 From: Dusan Balek Date: Mon, 29 Aug 2022 12:35:57 +0200 Subject: [PATCH] OrganizeImports fixed for clashing star imports. --- .../java/hints/OrganizeImportsTest.java | 23 +++++++++++++++++++ .../api/java/source/GeneratorUtilities.java | 3 +-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/OrganizeImportsTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/OrganizeImportsTest.java index 317f74db10e0..7c651dd8353b 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/OrganizeImportsTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/OrganizeImportsTest.java @@ -49,4 +49,27 @@ public void testSimple() throws Exception { " List l = new ArrayList();\n" + "}\n"); } + + public void testClashing() throws Exception { + HintTest.create() + .input("package test;\n" + + "import java.awt.*;\n" + + "import java.util.List;\n" + + "import java.util.*;\n" + + "public class Test {\n" + + " List l = new ArrayList();\n" + + " Button b;\n" + + "}\n") + .run(OrganizeImports.class) + .findWarning("2:0-2:22:verifier:MSG_OragnizeImports") + .applyFix() + .assertOutput("package test;\n" + + "import java.awt.*;\n" + + "import java.util.*;\n" + + "import java.util.List;\n" + + "public class Test {\n" + + " List l = new ArrayList();\n" + + " Button b;\n" + + "}\n"); + } } diff --git a/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java b/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java index c736797aa6c5..6b0cc4b9e77e 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java @@ -1278,9 +1278,8 @@ private CompilationUnitTree addImports(CompilationUnitTree cut, List