Find Usages: Fix reference check for the case of multiple resolve results

This commit is contained in:
Alexey Sedunov
2014-10-09 16:14:31 +04:00
parent f0a0df94b5
commit 0d220c68ea
9 changed files with 69 additions and 2 deletions
@@ -33,6 +33,7 @@ import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.JetObjectDeclaration
import org.jetbrains.jet.lang.psi.JetClassObject
import org.jetbrains.jet.lang.psi.JetClass
import com.intellij.psi.PsiPolyVariantReference
// Navigation element of the resolved reference
// For property accessor return enclosing property
@@ -49,7 +50,7 @@ public val PsiReference.unwrappedTargets: Set<PsiElement>
}
return when (this) {
is JetMultiReference<*> -> multiResolve(false).map { it.getElement()?.adjust() }.filterNotNullTo(HashSet<PsiElement>())
is PsiPolyVariantReference -> multiResolve(false).map { it.getElement()?.adjust() }.filterNotNullTo(HashSet<PsiElement>())
else -> ContainerUtil.createMaybeSingletonSet(resolve()?.adjust())
}
}
@@ -1,5 +1,6 @@
Function call (12: 20) A(0).plus(A(1).plus(2))
Function call (10: 17) A(0) + A(1) + 2
Function call (11: 20) A(0) plus A(1) plus 2
Function call (12: 20) A(0).plus(A(1).plus(2))
Function call (15: 7) a += 1
Function call (6: 30) fun plus(a: A): A = this + a.n
Unclassified usage (18: 5) +A(0)
@@ -0,0 +1,17 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
// OPTIONS: usages
package server
fun <caret>foo() {
}
fun Int.foo() {
}
fun foo(n: Int) {
}
val foo: Int
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
// OPTIONS: usages
package client
import server.foo
fun test() {
foo()
foo(1)
val t = foo
}
@@ -0,0 +1,2 @@
Function call (8: 5) foo()
Usage in import (5: 15) import server.foo
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetProperty
// OPTIONS: usages
package server
fun foo() {
}
val <caret>foo: Int = 1
val Int.foo: Int = 2
@@ -0,0 +1,10 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetProperty
// OPTIONS: usages
package client
import server.foo
fun test() {
foo()
val t = 1.foo + foo
}
@@ -0,0 +1,2 @@
Usage in import (5: 15) import server.foo
Value read (9: 21) val t = 1.foo + foo
@@ -472,6 +472,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
doTest(fileName);
}
@TestMetadata("kotlinMultiRefInImport.0.kt")
public void testKotlinMultiRefInImport() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinOverloadAndExtensionUsages.0.kt")
public void testKotlinOverloadAndExtensionUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/kotlinOverloadAndExtensionUsages.0.kt");
@@ -674,6 +680,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
doTest(fileName);
}
@TestMetadata("kotlinMultiRefInImport.0.kt")
public void testKotlinMultiRefInImport() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinPrivatePropertyUsages.0.kt")
public void testKotlinPrivatePropertyUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinPrivatePropertyUsages.0.kt");