From e7796fbb589f58580016ce6510ddb422ece1f675 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 4 Mar 2015 15:26:53 +0300 Subject: [PATCH] Not trying to find declaration in both builtins and decompiled code (as it worked before). --- .../src/org/jetbrains/kotlin/utils/addToStdlib.kt | 2 ++ .../idea/codeInsight/DescriptorToSourceUtilsIde.kt | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/addToStdlib.kt b/compiler/util/src/org/jetbrains/kotlin/utils/addToStdlib.kt index 2b296993559..1151a39fcf6 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/addToStdlib.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/addToStdlib.kt @@ -52,3 +52,5 @@ public inline fun Array<*>.firstIsInstance(): T { for (element in this) if (element is T) return element throw NoSuchElementException("No element of given type found") } + +public fun streamOfLazyValues(vararg elements: () -> T): Stream = elements.stream().map { it() } \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToSourceUtilsIde.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToSourceUtilsIde.kt index 9e277dfb55b..7541b2342e9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToSourceUtilsIde.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToSourceUtilsIde.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.* import java.util.* import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.utils.addToStdlib.streamOfLazyValues public object DescriptorToSourceUtilsIde { // Returns PSI element for descriptor. If there are many relevant elements (e.g. it is fake override @@ -46,11 +47,12 @@ public object DescriptorToSourceUtilsIde { private fun getDeclarationsStream(project: Project, targetDescriptor: DeclarationDescriptor): Stream { val effectiveReferencedDescriptors = DescriptorToSourceUtils.getEffectiveReferencedDescriptors(targetDescriptor).stream() - return effectiveReferencedDescriptors.flatMap { - streamOf( - DescriptorToSourceUtils.getSourceFromDescriptor(it), - findBuiltinDeclaration(project, it), - DecompiledNavigationUtils.getDeclarationFromDecompiledClassFile(project, it) + return effectiveReferencedDescriptors.flatMap { effectiveReferenced -> + // References in library sources should be resolved to corresponding decompiled declarations, + // therefore we put both source declaration and decompiled declaration to stream, and afterwards we filter it in getAllDeclarations + streamOfLazyValues( + { DescriptorToSourceUtils.getSourceFromDescriptor(effectiveReferenced) }, + { findBuiltinDeclaration(project, effectiveReferenced) ?: DecompiledNavigationUtils.getDeclarationFromDecompiledClassFile(project, effectiveReferenced) } ) }.filterNotNull() }