Extend import resolution for library-to-source analysis

Use composite importing scope for references when resolution anchors are enabled.
Composite scope provides additional descriptors from scope of resolution anchor module.
Overriding old importing scope with a new one is not possible as it breaks library
dependencies on other libraries, which are inaccessible in anchor scope (scope for sources).

KT-24309 In Progress
This commit is contained in:
Pavel Kirpichenkov
2020-06-15 15:36:53 +03:00
parent 8c876e4621
commit 5892bdf3f4
8 changed files with 94 additions and 2 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.descriptors
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.RESOLUTION_ANCHOR_PROVIDER_CAPABILITY
import org.jetbrains.kotlin.resolve.getResolutionAnchorIfAny
fun ModuleDescriptor.findClassifierAcrossModuleDependencies(classId: ClassId): ClassifierDescriptor? = withAnchorFallback {
val packageViewDescriptor = getPackage(classId.packageFqName)
@@ -40,7 +41,7 @@ fun ModuleDescriptor.findClassifierAcrossModuleDependencies(classId: ClassId): C
private inline fun ModuleDescriptor.withAnchorFallback(
crossinline doSearch: ModuleDescriptor.() -> ClassifierDescriptor?
): ClassifierDescriptor? {
val anchor = getCapability(RESOLUTION_ANCHOR_PROVIDER_CAPABILITY)?.getResolutionAnchor(this)
val anchor = getResolutionAnchorIfAny()
return if (anchor == null) doSearch() else doSearch() ?: anchor.doSearch()
}
@@ -19,3 +19,6 @@ interface ResolutionAnchorProvider {
}
val RESOLUTION_ANCHOR_PROVIDER_CAPABILITY = ModuleCapability<ResolutionAnchorProvider>("ResolutionAnchorProvider")
fun ModuleDescriptor.getResolutionAnchorIfAny(): ModuleDescriptor? =
getCapability(RESOLUTION_ANCHOR_PROVIDER_CAPABILITY)?.getResolutionAnchor(this)