diff --git a/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt b/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt index feef8ef11cc..1cb23a1e3e4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt @@ -47,16 +47,13 @@ public class KotlinIndicesHelper( private val moduleDescriptor: ModuleDescriptor, private val visibilityFilter: (DeclarationDescriptor) -> Boolean ) { - public fun getTopLevelCallablesByName(name: String, context: JetExpression /*TODO: to be dropped*/): Collection { - val resolutionScope = bindingContext[BindingContext.RESOLUTION_SCOPE, context] ?: return listOf() - + public fun getTopLevelCallablesByName(name: String): Collection { val declarations = HashSet() declarations.addTopLevelNonExtensionCallablesByName(JetFunctionShortNameIndex.getInstance(), name) declarations.addTopLevelNonExtensionCallablesByName(JetPropertyShortNameIndex.getInstance(), name) return declarations.flatMap { if (it.getContainingJetFile().isCompiled()) { - val importDirective = JetPsiFactory(project).createImportDirective(it.getFqName().asString()) - analyzeImportReference(importDirective, resolutionScope, BindingTraceContext()).filterIsInstance() + analyzeImportReference(it.getFqName()!!).filterIsInstance() } else { (resolutionFacade.resolveToDescriptor(it) as? CallableDescriptor).singletonOrEmptyList() @@ -71,15 +68,12 @@ public class KotlinIndicesHelper( index.get(name, project, scope).filterTo(this) { it.getParent() is JetFile && it.getReceiverTypeReference() == null } } - public fun getTopLevelCallables(nameFilter: (String) -> Boolean, context: JetExpression /*TODO: to be dropped*/): Collection { + public fun getTopLevelCallables(nameFilter: (String) -> Boolean): Collection { val sourceNames = JetTopLevelFunctionFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertyFqnNameIndex.getInstance().getAllKeys(project).stream() val allFqNames = sourceNames.map { FqName(it) } - - val jetScope = bindingContext[BindingContext.RESOLUTION_SCOPE, context] ?: return listOf() - return allFqNames.filter { nameFilter(it.shortName().asString()) } .toSet() - .flatMap { findTopLevelCallables(it, context, jetScope).filter(visibilityFilter) } + .flatMap { findTopLevelCallables(it).filter(visibilityFilter) } } public fun getCallableExtensions(nameFilter: (String) -> Boolean, expression: JetSimpleNameExpression): Collection { @@ -113,12 +107,10 @@ public class KotlinIndicesHelper( val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, receiverExpression] if (expressionType == null || expressionType.isError()) return - val resolutionScope = bindingContext[BindingContext.RESOLUTION_SCOPE, receiverExpression] ?: return - val receiverValue = ExpressionReceiver(receiverExpression, expressionType) matchingNames.flatMapTo(this) { - findSuitableExtensions(it, index, receiverValue, dataFlowInfo, callType, resolutionScope, bindingContext) + findSuitableExtensions(it, index, receiverValue, dataFlowInfo, callType, bindingContext) } } else { @@ -126,7 +118,7 @@ public class KotlinIndicesHelper( for (receiver in resolutionScope.getImplicitReceiversWithInstance()) { matchingNames.flatMapTo(this) { - findSuitableExtensions(it, index, receiver.getValue(), dataFlowInfo, CallType.NORMAL, resolutionScope, bindingContext) + findSuitableExtensions(it, index, receiver.getValue(), dataFlowInfo, CallType.NORMAL, bindingContext) } } } @@ -140,13 +132,10 @@ public class KotlinIndicesHelper( receiverValue: ReceiverValue, dataFlowInfo: DataFlowInfo, callType: CallType, - resolutionScope: JetScope, bindingContext: BindingContext): Stream { - val fqnString = callableFQN.asString() - val extensions = index.get(fqnString, project, scope).filter { it.getReceiverTypeReference() != null } + val extensions = index.get(callableFQN.asString(), project, scope).filter { it.getReceiverTypeReference() != null } val descriptors = if (extensions.any { it.getContainingJetFile().isCompiled() } ) { - val importDirective = JetPsiFactory(project).createImportDirective(fqnString) - analyzeImportReference(importDirective, resolutionScope, BindingTraceContext()) + analyzeImportReference(callableFQN) .filterIsInstance() .filter { it.getExtensionReceiverParameter() != null } } @@ -177,15 +166,15 @@ public class KotlinIndicesHelper( .filter(visibilityFilter) } - private fun findTopLevelCallables(fqName: FqName, context: JetExpression, jetScope: JetScope): Collection { - val importDirective = JetPsiFactory(context.getProject()).createImportDirective(ImportPath(fqName, false)) - val allDescriptors = analyzeImportReference(importDirective, jetScope, BindingTraceContext()) - return allDescriptors.filterIsInstance().filter { it.getExtensionReceiverParameter() == null } + private fun findTopLevelCallables(fqName: FqName): Collection { + return analyzeImportReference(fqName) + .filterIsInstance() + .filter { it.getExtensionReceiverParameter() == null } } - private fun analyzeImportReference( - importDirective: JetImportDirective, scope: JetScope, trace: BindingTrace - ): Collection { - return QualifiedExpressionResolver().processImportReference(importDirective, scope, scope, null, trace, LookupMode.EVERYTHING) + private fun analyzeImportReference(fqName: FqName): Collection { + val importDirective = JetPsiFactory(project).createImportDirective(ImportPath(fqName, false)) + val scope = JetModuleUtil.getSubpackagesOfRootScope(moduleDescriptor) + return QualifiedExpressionResolver().processImportReference(importDirective, scope, scope, null, BindingTraceContext(), LookupMode.EVERYTHING) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt b/idea/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt index 343a502c74f..49f480b2552 100644 --- a/idea/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt +++ b/idea/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt @@ -198,7 +198,7 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess = configuration.completeNonImportedDeclarations || prefix.length() >= 3 protected fun getKotlinTopLevelCallables(): Collection - = indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) }, reference!!.expression) + = indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) }) protected fun getKotlinExtensions(): Collection = indicesHelper.getCallableExtensions({ prefixMatcher.prefixMatches(it) }, reference!!.expression) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt index 6092cd6d806..dc6123198f3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt @@ -142,20 +142,14 @@ public class AutoImportFix(element: JetSimpleNameExpression) : JetHintAction - = indicesHelper.getTopLevelCallablesByName(name, context) - - private fun getExtensions(name: String, expression: JetSimpleNameExpression, indicesHelper: KotlinIndicesHelper): Collection - = indicesHelper.getCallableExtensions({ it == name }, expression) - private fun getClasses(name: String, file: JetFile, searchScope: GlobalSearchScope): Collection = getShortNamesCache(file).getClassesByName(name, searchScope) .map { element.getResolutionFacade().psiClassToDescriptor(it) }