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