From 156184b0eb3d2fd7b9e940361129837e33942305 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 21 Jan 2015 16:15:55 +0300 Subject: [PATCH] Extracted function which gets component function name for data class property. It used to rely on the fact that class is already resolved before. Added force resolution of class, to make this function reusable in other context. --- .../idea/search/usagesSearch/searchHelpers.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/searchHelpers.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/searchHelpers.kt index 066a2e12598..459453b1515 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/searchHelpers.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/searchHelpers.kt @@ -73,18 +73,30 @@ public fun PsiNamedElement.getSpecialNamesToSearch(): List { return when { name == null || !Name.isValidIdentifier(name) -> Collections.emptyList() this is JetParameter -> { - if (!hasValOrVarNode()) return Collections.emptyList() + val componentFunctionName = this.dataClassComponentFunctionName() + if (componentFunctionName == null) return Collections.emptyList() - val context = this.analyze() - val paramDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, this] as? ValueParameterDescriptor - context[BindingContext.DATA_CLASS_COMPONENT_FUNCTION, paramDescriptor]?.let { - listOf(it.getName().asString(), JetTokens.LPAR.getValue()) - } ?: Collections.emptyList() + return listOf(componentFunctionName.asString(), JetTokens.LPAR.getValue()) } else -> Name.identifier(name).getOperationSymbolsToSearch().map { (it as JetSingleValueToken).getValue() } } } +fun JetParameter.dataClassComponentFunctionName(): Name? { + if (!hasValOrVarNode()) return null + + // Forcing full resolve of owner class: otherwise DATA_CLASS_COMPONENT_FUNCTION won't be calculated. + // This is a hack, but better solution would need refactoring of data class component function resolution: they need to be resolved + // when resolving corresponding property. + LightClassUtil.getLightClassPropertyMethods(this) + + val context = this.analyze() + val paramDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, this] as? ValueParameterDescriptor + return context[BindingContext.DATA_CLASS_COMPONENT_FUNCTION, paramDescriptor]?.let { + it.getName() + } +} + public abstract class UsagesSearchHelper { protected open fun makeFilter(target: UsagesSearchTarget): UsagesSearchFilter = isTargetUsage