From e34bc30bd7fa6e80ea2199ce8d7238d1dd8b1eec Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 16 Aug 2016 18:52:04 +0300 Subject: [PATCH] Exclude alias imported names from all-under imported packages when determining whether a type has been imported for completion. #KT-13447 Fixed --- .../testData/weighers/basic/ImportedOrder.Data1.kt | 1 + .../testData/weighers/basic/ImportedOrder.kt | 4 ++++ .../kotlin/idea/core/ImportableFqNameClassifier.kt | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/idea/idea-completion/testData/weighers/basic/ImportedOrder.Data1.kt b/idea/idea-completion/testData/weighers/basic/ImportedOrder.Data1.kt index a5c89e8d385..20366d889bf 100644 --- a/idea/idea-completion/testData/weighers/basic/ImportedOrder.Data1.kt +++ b/idea/idea-completion/testData/weighers/basic/ImportedOrder.Data1.kt @@ -2,3 +2,4 @@ package ppp1 class MyClass1 class MyClass2 +class MyClass7 \ No newline at end of file diff --git a/idea/idea-completion/testData/weighers/basic/ImportedOrder.kt b/idea/idea-completion/testData/weighers/basic/ImportedOrder.kt index 7edde684ebf..46b43f060f2 100644 --- a/idea/idea-completion/testData/weighers/basic/ImportedOrder.kt +++ b/idea/idea-completion/testData/weighers/basic/ImportedOrder.kt @@ -1,5 +1,6 @@ import ppp1.* import ppp3.MyClass6 +import ppp1.MyClass7 as AnotherClass7 val v = My @@ -22,3 +23,6 @@ val v = My /* not imported */ // ORDER: MyClass4 + +/* not imported */ +// ORDER: MyClass7 diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ImportableFqNameClassifier.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ImportableFqNameClassifier.kt index 772b89a036d..22efb8e9f33 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ImportableFqNameClassifier.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ImportableFqNameClassifier.kt @@ -29,6 +29,7 @@ class ImportableFqNameClassifier(private val file: KtFile) { private val preciseImports = HashSet() private val preciseImportPackages = HashSet() private val allUnderImports = HashSet() + private val excludedImports = HashSet() init { for (import in file.importDirectives) { @@ -37,9 +38,12 @@ class ImportableFqNameClassifier(private val file: KtFile) { if (importPath.isAllUnder) { allUnderImports.add(fqName) } - else { + else if (!importPath.hasAlias()) { preciseImports.add(fqName) preciseImportPackages.add(fqName.parent()) + } else { + excludedImports.add(fqName) + // TODO: support aliased imports in completion } } } @@ -84,7 +88,7 @@ class ImportableFqNameClassifier(private val file: KtFile) { } private fun isImportedWithPreciseImport(name: FqName) = name in preciseImports - private fun isImportedWithAllUnderImport(name: FqName) = name.parent() in allUnderImports + private fun isImportedWithAllUnderImport(name: FqName) = name.parent() in allUnderImports && name !in excludedImports private fun hasPreciseImportFromPackage(packageName: FqName) = packageName in preciseImportPackages }