diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt index 45bcb52626a..a4049e794a6 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.compatibility.ExecutorProcessor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.idea.references.KtSimpleNameReference import org.jetbrains.kotlin.idea.search.* +import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions.Companion.Empty import org.jetbrains.kotlin.idea.search.usagesSearch.dataClassComponentFunction import org.jetbrains.kotlin.idea.search.usagesSearch.getClassNameForCompanionObject import org.jetbrains.kotlin.idea.search.usagesSearch.operators.OperatorReferenceSearcher @@ -46,13 +47,15 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.parents import java.util.* -data class KotlinReferencesSearchOptions(val acceptCallableOverrides: Boolean = false, - val acceptOverloads: Boolean = false, - val acceptExtensionsOfDeclarationClass: Boolean = false, - val acceptCompanionObjectMembers: Boolean = false, - val searchForComponentConventions: Boolean = true, - val searchForOperatorConventions: Boolean = true, - val searchNamedArguments: Boolean = true) { +data class KotlinReferencesSearchOptions( + val acceptCallableOverrides: Boolean = false, + val acceptOverloads: Boolean = false, + val acceptExtensionsOfDeclarationClass: Boolean = false, + val acceptCompanionObjectMembers: Boolean = false, + val searchForComponentConventions: Boolean = true, + val searchForOperatorConventions: Boolean = true, + val searchNamedArguments: Boolean = true +) { fun anyEnabled(): Boolean = acceptCallableOverrides || acceptOverloads || acceptExtensionsOfDeclarationClass companion object { @@ -61,12 +64,12 @@ data class KotlinReferencesSearchOptions(val acceptCallableOverrides: Boolean = } class KotlinReferencesSearchParameters( - elementToSearch: PsiElement, - scope: SearchScope = runReadAction { elementToSearch.project.allScope() }, - ignoreAccessScope: Boolean = false, - optimizer: SearchRequestCollector? = null, - val kotlinOptions: KotlinReferencesSearchOptions = KotlinReferencesSearchOptions.Empty) - : ReferencesSearch.SearchParameters(elementToSearch, scope, ignoreAccessScope, optimizer) + elementToSearch: PsiElement, + scope: SearchScope = runReadAction { elementToSearch.project.allScope() }, + ignoreAccessScope: Boolean = false, + optimizer: SearchRequestCollector? = null, + val kotlinOptions: KotlinReferencesSearchOptions = Empty +) : ReferencesSearch.SearchParameters(elementToSearch, scope, ignoreAccessScope, optimizer) class KotlinReferencesSearcher : QueryExecutorBase() { override fun processQuery(queryParameters: ReferencesSearch.SearchParameters, consumer: ExecutorProcessor) { @@ -77,8 +80,7 @@ class KotlinReferencesSearcher : QueryExecutorBase) { - private val kotlinOptions = (queryParameters as? KotlinReferencesSearchParameters)?.kotlinOptions - ?: KotlinReferencesSearchOptions.Empty + private val kotlinOptions = (queryParameters as? KotlinReferencesSearchParameters)?.kotlinOptions ?: Empty private val longTasks = ArrayList<() -> Unit>() @@ -95,8 +97,7 @@ class KotlinReferencesSearcher : QueryExecutorBase() searchNamedElement(property) - } - else if (declaration is KtFunction) { + } else if (declaration is KtFunction) { processStaticsFromCompanionObject(declaration) if (element.isMangled) { searchNamedElement(declaration) { it.restrictToKotlinSources() } @@ -256,22 +261,22 @@ class KotlinReferencesSearcher : QueryExecutorBase()?.toLightClass() if (originLightClass != null) { val lightDeclarations: List?> = - originLightClass.methods.map { it as? KtLightMethod } + - originLightClass.fields.map { it as? KtLightField } + originLightClass.methods.map { it as? KtLightMethod } + originLightClass.fields.map { it as? KtLightField } for (declaration in element.declarations) { lightDeclarations - .firstOrNull { it?.kotlinOrigin == declaration } - ?.let { searchNamedElement(it) } + .firstOrNull { it?.kotlinOrigin == declaration } + ?.let { searchNamedElement(it) } } } } } } - private fun searchDataClassComponentUsages(containingClass: PsiClass?, - componentFunctionDescriptor: FunctionDescriptor, - kotlinOptions: KotlinReferencesSearchOptions + private fun searchDataClassComponentUsages( + containingClass: PsiClass?, + componentFunctionDescriptor: FunctionDescriptor, + kotlinOptions: KotlinReferencesSearchOptions ) { val componentFunction = containingClass?.methods?.firstOrNull { it.name == componentFunctionDescriptor.name.asString() && it.parameterList.parametersCount == 0 @@ -280,7 +285,8 @@ class KotlinReferencesSearcher : QueryExecutorBase { val originObject = declaration.parents - .dropWhile { it is KtClassBody } - .firstOrNull() as? KtObjectDeclaration ?: return emptyList() + .dropWhile { it is KtClassBody } + .firstOrNull() as? KtObjectDeclaration ?: return emptyList() if (!originObject.isCompanion()) return emptyList() val originClass = originObject.getStrictParentOfType() val originLightClass = originClass?.toLightClass() ?: return emptyList() @@ -309,9 +315,11 @@ class KotlinReferencesSearcher : QueryExecutorBase