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