From f92bc393230c947244df876f9bb98612b6761e60 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 30 Mar 2015 14:47:24 +0300 Subject: [PATCH] Minor code improvements --- .../kotlin/idea/caches/KotlinIndicesHelper.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt b/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt index 639f6c8d9f9..796fd8d8045 100644 --- a/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt @@ -52,7 +52,7 @@ public class KotlinIndicesHelper( declarations.addTopLevelNonExtensionCallablesByName(JetFunctionShortNameIndex.getInstance(), name) declarations.addTopLevelNonExtensionCallablesByName(JetPropertyShortNameIndex.getInstance(), name) return declarations.flatMap { - if (it.getContainingJetFile().isCompiled()) { + if (it.getContainingJetFile().isCompiled()) { //TODO: it's temporary while resolveToDescriptor does not work for compiled declarations analyzeImportReference(it.getFqName()!!).filterIsInstance() } else { @@ -69,9 +69,10 @@ public class KotlinIndicesHelper( } public fun getTopLevelCallables(nameFilter: (String) -> Boolean): Collection { - val sourceNames = JetTopLevelFunctionFqnNameIndex.getInstance().getAllKeys(project).sequence() + JetTopLevelPropertyFqnNameIndex.getInstance().getAllKeys(project).sequence() - val allFqNames = sourceNames.map { FqName(it) } - return allFqNames.filter { nameFilter(it.shortName().asString()) } + return (JetTopLevelFunctionFqnNameIndex.getInstance().getAllKeys(project).sequence() + + JetTopLevelPropertyFqnNameIndex.getInstance().getAllKeys(project).sequence()) + .map { FqName(it) } + .filter { nameFilter(it.shortName().asString()) } .toSet() .flatMap { findTopLevelCallables(it).filter(visibilityFilter) } } @@ -134,12 +135,14 @@ public class KotlinIndicesHelper( callType: CallType, bindingContext: BindingContext): Sequence { val extensions = index.get(callableFQN.asString(), project, scope).filter { it.getReceiverTypeReference() != null } - val descriptors = if (extensions.any { it.getContainingJetFile().isCompiled() } ) { + val descriptors = if (extensions.any { it.getContainingJetFile().isCompiled() } ) { //TODO: it's temporary while resolveToDescriptor does not work for compiled declarations analyzeImportReference(callableFQN) .filterIsInstance() .filter { it.getExtensionReceiverParameter() != null } } - else extensions.map { resolutionFacade.resolveToDescriptor(it) as CallableDescriptor } + else { + extensions.map { resolutionFacade.resolveToDescriptor(it) as CallableDescriptor } + } return descriptors.sequence() .filter(visibilityFilter) .flatMap { it.substituteExtensionIfCallable(receiverValue, callType, bindingContext, dataFlowInfo).sequence() } @@ -158,7 +161,7 @@ public class KotlinIndicesHelper( if (declarations.isEmpty()) { // This fqn is absent in caches, dead or not in scope - return listOf() + return emptyList() } // Note: Can't search with psi element as analyzer could be built over temp files