KT-13605 Find Usages fails to find usages of component function defined in Java

#KT-13605 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-09-03 01:15:18 +03:00
parent 5e52e74963
commit 478556890a
8 changed files with 35 additions and 18 deletions
@@ -78,7 +78,7 @@ fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
if (candidateTarget !is KtNamedFunction) return false
}
is KtDestructuringDeclarationReference -> {
if (candidateTarget !is KtNamedFunction && candidateTarget !is KtParameter) return false
if (candidateTarget !is KtNamedFunction && candidateTarget !is KtParameter && candidateTarget !is PsiMethod) return false
}
}
@@ -25,24 +25,16 @@ import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.references.KtDestructuringDeclarationReference
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.dataClassUtils.getComponentIndex
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
class DestructuringDeclarationReferenceSearcher(
targetDeclaration: PsiElement,
private val componentIndex: Int,
searchScope: SearchScope,
consumer: Processor<PsiReference>,
optimizer: SearchRequestCollector
) : OperatorReferenceSearcher<KtDestructuringDeclaration>(targetDeclaration, searchScope, consumer, optimizer, wordsToSearch = listOf("(")) {
//TODO
private val componentIndex = when (targetDeclaration) {
is KtParameter -> targetDeclaration.dataClassComponentFunction()?.name?.asString()?.let { getComponentIndex(it) }
is KtFunction -> targetDeclaration.name?.let { getComponentIndex(it) }
//TODO: java component functions (see KT-13605)
else -> null
}
override fun resolveTargetToDescriptor(): FunctionDescriptor? {
if (targetDeclaration is KtParameter) {
return targetDeclaration.dataClassComponentFunction()
@@ -52,15 +44,10 @@ class DestructuringDeclarationReferenceSearcher(
}
}
override fun run() {
if (componentIndex == null) return
super.run()
}
override fun extractReference(element: PsiElement): PsiReference? {
val destructuringDeclaration = element as? KtDestructuringDeclaration ?: return null
val entries = destructuringDeclaration.entries
if (entries.size < componentIndex!!) return null
if (entries.size < componentIndex) return null
return entries[componentIndex - 1].references.firstIsInstance<KtDestructuringDeclarationReference>()
}
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.idea.util.fuzzyExtensionReceiverType
import org.jetbrains.kotlin.idea.util.toFuzzyType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.dataClassUtils.getComponentIndex
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.types.expressions.OperatorConventions
@@ -105,7 +106,8 @@ abstract class OperatorReferenceSearcher<TReferenceElement : KtElement>(
): OperatorReferenceSearcher<*>? {
if (isComponentLike(name)) {
if (!options.searchForComponentConventions) return null
return DestructuringDeclarationReferenceSearcher(declaration, searchScope, consumer, optimizer)
val componentIndex = getComponentIndex(name.asString())
return DestructuringDeclarationReferenceSearcher(declaration, componentIndex, searchScope, consumer, optimizer)
}
if (!options.searchForOperatorConventions) return null
@@ -160,7 +162,7 @@ abstract class OperatorReferenceSearcher<TReferenceElement : KtElement>(
} as? FunctionDescriptor
}
open fun run() {
fun run() {
val inProgress = SearchesInProgress.get()
if (!inProgress.add(targetDeclaration)) return //TODO: it's not quite correct