From 7b6df0a7cc8494dc43409535adce4880092ce393 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 24 Jul 2018 13:27:23 +0300 Subject: [PATCH] Don't delete unresolved imports in cleanup inspection (KT-25678) It looks like they were deleted because of the bug in search for deprecated imports search. #KT-25678 Fixed --- .../idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt | 7 ++++++- idea/testData/inspections/cleanup/cleanup.kt | 1 + idea/testData/inspections/cleanup/cleanup.kt.after | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt index 02a79999d70..554fbfe60c2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt @@ -55,7 +55,12 @@ class DeprecatedSymbolUsageFix( } fun isImportToBeRemoved(import: KtImportDirective): Boolean { - return !import.isAllUnder && import.targetDescriptors().all { + if (import.isAllUnder) return false + + val targetDescriptors = import.targetDescriptors() + if (targetDescriptors.isEmpty()) return false + + return targetDescriptors.all { DeprecatedSymbolUsageFixBase.fetchReplaceWithPattern(it, import.project) != null } } diff --git a/idea/testData/inspections/cleanup/cleanup.kt b/idea/testData/inspections/cleanup/cleanup.kt index caa21c05618..d7200e391b5 100644 --- a/idea/testData/inspections/cleanup/cleanup.kt +++ b/idea/testData/inspections/cleanup/cleanup.kt @@ -2,6 +2,7 @@ import pack.oldFun1 import pack.oldFun2 // should not be removed for non-deprecated overload used import pack.oldFun3 import kotlin.reflect.KProperty +import some.unresolved.declaration // should not be removed class A private() diff --git a/idea/testData/inspections/cleanup/cleanup.kt.after b/idea/testData/inspections/cleanup/cleanup.kt.after index 378f5a40534..2bd0bc5cadc 100644 --- a/idea/testData/inspections/cleanup/cleanup.kt.after +++ b/idea/testData/inspections/cleanup/cleanup.kt.after @@ -1,6 +1,7 @@ import pack.bar import pack.oldFun2 // should not be removed for non-deprecated overload used import kotlin.reflect.KProperty +import some.unresolved.declaration // should not be removed class A private constructor()