From 59f939d9efe0150978b6a1c7323a9ed975935a99 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 27 Mar 2015 15:01:36 +0300 Subject: [PATCH] Do check isCheapEnoughToSearch for companion objects, but just ignore ZERO_OCCURENCES outcome. --- .../inspections/UnusedSymbolInspection.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt index 65e05d4585c..e84635e051d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt @@ -162,19 +162,22 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() { val psiSearchHelper = PsiSearchHelper.SERVICE.getInstance(declaration.getProject()) val useScope = declaration.getUseScope() - if (!(declaration is JetObjectDeclaration && declaration.isCompanion())) { - if (useScope is GlobalSearchScope) { - var zeroOccurrences = true + if (useScope is GlobalSearchScope) { + var zeroOccurrences = true - for (name in listOf(declaration.getName()) + declaration.getAccessorNames() + declaration.getClassNameForCompanionObject().singletonOrEmptyList()) { - when (psiSearchHelper.isCheapEnoughToSearch(name, useScope, null, null)) { - ZERO_OCCURRENCES -> {} // go on, check other names - FEW_OCCURRENCES -> zeroOccurrences = false - TOO_MANY_OCCURRENCES -> return true // searching usages is too expensive; behave like it is used - } + for (name in listOf(declaration.getName()) + declaration.getAccessorNames() + declaration.getClassNameForCompanionObject().singletonOrEmptyList()) { + when (psiSearchHelper.isCheapEnoughToSearch(name, useScope, null, null)) { + ZERO_OCCURRENCES -> {} // go on, check other names + FEW_OCCURRENCES -> zeroOccurrences = false + TOO_MANY_OCCURRENCES -> return true // searching usages is too expensive; behave like it is used } + } - if (zeroOccurrences) { + if (zeroOccurrences) { + if (declaration is JetObjectDeclaration && declaration.isCompanion()) { + // go on: companion object can be used only in containing class + } + else { return false } }