|
| 1 | +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 |
| 2 | +index aed6e6110c..1c081994d8 100644 |
| 3 | +--- a/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java |
| 4 | ++++ b/java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java |
| 5 | +@@ -1276,7 +1276,7 @@ public final class GeneratorUtilities { |
| 6 | + // check for possible name clashes originating from adding the package imports |
| 7 | + Set<Element> explicitNamedImports = new HashSet<Element>(); |
| 8 | + for (Element element : elementsToImport) { |
| 9 | +- if (element.getKind().isClass() || element.getKind().isInterface()) { |
| 10 | ++ if (element.getEnclosingElement() != pkg && (element.getKind().isClass() || element.getKind().isInterface())) { |
| 11 | + for (Symbol sym : importScope.getSymbolsByName((com.sun.tools.javac.util.Name)element.getSimpleName())) { |
| 12 | + if (sym.getKind().isClass() || sym.getKind().isInterface()) { |
| 13 | + if (sym != element) { |
| 14 | +diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/GeneratorUtilitiesTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/GeneratorUtilitiesTest.java |
| 15 | +index 90d0261c19..3f13dde797 100644 |
| 16 | +--- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/GeneratorUtilitiesTest.java |
| 17 | ++++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/GeneratorUtilitiesTest.java |
| 18 | +@@ -583,6 +583,18 @@ public class GeneratorUtilitiesTest extends NbTestCase { |
| 19 | + }, false); |
| 20 | + } |
| 21 | + |
| 22 | ++ public void testAddImports14() throws Exception { |
| 23 | ++ performTest("test/Process.java", "package test;\nimport java.util.Collections;\npublic class Process {\npublic static void main(String... args) {\n" + |
| 24 | ++ "Collections.singleton(Process.class).forEach(System.out::println);\n}\n}", "1.5", new AddImportsTask("test.Process"), new Validator() { |
| 25 | ++ public void validate(CompilationInfo info) { |
| 26 | ++ assertEquals(0, info.getDiagnostics().size()); |
| 27 | ++ List<? extends ImportTree> imports = info.getCompilationUnit().getImports(); |
| 28 | ++ assertEquals(1, imports.size()); |
| 29 | ++ assertEquals("java.util.Collections", imports.get(0).getQualifiedIdentifier().toString()); |
| 30 | ++ } |
| 31 | ++ }, false); |
| 32 | ++ } |
| 33 | ++ |
| 34 | + public void testAddImportsIncrementallyWithStatic_JIRA3019() throws Exception { |
| 35 | + JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true; |
| 36 | + performTest("package test;\npublic class Test { public static final String CONST = null; }\n", "11", new AddImportsTask(true, "test.Test.CONST", "java.util.List"), new Validator() { |
0 commit comments