[Analysis API FE1.0] fix constructors in scopes
This commit is contained in:
+14
-9
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.analysis.api.descriptors.types.base.KtFe10Type
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.scopes.KtCompositeScope
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.scopes.KtEmptyScope
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtTypeScope
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFileSymbol
|
||||
@@ -63,21 +62,21 @@ internal class KtFe10ScopeProvider(
|
||||
val descriptor = getDescriptor<ClassDescriptor>(classSymbol)
|
||||
?: return getEmptyScope()
|
||||
|
||||
return KtFe10ScopeMember(descriptor.unsubstitutedMemberScope, analysisContext)
|
||||
return KtFe10ScopeMember(descriptor.unsubstitutedMemberScope, descriptor.constructors, analysisContext)
|
||||
}
|
||||
|
||||
override fun getDeclaredMemberScope(classSymbol: KtSymbolWithMembers): KtScope {
|
||||
val descriptor = getDescriptor<ClassDescriptor>(classSymbol)
|
||||
?: return getEmptyScope()
|
||||
|
||||
return KtFe10ScopeMember(DeclaredMemberScope(descriptor), analysisContext)
|
||||
return KtFe10ScopeMember(DeclaredMemberScope(descriptor), descriptor.constructors, analysisContext)
|
||||
}
|
||||
|
||||
override fun getDelegatedMemberScope(classSymbol: KtSymbolWithMembers): KtScope {
|
||||
val descriptor = getDescriptor<ClassDescriptor>(classSymbol)
|
||||
?: return getEmptyScope()
|
||||
|
||||
return KtFe10ScopeMember(DeclaredMemberScope(descriptor, forDelegatedMembersOnly = true), analysisContext)
|
||||
return KtFe10ScopeMember(DeclaredMemberScope(descriptor, forDelegatedMembersOnly = true), emptyList(), analysisContext)
|
||||
}
|
||||
|
||||
private class DeclaredMemberScope(
|
||||
@@ -90,13 +89,13 @@ internal class KtFe10ScopeProvider(
|
||||
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||
return allMemberScope.getContributedVariables(name, location).filter {
|
||||
it.containingDeclaration == owner && it.isDelegatedIfRequired()
|
||||
it.isDeclaredInOwner() && it.isDelegatedIfRequired()
|
||||
}.mapToDelegatedIfRequired()
|
||||
}
|
||||
|
||||
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
|
||||
return allMemberScope.getContributedFunctions(name, location).filter {
|
||||
it.containingDeclaration == owner && it.isDelegatedIfRequired()
|
||||
it.isDeclaredInOwner() && it.isDelegatedIfRequired()
|
||||
}.mapToDelegatedIfRequired()
|
||||
}
|
||||
|
||||
@@ -125,7 +124,7 @@ internal class KtFe10ScopeProvider(
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
|
||||
if (forDelegatedMembersOnly) return null
|
||||
return allMemberScope.getContributedClassifier(name, location)?.takeIf { it.containingDeclaration == owner }
|
||||
return allMemberScope.getContributedClassifier(name, location)?.takeIf { it.isDeclaredInOwner() }
|
||||
}
|
||||
|
||||
override fun getContributedDescriptors(
|
||||
@@ -133,7 +132,7 @@ internal class KtFe10ScopeProvider(
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
return allMemberScope.getContributedDescriptors(kindFilter, nameFilter).filter {
|
||||
it.containingDeclaration == owner && it.isDelegatedIfRequired()
|
||||
it.isDeclaredInOwner() && it.isDelegatedIfRequired()
|
||||
}.mapToDelegatedIfRequired()
|
||||
}
|
||||
|
||||
@@ -153,11 +152,17 @@ internal class KtFe10ScopeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun DeclarationDescriptor.isDeclaredInOwner() = when (this) {
|
||||
is CallableDescriptor -> dispatchReceiverParameter?.containingDeclaration == owner
|
||||
else -> containingDeclaration == owner
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun getStaticMemberScope(symbol: KtSymbolWithMembers): KtScope {
|
||||
val descriptor = getDescriptor<ClassDescriptor>(symbol) ?: return getEmptyScope()
|
||||
return KtFe10ScopeMember(descriptor.staticScope, analysisContext)
|
||||
return KtFe10ScopeMember(descriptor.staticScope, emptyList(), analysisContext)
|
||||
}
|
||||
|
||||
override fun getEmptyScope(): KtScope {
|
||||
|
||||
+2
-2
@@ -7,17 +7,17 @@ package org.jetbrains.kotlin.analysis.api.descriptors.scopes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisContext
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.KtFe10PackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
|
||||
internal class KtFe10PackageScope(
|
||||
scope: MemberScope,
|
||||
private val owner: KtPackageSymbol,
|
||||
analysisContext: Fe10AnalysisContext
|
||||
) : KtFe10ScopeMember(scope, analysisContext) {
|
||||
) : KtFe10ScopeMember(scope, constructors = emptyList(), analysisContext) {
|
||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||
val packageFragmentProvider = analysisContext.resolveSession.packageFragmentProvider
|
||||
return packageFragmentProvider.getSubPackagesOf(owner.fqName, nameFilter)
|
||||
|
||||
+17
-11
@@ -5,18 +5,18 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.descriptors.scopes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisContext
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
@@ -44,14 +44,6 @@ internal abstract class KtFe10ScopeResolution : KtScope, KtLifetimeOwner {
|
||||
.mapNotNull { it.toKtSymbol(analysisContext) as? KtClassifierSymbol }
|
||||
}
|
||||
|
||||
override fun getConstructors(): Sequence<KtConstructorSymbol> = withValidityAssertion {
|
||||
return scope
|
||||
.getContributedDescriptors(kindFilter = DescriptorKindFilter.FUNCTIONS)
|
||||
.asSequence()
|
||||
.filterIsInstance<ConstructorDescriptor>()
|
||||
.map { it.toKtConstructorSymbol(analysisContext) }
|
||||
}
|
||||
|
||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||
emptySequence()
|
||||
}
|
||||
@@ -71,10 +63,20 @@ internal class KtFe10ScopeLexical(
|
||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||
return emptySet()
|
||||
}
|
||||
|
||||
override fun getConstructors(): Sequence<KtConstructorSymbol> = withValidityAssertion {
|
||||
return scope
|
||||
.getContributedDescriptors(kindFilter = DescriptorKindFilter.FUNCTIONS)
|
||||
.asSequence()
|
||||
.filterIsInstance<ConstructorDescriptor>()
|
||||
.map { it.toKtConstructorSymbol(analysisContext) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal open class KtFe10ScopeMember(
|
||||
override val scope: MemberScope,
|
||||
private val constructors: Collection<ConstructorDescriptor>,
|
||||
override val analysisContext: Fe10AnalysisContext
|
||||
) : KtFe10ScopeResolution() {
|
||||
override fun getPossibleCallableNames(): Set<Name> = withValidityAssertion {
|
||||
@@ -84,4 +86,8 @@ internal open class KtFe10ScopeMember(
|
||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||
return scope.getClassifierNames() ?: emptySet()
|
||||
}
|
||||
|
||||
override fun getConstructors(): Sequence<KtConstructorSymbol> = sequence {
|
||||
constructors.forEach { yield(it.toKtConstructorSymbol(analysisContext)) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user