From 0d220c68ea4d42b2917098937420f893c62e9de0 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 9 Oct 2014 16:14:31 +0400 Subject: [PATCH] Find Usages: Fix reference check for the case of multiple resolve results --- .../jet/plugin/references/referenceUtil.kt | 3 ++- .../kotlin/conventions/plus.results.txt | 3 ++- .../kotlinMultiRefInImport.0.kt | 17 +++++++++++++++++ .../kotlinMultiRefInImport.1.kt | 11 +++++++++++ .../kotlinMultiRefInImport.results.txt | 2 ++ .../kotlinMultiRefInImport.0.kt | 11 +++++++++++ .../kotlinMultiRefInImport.1.kt | 10 ++++++++++ .../kotlinMultiRefInImport.results.txt | 2 ++ .../findUsages/JetFindUsagesTestGenerated.java | 12 ++++++++++++ 9 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.0.kt create mode 100644 idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.1.kt create mode 100644 idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.results.txt create mode 100644 idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.0.kt create mode 100644 idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.1.kt create mode 100644 idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.results.txt diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt index b94e4a7374e..78d40897b4a 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt @@ -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 } return when (this) { - is JetMultiReference<*> -> multiResolve(false).map { it.getElement()?.adjust() }.filterNotNullTo(HashSet()) + is PsiPolyVariantReference -> multiResolve(false).map { it.getElement()?.adjust() }.filterNotNullTo(HashSet()) else -> ContainerUtil.createMaybeSingletonSet(resolve()?.adjust()) } } diff --git a/idea/testData/findUsages/kotlin/conventions/plus.results.txt b/idea/testData/findUsages/kotlin/conventions/plus.results.txt index 1edea255478..ced53573769 100644 --- a/idea/testData/findUsages/kotlin/conventions/plus.results.txt +++ b/idea/testData/findUsages/kotlin/conventions/plus.results.txt @@ -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) diff --git a/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.0.kt b/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.0.kt new file mode 100644 index 00000000000..228ffec2262 --- /dev/null +++ b/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.0.kt @@ -0,0 +1,17 @@ +// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction +// OPTIONS: usages +package server + +fun foo() { + +} + +fun Int.foo() { + +} + +fun foo(n: Int) { + +} + +val foo: Int \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.1.kt b/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.1.kt new file mode 100644 index 00000000000..eae414341de --- /dev/null +++ b/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.1.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.results.txt b/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.results.txt new file mode 100644 index 00000000000..6173c25cf0c --- /dev/null +++ b/idea/testData/findUsages/kotlin/findFunctionUsages/kotlinMultiRefInImport.results.txt @@ -0,0 +1,2 @@ +Function call (8: 5) foo() +Usage in import (5: 15) import server.foo diff --git a/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.0.kt b/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.0.kt new file mode 100644 index 00000000000..d581936eaeb --- /dev/null +++ b/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.0.kt @@ -0,0 +1,11 @@ +// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetProperty +// OPTIONS: usages +package server + +fun foo() { + +} + +val foo: Int = 1 + +val Int.foo: Int = 2 \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.1.kt b/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.1.kt new file mode 100644 index 00000000000..7c3eeb05e69 --- /dev/null +++ b/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.1.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.results.txt b/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.results.txt new file mode 100644 index 00000000000..a5e2729e692 --- /dev/null +++ b/idea/testData/findUsages/kotlin/findPropertyUsages/kotlinMultiRefInImport.results.txt @@ -0,0 +1,2 @@ +Usage in import (5: 15) import server.foo +Value read (9: 21) val t = 1.foo + foo diff --git a/idea/tests/org/jetbrains/jet/findUsages/JetFindUsagesTestGenerated.java b/idea/tests/org/jetbrains/jet/findUsages/JetFindUsagesTestGenerated.java index f33111494b6..7c4e620503c 100644 --- a/idea/tests/org/jetbrains/jet/findUsages/JetFindUsagesTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/findUsages/JetFindUsagesTestGenerated.java @@ -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");