[FIR] Properly use FirContainingNamesAwareScope in all places
Split some delegating scopes to basic and name aware implementations Also get rid of getContainingCallableNamesIfPresent and getContainingClassifierNamesIfPresent functions because they are not needed anymore
This commit is contained in:
committed by
TeamCityServer
parent
5f625f3c16
commit
b4d955838e
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes
|
||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
|
||||
import org.jetbrains.kotlin.fir.java.scopes.*
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.*
|
||||
@@ -68,7 +68,7 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildDeclaredMemberScope(useSiteSession: FirSession, regularClass: FirRegularClass): FirScope {
|
||||
private fun buildDeclaredMemberScope(useSiteSession: FirSession, regularClass: FirRegularClass): FirContainingNamesAwareScope {
|
||||
return if (regularClass is FirJavaClass) useSiteSession.declaredMemberScopeWithLazyNestedScope(
|
||||
regularClass,
|
||||
existingNames = regularClass.existingNestedClassifierNames,
|
||||
@@ -112,9 +112,9 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
klass: FirClass,
|
||||
useSiteSession: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
): FirScope? {
|
||||
): FirContainingNamesAwareScope? {
|
||||
val scope = getStaticMemberScopeForCallables(klass, useSiteSession, scopeSession, hashSetOf()) ?: return null
|
||||
return FirOnlyCallablesScope(FirStaticScope(scope))
|
||||
return FirNameAwareOnlyCallablesScope(FirStaticScope(scope))
|
||||
}
|
||||
|
||||
private fun getStaticMemberScopeForCallables(
|
||||
@@ -193,7 +193,11 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getNestedClassifierScope(klass: FirClass, useSiteSession: FirSession, scopeSession: ScopeSession): FirScope? {
|
||||
override fun getNestedClassifierScope(
|
||||
klass: FirClass,
|
||||
useSiteSession: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
): FirContainingNamesAwareScope? {
|
||||
return lazyNestedClassifierScope(
|
||||
klass.classId,
|
||||
(klass as FirJavaClass).existingNestedClassifierNames,
|
||||
|
||||
+7
-9
@@ -8,8 +8,6 @@ package org.jetbrains.kotlin.fir.java.scopes
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
|
||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.getContainingCallableNamesIfPresent
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.isStatic
|
||||
@@ -18,9 +16,9 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
class JavaClassStaticUseSiteScope internal constructor(
|
||||
session: FirSession,
|
||||
private val declaredMemberScope: FirScope,
|
||||
private val superClassScope: FirScope,
|
||||
private val superTypesScopes: List<FirScope>,
|
||||
private val declaredMemberScope: FirContainingNamesAwareScope,
|
||||
private val superClassScope: FirContainingNamesAwareScope,
|
||||
private val superTypesScopes: List<FirContainingNamesAwareScope>,
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
) : FirContainingNamesAwareScope() {
|
||||
private val functions = hashMapOf<Name, Collection<FirNamedFunctionSymbol>>()
|
||||
@@ -84,9 +82,9 @@ class JavaClassStaticUseSiteScope internal constructor(
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override fun getCallableNames(): Set<Name> {
|
||||
return buildSet {
|
||||
addAll(declaredMemberScope.getContainingCallableNamesIfPresent())
|
||||
addAll(declaredMemberScope.getCallableNames())
|
||||
for (superTypesScope in superTypesScopes) {
|
||||
addAll(superTypesScope.getContainingCallableNamesIfPresent())
|
||||
addAll(superTypesScope.getCallableNames())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,9 +92,9 @@ class JavaClassStaticUseSiteScope internal constructor(
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override fun getClassifierNames(): Set<Name> {
|
||||
return buildSet {
|
||||
addAll(declaredMemberScope.getContainingCallableNamesIfPresent())
|
||||
addAll(declaredMemberScope.getClassifierNames())
|
||||
for (superTypesScope in superTypesScopes) {
|
||||
addAll(superTypesScope.getContainingCallableNamesIfPresent())
|
||||
addAll(superTypesScope.getClassifierNames())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -41,7 +41,7 @@ class JavaClassUseSiteMemberScope(
|
||||
klass: FirJavaClass,
|
||||
session: FirSession,
|
||||
superTypesScope: FirTypeScope,
|
||||
declaredMemberScope: FirScope
|
||||
declaredMemberScope: FirContainingNamesAwareScope
|
||||
) : AbstractFirUseSiteMemberScope(
|
||||
session,
|
||||
JavaOverrideChecker(session, klass.javaTypeParameterStack),
|
||||
@@ -55,13 +55,13 @@ class JavaClassUseSiteMemberScope(
|
||||
private val canUseSpecialGetters: Boolean by lazy { !klass.hasKotlinSuper(session) }
|
||||
|
||||
private val callableNamesCached by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
declaredMemberScope.getContainingCallableNamesIfPresent() + superTypesScope.getCallableNames()
|
||||
declaredMemberScope.getCallableNames() + superTypesScope.getCallableNames()
|
||||
}
|
||||
|
||||
override fun getCallableNames(): Set<Name> = callableNamesCached
|
||||
|
||||
override fun getClassifierNames(): Set<Name> {
|
||||
return declaredMemberScope.getContainingClassifierNamesIfPresent() + superTypesScope.getClassifierNames()
|
||||
return declaredMemberScope.getClassifierNames() + superTypesScope.getClassifierNames()
|
||||
}
|
||||
|
||||
private fun generateAccessorSymbol(
|
||||
|
||||
@@ -12,20 +12,19 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
||||
import org.jetbrains.kotlin.fir.scopes.jvm.JvmMappedScope
|
||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
|
||||
|
||||
fun wrapScopeWithJvmMapped(
|
||||
klass: FirClass,
|
||||
declaredMemberScope: FirScope,
|
||||
declaredMemberScope: FirContainingNamesAwareScope,
|
||||
useSiteSession: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
): FirScope {
|
||||
): FirContainingNamesAwareScope {
|
||||
val classId = klass.classId
|
||||
val kotlinUnsafeFqName = classId.asSingleFqName().toUnsafe()
|
||||
val javaClassId = JavaToKotlinClassMap.mapKotlinToJava(kotlinUnsafeFqName)
|
||||
|
||||
@@ -13,7 +13,9 @@ import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
|
||||
import org.jetbrains.kotlin.fir.scopes.*
|
||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
@@ -26,7 +28,7 @@ class JvmMappedScope(
|
||||
private val session: FirSession,
|
||||
private val firKotlinClass: FirClass,
|
||||
private val firJavaClass: FirRegularClass,
|
||||
private val declaredMemberScope: FirScope,
|
||||
private val declaredMemberScope: FirContainingNamesAwareScope,
|
||||
private val javaMappedClassUseSiteScope: FirTypeScope,
|
||||
private val signatures: Signatures
|
||||
) : FirTypeScope() {
|
||||
@@ -116,11 +118,11 @@ class JvmMappedScope(
|
||||
}
|
||||
|
||||
override fun getCallableNames(): Set<Name> {
|
||||
return declaredMemberScope.getContainingCallableNamesIfPresent() + signatures.visibleMethodSignaturesByName.keys
|
||||
return declaredMemberScope.getCallableNames() + signatures.visibleMethodSignaturesByName.keys
|
||||
}
|
||||
|
||||
override fun getClassifierNames(): Set<Name> {
|
||||
return declaredMemberScope.getContainingClassifierNamesIfPresent()
|
||||
return declaredMemberScope.getClassifierNames()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user