FIR: Avoid creating empty nested classes scopes
This commit is contained in:
+2
-2
@@ -48,11 +48,11 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(
|
||||
firClass.addTypeParametersScope()
|
||||
val companionObject = firClass.companionObject
|
||||
if (companionObject != null) {
|
||||
towerScope.addScope(nestedClassifierScope(companionObject))
|
||||
nestedClassifierScope(companionObject)?.let(towerScope::addScope)
|
||||
}
|
||||
}
|
||||
|
||||
towerScope.addScope(nestedClassifierScope(firClass))
|
||||
nestedClassifierScope(firClass)?.let(towerScope::addScope)
|
||||
|
||||
transformElement(firClass, data)
|
||||
}
|
||||
|
||||
+2
-2
@@ -133,9 +133,9 @@ private fun createScopesForNestedClasses(
|
||||
addIfNotNull(klass.typeParametersScope())
|
||||
val companionObjects = klass.declarations.filterIsInstance<FirRegularClass>().filter { it.isCompanion }
|
||||
for (companionObject in companionObjects) {
|
||||
add(nestedClassifierScope(companionObject))
|
||||
addIfNotNull(nestedClassifierScope(companionObject))
|
||||
}
|
||||
add(nestedClassifierScope(klass))
|
||||
addIfNotNull(nestedClassifierScope(klass))
|
||||
}
|
||||
|
||||
fun FirRegularClass.resolveSupertypesInTheAir(session: FirSession): List<FirTypeRef> {
|
||||
|
||||
+3
-1
@@ -72,5 +72,7 @@ class FirClassDeclaredMemberScope(
|
||||
override fun processClassifiersByNameWithSubstitution(
|
||||
name: Name,
|
||||
processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit
|
||||
) = nestedClassifierScope.processClassifiersByNameWithSubstitution(name, processor)
|
||||
) {
|
||||
nestedClassifierScope?.processClassifiersByNameWithSubstitution(name, processor)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -13,11 +13,12 @@ import org.jetbrains.kotlin.fir.resolve.declaredMemberScopeProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.getOrPutNullable
|
||||
|
||||
class FirDeclaredMemberScopeProvider : FirSessionComponent {
|
||||
|
||||
private val declaredMemberCache = mutableMapOf<FirClass<*>, FirScope>()
|
||||
private val nestedClassifierCache = mutableMapOf<FirClass<*>, FirNestedClassifierScope>()
|
||||
private val nestedClassifierCache = mutableMapOf<FirClass<*>, FirNestedClassifierScope?>()
|
||||
|
||||
fun getClassByClassId(classId: ClassId): FirClass<*>? {
|
||||
for ((clazz, _) in declaredMemberCache) {
|
||||
@@ -48,9 +49,9 @@ class FirDeclaredMemberScopeProvider : FirSessionComponent {
|
||||
}
|
||||
}
|
||||
|
||||
fun nestedClassifierScope(klass: FirClass<*>): FirNestedClassifierScope {
|
||||
return nestedClassifierCache.getOrPut(klass) {
|
||||
FirNestedClassifierScope(klass)
|
||||
fun nestedClassifierScope(klass: FirClass<*>): FirNestedClassifierScope? {
|
||||
return nestedClassifierCache.getOrPutNullable(klass) {
|
||||
FirNestedClassifierScope(klass).takeUnless { it.isEmpty() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +74,7 @@ fun declaredMemberScopeWithLazyNestedScope(
|
||||
.declaredMemberScope(klass, useLazyNestedClassifierScope = true, existingNames = existingNames, symbolProvider = symbolProvider)
|
||||
}
|
||||
|
||||
fun nestedClassifierScope(klass: FirClass<*>): FirNestedClassifierScope {
|
||||
fun nestedClassifierScope(klass: FirClass<*>): FirNestedClassifierScope? {
|
||||
return klass
|
||||
.session
|
||||
.declaredMemberScopeProvider
|
||||
@@ -84,7 +85,8 @@ fun lazyNestedClassifierScope(
|
||||
classId: ClassId,
|
||||
existingNames: List<Name>,
|
||||
symbolProvider: FirSymbolProvider
|
||||
): FirLazyNestedClassifierScope {
|
||||
): FirLazyNestedClassifierScope? {
|
||||
if (existingNames.isEmpty()) return null
|
||||
return FirLazyNestedClassifierScope(classId, existingNames, symbolProvider)
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -25,6 +25,8 @@ class FirNestedClassifierScope(val klass: FirClass<*>) : FirScope() {
|
||||
result
|
||||
}
|
||||
|
||||
fun isEmpty() = classIndex.isEmpty()
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(
|
||||
name: Name,
|
||||
processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit
|
||||
|
||||
Reference in New Issue
Block a user