diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt index d9d83b1d957..29e4351d6d4 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinRequestResultProces import org.jetbrains.kotlin.idea.search.restrictToKotlinSources import org.jetbrains.kotlin.idea.search.usagesSearch.DestructuringDeclarationUsageSearch.* import org.jetbrains.kotlin.idea.util.FuzzyType +import org.jetbrains.kotlin.idea.util.ProjectRootsUtil import org.jetbrains.kotlin.idea.util.fuzzyExtensionReceiverType import org.jetbrains.kotlin.idea.util.toFuzzyType import org.jetbrains.kotlin.kdoc.psi.impl.KDocName @@ -59,7 +60,6 @@ enum class DestructuringDeclarationUsageSearch { var destructuringDeclarationUsageSearchMode = if (ApplicationManager.getApplication().isUnitTestMode) ALWAYS_SMART else PLAIN_WHEN_NEEDED -//TODO: compiled code //TODO: check if it's too expensive fun findDestructuringDeclarationUsages( @@ -127,7 +127,7 @@ private class Processor( // we don't need to search usages of declarations in Java because Java doesn't have implicitly typed declarations so such usages cannot affect Kotlin code //TODO: what about Scala and other JVM-languages? - private val declarationUsageScope = GlobalSearchScope.projectScope(project).restrictToKotlinSources() //TODO: search in libraries? + private val declarationUsageScope = GlobalSearchScope.projectScope(project).restrictToKotlinSources() private val declarationsToProcess = ArrayDeque() private val declarationsToProcessSet = HashSet() @@ -142,6 +142,12 @@ private class Processor( else -> return } + // for data class from library always use plain search because we cannot search usages in compiled code (we could though) + if (!ProjectRootsUtil.isInProjectSource(psiClass)) { + plainSearchHandler(searchScope) + return + } + val parameters = ClassInheritorsSearch.SearchParameters(psiClass, GlobalSearchScope.allScope(project), true, true, false) val classesToSearch = listOf(psiClass) + ClassInheritorsSearch.search(parameters).findAll() diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.0.kt b/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.0.kt new file mode 100644 index 00000000000..d489a5241f6 --- /dev/null +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.0.kt @@ -0,0 +1,12 @@ +// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction +// OPTIONS: usages +// FIND_BY_REF + +fun foo(p: Pair) { + p.component1() + val (x, y) = p +} + +fun foo() { + val (x, y) = 1 to "a" +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.results.txt b/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.results.txt new file mode 100644 index 00000000000..eade0eace25 --- /dev/null +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.results.txt @@ -0,0 +1,3 @@ +Function call 6 p.component1() +Value read 11 val (x, y) = 1 to "a" +Value read 7 val (x, y) = p \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java b/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java index ba8f4528e59..997cbc6d4e7 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java @@ -194,6 +194,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest { doTest(fileName); } + @TestMetadata("dataClassFromStdlib.0.kt") + public void testDataClassFromStdlib() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.0.kt"); + doTest(fileName); + } + @TestMetadata("extensionComponentFun.0.kt") public void testExtensionComponentFun() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.0.kt");