processAllExactUsages() only for KtDeclaration

This commit is contained in:
Valentin Kipyatkov
2020-02-10 13:36:42 +02:00
parent c33a4c5c5b
commit ee6d6adf70
@@ -34,18 +34,19 @@ import org.jetbrains.kotlin.psi.KtConstructor
import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtPsiUtil import org.jetbrains.kotlin.psi.KtPsiUtil
import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addIfNotNull
fun PsiElement.processAllExactUsages( fun KtDeclaration.processAllExactUsages(
options: FindUsagesOptions, options: FindUsagesOptions,
processor: (UsageInfo) -> Unit processor: (UsageInfo) -> Unit
) { ) {
fun elementsToCheckReferenceAgainst(reference: PsiReference): List<PsiElement> { fun elementsToCheckReferenceAgainst(reference: PsiReference): List<PsiElement> {
if (reference is KtReference || this !is KtDeclaration) return listOf(this) if (reference is KtReference) return listOf(this)
return SmartList<PsiElement>().also { list -> return SmartList<PsiElement>().also { list ->
list += this list += this
list += toLightElements() list += toLightElements()
if (this is KtConstructor<*>) { if (this is KtConstructor<*>) {
getContainingClassOrObject().toLightClass()?.let { list += it } list.addIfNotNull(getContainingClassOrObject().toLightClass())
} }
} }
} }