Moved package directive resolve to NewQualifiedExpressionResolver
This commit is contained in:
@@ -1230,23 +1230,6 @@ public class DescriptorResolver {
|
|||||||
return getParentOfType(scope.getOwnerDescriptor(), ClassDescriptor.class, false);
|
return getParentOfType(scope.getOwnerDescriptor(), ClassDescriptor.class, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resolvePackageHeader(
|
|
||||||
@NotNull JetPackageDirective packageDirective,
|
|
||||||
@NotNull ModuleDescriptor module,
|
|
||||||
@NotNull BindingTrace trace
|
|
||||||
) {
|
|
||||||
for (JetSimpleNameExpression nameExpression : packageDirective.getPackageNames()) {
|
|
||||||
FqName fqName = packageDirective.getFqName(nameExpression);
|
|
||||||
|
|
||||||
PackageViewDescriptor packageView = module.getPackage(fqName);
|
|
||||||
trace.record(REFERENCE_TARGET, nameExpression, packageView);
|
|
||||||
|
|
||||||
PackageViewDescriptor parentPackageView = packageView.getContainingDeclaration();
|
|
||||||
assert parentPackageView != null : "Should not be null since " + fqName + " should not be root";
|
|
||||||
trace.record(RESOLUTION_SCOPE, nameExpression, parentPackageView.getMemberScope());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerFileInPackage(@NotNull BindingTrace trace, @NotNull JetFile file) {
|
public static void registerFileInPackage(@NotNull BindingTrace trace, @NotNull JetFile file) {
|
||||||
// Register files corresponding to this package
|
// Register files corresponding to this package
|
||||||
// The trace currently does not support bi-di multimaps that would handle this task nicer
|
// The trace currently does not support bi-di multimaps that would handle this task nicer
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ public class LazyTopDownAnalyzer(
|
|||||||
private val bodyResolver: BodyResolver,
|
private val bodyResolver: BodyResolver,
|
||||||
private val topLevelDescriptorProvider: TopLevelDescriptorProvider,
|
private val topLevelDescriptorProvider: TopLevelDescriptorProvider,
|
||||||
private val fileScopeProvider: FileScopeProvider,
|
private val fileScopeProvider: FileScopeProvider,
|
||||||
private val declarationScopeProvider: DeclarationScopeProvider
|
private val declarationScopeProvider: DeclarationScopeProvider,
|
||||||
|
private val newQualifiedExpressionResolver: NewQualifiedExpressionResolver
|
||||||
) {
|
) {
|
||||||
public fun analyzeDeclarations(topDownAnalysisMode: TopDownAnalysisMode, declarations: Collection<PsiElement>, outerDataFlowInfo: DataFlowInfo): TopDownAnalysisContext {
|
public fun analyzeDeclarations(topDownAnalysisMode: TopDownAnalysisMode, declarations: Collection<PsiElement>, outerDataFlowInfo: DataFlowInfo): TopDownAnalysisContext {
|
||||||
val c = TopDownAnalysisContext(topDownAnalysisMode, outerDataFlowInfo, declarationScopeProvider)
|
val c = TopDownAnalysisContext(topDownAnalysisMode, outerDataFlowInfo, declarationScopeProvider)
|
||||||
@@ -92,7 +93,7 @@ public class LazyTopDownAnalyzer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPackageDirective(directive: JetPackageDirective) {
|
override fun visitPackageDirective(directive: JetPackageDirective) {
|
||||||
DescriptorResolver.resolvePackageHeader(directive, moduleDescriptor, trace)
|
newQualifiedExpressionResolver.resolvePackageHeader(directive, moduleDescriptor, trace)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitImportDirective(importDirective: JetImportDirective) {
|
override fun visitImportDirective(importDirective: JetImportDirective) {
|
||||||
|
|||||||
+22
-15
@@ -32,6 +32,17 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
|
|
||||||
public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator) {
|
public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator) {
|
||||||
|
|
||||||
|
|
||||||
|
public fun resolvePackageHeader(
|
||||||
|
packageDirective: JetPackageDirective,
|
||||||
|
module: ModuleDescriptor,
|
||||||
|
trace: BindingTrace
|
||||||
|
) {
|
||||||
|
for (nameExpression in packageDirective.packageNames) {
|
||||||
|
storageResult(trace, nameExpression, listOf(module.getPackage(packageDirective.getFqName(nameExpression))), null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public fun processImportReference(
|
public fun processImportReference(
|
||||||
importDirective: JetImportDirective,
|
importDirective: JetImportDirective,
|
||||||
moduleDescriptor: ModuleDescriptor,
|
moduleDescriptor: ModuleDescriptor,
|
||||||
@@ -74,7 +85,7 @@ public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsag
|
|||||||
// todo assert?
|
// todo assert?
|
||||||
else -> return JetScope.Empty
|
else -> return JetScope.Empty
|
||||||
}
|
}
|
||||||
storageResult(trace, lastPart, descriptors, shouldBeVisibleFrom)
|
storageResult(trace, lastPart.expression, descriptors, shouldBeVisibleFrom)
|
||||||
|
|
||||||
val aliasName = JetPsiUtil.getAliasName(importDirective) ?: return JetScope.Empty
|
val aliasName = JetPsiUtil.getAliasName(importDirective) ?: return JetScope.Empty
|
||||||
return SingleImportScope(aliasName, descriptors)
|
return SingleImportScope(aliasName, descriptors)
|
||||||
@@ -126,7 +137,7 @@ public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsag
|
|||||||
|
|
||||||
val (currentDescriptor, currentIndex) = firstPartResolver(path.first())?.let {
|
val (currentDescriptor, currentIndex) = firstPartResolver(path.first())?.let {
|
||||||
Pair(it, 1)
|
Pair(it, 1)
|
||||||
} ?: moduleDescriptor.quickResolveToPackage(path, trace, shouldBeVisibleFrom)
|
} ?: moduleDescriptor.quickResolveToPackage(path, trace)
|
||||||
return path.subList(currentIndex, path.size()).fold<QualifierPart, DeclarationDescriptor?>(currentDescriptor) {
|
return path.subList(currentIndex, path.size()).fold<QualifierPart, DeclarationDescriptor?>(currentDescriptor) {
|
||||||
descriptor, qualifierPart ->
|
descriptor, qualifierPart ->
|
||||||
val nextDescriptor = when (descriptor) {
|
val nextDescriptor = when (descriptor) {
|
||||||
@@ -147,15 +158,14 @@ public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsag
|
|||||||
}
|
}
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
storageResult(trace, qualifierPart, listOfNotNull(nextDescriptor), shouldBeVisibleFrom)
|
storageResult(trace, qualifierPart.expression, listOfNotNull(nextDescriptor), shouldBeVisibleFrom)
|
||||||
nextDescriptor
|
nextDescriptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ModuleDescriptor.quickResolveToPackage(
|
private fun ModuleDescriptor.quickResolveToPackage(
|
||||||
path: List<QualifierPart>,
|
path: List<QualifierPart>,
|
||||||
trace: BindingTrace,
|
trace: BindingTrace
|
||||||
shouldBeVisibleFrom: DeclarationDescriptor
|
|
||||||
): Pair<PackageViewDescriptor, Int> {
|
): Pair<PackageViewDescriptor, Int> {
|
||||||
val possiblePackagePrefixSize = path.indexOfFirst { it.typeArguments != null }.let { if (it == -1) path.size() else it + 1 }
|
val possiblePackagePrefixSize = path.indexOfFirst { it.typeArguments != null }.let { if (it == -1) path.size() else it + 1 }
|
||||||
var fqName = path.subList(0, possiblePackagePrefixSize).fold(FqName.ROOT) { fqName, qualifierPart ->
|
var fqName = path.subList(0, possiblePackagePrefixSize).fold(FqName.ROOT) { fqName, qualifierPart ->
|
||||||
@@ -165,7 +175,7 @@ public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsag
|
|||||||
while (!fqName.isRoot) {
|
while (!fqName.isRoot) {
|
||||||
val packageDescriptor = getPackage(fqName)
|
val packageDescriptor = getPackage(fqName)
|
||||||
if (!packageDescriptor.isEmpty()) {
|
if (!packageDescriptor.isEmpty()) {
|
||||||
recordPackageViews(path.subList(0, prefixSize), packageDescriptor, trace, shouldBeVisibleFrom)
|
recordPackageViews(path.subList(0, prefixSize), packageDescriptor, trace)
|
||||||
return Pair(packageDescriptor, prefixSize)
|
return Pair(packageDescriptor, prefixSize)
|
||||||
}
|
}
|
||||||
fqName = fqName.parent()
|
fqName = fqName.parent()
|
||||||
@@ -177,11 +187,10 @@ public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsag
|
|||||||
private fun recordPackageViews(
|
private fun recordPackageViews(
|
||||||
path: List<QualifierPart>,
|
path: List<QualifierPart>,
|
||||||
packageView: PackageViewDescriptor,
|
packageView: PackageViewDescriptor,
|
||||||
trace: BindingTrace,
|
trace: BindingTrace
|
||||||
shouldBeVisibleFrom: DeclarationDescriptor
|
|
||||||
) {
|
) {
|
||||||
path.foldRight(packageView) { qualifierPart, currentView ->
|
path.foldRight(packageView) { qualifierPart, currentView ->
|
||||||
storageResult(trace, qualifierPart, listOfNotNull(currentView), shouldBeVisibleFrom)
|
storageResult(trace, qualifierPart.expression, listOfNotNull(currentView), null)
|
||||||
val parentView = currentView.containingDeclaration
|
val parentView = currentView.containingDeclaration
|
||||||
assert(parentView != null) {
|
assert(parentView != null) {
|
||||||
"Containing Declaration must be not null for package with fqName: ${currentView.fqName}, " +
|
"Containing Declaration must be not null for package with fqName: ${currentView.fqName}, " +
|
||||||
@@ -193,12 +202,10 @@ public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsag
|
|||||||
|
|
||||||
private fun storageResult(
|
private fun storageResult(
|
||||||
trace: BindingTrace,
|
trace: BindingTrace,
|
||||||
qualifierPart: QualifierPart,
|
referenceExpression: JetSimpleNameExpression,
|
||||||
descriptors: Collection<DeclarationDescriptor>,
|
descriptors: Collection<DeclarationDescriptor>,
|
||||||
shouldBeVisibleFrom: DeclarationDescriptor
|
shouldBeVisibleFrom: DeclarationDescriptor?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val referenceExpression = qualifierPart.expression
|
|
||||||
if (descriptors.isEmpty()) {
|
if (descriptors.isEmpty()) {
|
||||||
trace.report(Errors.UNRESOLVED_REFERENCE.on(referenceExpression, referenceExpression))
|
trace.report(Errors.UNRESOLVED_REFERENCE.on(referenceExpression, referenceExpression))
|
||||||
}
|
}
|
||||||
@@ -212,11 +219,11 @@ public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsag
|
|||||||
if (descriptor is ClassifierDescriptor) {
|
if (descriptor is ClassifierDescriptor) {
|
||||||
symbolUsageValidator.validateTypeUsage(descriptor, trace, referenceExpression)
|
symbolUsageValidator.validateTypeUsage(descriptor, trace, referenceExpression)
|
||||||
}
|
}
|
||||||
if (descriptor is DeclarationDescriptorWithVisibility) {
|
if (descriptor is DeclarationDescriptorWithVisibility && shouldBeVisibleFrom != null) {
|
||||||
checkVisibility(descriptor, trace, referenceExpression, shouldBeVisibleFrom)
|
checkVisibility(descriptor, trace, referenceExpression, shouldBeVisibleFrom)
|
||||||
}
|
}
|
||||||
|
|
||||||
storageQualifier(trace, qualifierPart.expression, descriptor)
|
storageQualifier(trace, referenceExpression, descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user