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:
@@ -20,6 +20,7 @@ import com.intellij.psi.impl.source.DummyHolder
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.config.isLibraryToSourceAnalysisEnabled
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.incremental.KotlinLookupLocation
|
||||
@@ -35,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.CallExpressionElement
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.UnderscoreUsageChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.unrollToLeftMostQualifiedExpression
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.scopes.CompositePrioritizedImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
||||
@@ -221,6 +223,31 @@ class QualifiedExpressionResolver(val languageVersionSettings: LanguageVersionSe
|
||||
trace: BindingTrace,
|
||||
excludedImportNames: Collection<FqName>,
|
||||
packageFragmentForVisibilityCheck: PackageFragmentDescriptor?
|
||||
): ImportingScope? {
|
||||
fun processReferenceInContextOf(moduleDescriptor: ModuleDescriptor): ImportingScope? =
|
||||
doProcessImportReference(
|
||||
importDirective,
|
||||
moduleDescriptor,
|
||||
trace,
|
||||
excludedImportNames,
|
||||
packageFragmentForVisibilityCheck
|
||||
)
|
||||
|
||||
val primaryImportingScope = processReferenceInContextOf(moduleDescriptor)
|
||||
if (!languageVersionSettings.isLibraryToSourceAnalysisEnabled) return primaryImportingScope
|
||||
|
||||
val resolutionAnchor = moduleDescriptor.getResolutionAnchorIfAny() ?: return primaryImportingScope
|
||||
val secondaryImportingScope = processReferenceInContextOf(resolutionAnchor) ?: return primaryImportingScope
|
||||
if (primaryImportingScope == null) return secondaryImportingScope
|
||||
return CompositePrioritizedImportingScope(primaryImportingScope, secondaryImportingScope)
|
||||
}
|
||||
|
||||
private fun doProcessImportReference(
|
||||
importDirective: KtImportInfo,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
trace: BindingTrace,
|
||||
excludedImportNames: Collection<FqName>,
|
||||
packageFragmentForVisibilityCheck: PackageFragmentDescriptor?
|
||||
): ImportingScope? { // null if some error happened
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user