diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt index 6048165b464..fa01d90bd26 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt @@ -171,4 +171,6 @@ public class JetSimpleNameReference( override fun toString(): String { return javaClass().getSimpleName() + ": " + expression.getText() } + + override fun getCanonicalText(): String = expression.getText() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt index 3c772e03abb..27d9aaa6e23 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt @@ -53,7 +53,7 @@ public class KotlinReferencesSearcher : QueryExecutorBase true - !ref.matchesTarget(unwrappedElement) -> true + !ref.isReferenceTo(unwrappedElement) -> true else -> consumer.process(ref) } } @@ -73,20 +73,12 @@ public class KotlinReferencesSearcher : QueryExecutorBase(object : Computable { - override fun compute(): PsiClass? { - return LightClassUtil.getPsiClass(element) - } - }) + val lightClass = runReadAction { LightClassUtil.getPsiClass(element) } if (lightClass != null) { searchNamedElement(queryParameters, lightClass, className) if (element is JetObjectDeclaration && element.isCompanion()) { - val fieldForCompanionObject = ApplicationManager.getApplication().runReadAction(object : Computable { - override fun compute(): PsiField? { - return LightClassUtil.getLightFieldForCompanionObject(element) - } - }) + val fieldForCompanionObject = runReadAction { LightClassUtil.getLightFieldForCompanionObject(element) } if (fieldForCompanionObject != null) { searchNamedElement(queryParameters, fieldForCompanionObject) } diff --git a/idea/testData/search/references/testParam.kt b/idea/testData/search/references/testParam.kt new file mode 100644 index 00000000000..214ae93e24f --- /dev/null +++ b/idea/testData/search/references/testParam.kt @@ -0,0 +1,8 @@ +data class A(val n: Int, val s: String, val o: Any) + +fun test() { + val a = A(1, "2", Any()) + a.n + a.component1() + val (x, y, z) = a +} diff --git a/idea/testData/search/references/testPlus.kt b/idea/testData/search/references/testPlus.kt new file mode 100644 index 00000000000..5e0abef5817 --- /dev/null +++ b/idea/testData/search/references/testPlus.kt @@ -0,0 +1,12 @@ +class A() { + fun plus(rhs: A): A { + return A() + } +} + +val a1 = A() +val a2 = A() +val a3 = a1 + a2 +val a4 = a1.plus(a2) +val a5 = a1 plus a2 + diff --git a/idea/tests/org/jetbrains/kotlin/search/KotlinReferencesSearchTest.kt b/idea/tests/org/jetbrains/kotlin/search/KotlinReferencesSearchTest.kt new file mode 100644 index 00000000000..c0fd629e773 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/search/KotlinReferencesSearchTest.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.search + +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiReference +import com.intellij.psi.search.searches.ReferencesSearch +import org.jetbrains.kotlin.idea.references.JetMultiDeclarationReference +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.psi.JetFunction +import org.jetbrains.kotlin.psi.JetParameter +import org.jetbrains.kotlin.psi.psiUtil.getParentOfType +import org.junit.Assert +import java.io.File + +public class KotlinReferencesSearchTest(): AbstractSearcherTest() { + override fun getTestDataPath(): String { + return File(PluginTestCaseBase.getTestDataPathBase(), "/search/references").getPath() + File.separator + } + + public fun testPlus() { + val refs = doTest() + Assert.assertEquals(3, refs.size()) + Assert.assertEquals("+", refs[0].getCanonicalText()) + Assert.assertEquals("plus", refs[1].getCanonicalText()) + Assert.assertEquals("plus", refs[2].getCanonicalText()) + } + + public fun testParam() { + val refs = doTest() + Assert.assertEquals(3, refs.size()) + Assert.assertEquals("n", refs[0].getCanonicalText()) + Assert.assertEquals("component1", refs[1].getCanonicalText()) + Assert.assertTrue(refs[2] is JetMultiDeclarationReference) + } + + private inline fun doTest(): List { + myFixture.configureByFile(getFileName()) + val func = myFixture.getElementAtCaret().getParentOfType(false)!! + return ReferencesSearch.search(func).findAll().sortBy { it.getElement().getTextRange().getStartOffset() } + } +}