Allow search usages for declarations when correct isEquivalentTo

Now it's possible to do find usages for other languages when light
elements are used.

Revert efb36f4a49 and revise fix of KT-7983:
Don't consider local and non-local class with same fqn equivalent.

 #KT-7983 Fixed
This commit is contained in:
Nikolay Krasko
2017-04-17 18:37:18 +03:00
parent eb941c75f9
commit 5dbf3b6b4d
2 changed files with 23 additions and 9 deletions
@@ -50,14 +50,27 @@ open class KtClass : KtClassOrObject {
fun isInner(): Boolean = hasModifier(KtTokens.INNER_KEYWORD) fun isInner(): Boolean = hasModifier(KtTokens.INNER_KEYWORD)
override fun isEquivalentTo(another: PsiElement?): Boolean { override fun isEquivalentTo(another: PsiElement?): Boolean {
if (super.isEquivalentTo(another)) { if (this === another) {
return true return true
} }
if (another is KtClass) {
val fq1 = getQualifiedName() if (another !is KtClass) {
val fq2 = another.getQualifiedName() return false
return fq1 != null && fq2 != null && fq1 == fq2
} }
val fq1 = getQualifiedName() ?: return false
val fq2 = another.getQualifiedName() ?: return false
if (fq1 == fq2) {
val thisLocal = isLocal
if (thisLocal != another.isLocal) {
return false
}
// For non-local classes same fqn is enough
// Consider different instances of local classes non-equivalent
return !thisLocal
}
return false return false
} }
@@ -86,7 +86,11 @@ fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
} }
val targets = unwrappedTargets val targets = unwrappedTargets
if (unwrappedCandidate in targets) return true
val manager = candidateTarget.manager
if (targets.any { manager.areElementsEquivalent(unwrappedCandidate, it) }) {
return true
}
if (element is KtLabelReferenceExpression && (element.parent as? KtContainerNode)?.parent is KtReturnExpression) { if (element is KtLabelReferenceExpression && (element.parent as? KtContainerNode)?.parent is KtReturnExpression) {
targets.forEach { targets.forEach {
@@ -97,9 +101,6 @@ fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
} }
} }
// TODO: Investigate why PsiCompiledElement identity changes
if (unwrappedCandidate is PsiCompiledElement && targets.any { it.isEquivalentTo(unwrappedCandidate) }) return true
if (this is KtReference) { if (this is KtReference) {
return targets.any { return targets.any {
it.isConstructorOf(unwrappedCandidate) it.isConstructorOf(unwrappedCandidate)