FIR: distinguish lazy/non-lazy nested scopes more clear
This commit is contained in:
@@ -28,9 +28,7 @@ import org.jetbrains.kotlin.fir.java.scopes.JavaClassUseSiteMemberScope
|
|||||||
import org.jetbrains.kotlin.fir.java.scopes.JavaOverrideChecker
|
import org.jetbrains.kotlin.fir.java.scopes.JavaOverrideChecker
|
||||||
import org.jetbrains.kotlin.fir.resolve.*
|
import org.jetbrains.kotlin.fir.resolve.*
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirSuperTypeScope
|
import org.jetbrains.kotlin.fir.scopes.impl.*
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.nestedClassifierScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.toFirSourceElement
|
import org.jetbrains.kotlin.fir.toFirSourceElement
|
||||||
@@ -69,9 +67,8 @@ class JavaSymbolProvider(
|
|||||||
val symbol = this.getClassLikeSymbolByFqName(classId) ?: return null
|
val symbol = this.getClassLikeSymbolByFqName(classId) ?: return null
|
||||||
val regularClass = symbol.fir
|
val regularClass = symbol.fir
|
||||||
return if (regularClass is FirJavaClass) {
|
return if (regularClass is FirJavaClass) {
|
||||||
nestedClassifierScope(
|
lazyNestedClassifierScope(
|
||||||
classId,
|
classId,
|
||||||
session,
|
|
||||||
existingNames = regularClass.existingNestedClassifierNames,
|
existingNames = regularClass.existingNestedClassifierNames,
|
||||||
symbolProvider = this
|
symbolProvider = this
|
||||||
)
|
)
|
||||||
@@ -110,12 +107,11 @@ class JavaSymbolProvider(
|
|||||||
visitedSymbols: MutableSet<FirClassLikeSymbol<*>>
|
visitedSymbols: MutableSet<FirClassLikeSymbol<*>>
|
||||||
): JavaClassUseSiteMemberScope {
|
): JavaClassUseSiteMemberScope {
|
||||||
return scopeSession.getOrBuild(regularClass.symbol, JAVA_USE_SITE) {
|
return scopeSession.getOrBuild(regularClass.symbol, JAVA_USE_SITE) {
|
||||||
val declaredScope = declaredMemberScope(
|
val declaredScope = if (regularClass is FirJavaClass) declaredMemberScopeWithLazyNestedScope(
|
||||||
regularClass,
|
regularClass,
|
||||||
useLazyNestedClassifierScope = regularClass is FirJavaClass,
|
existingNames = regularClass.existingNestedClassifierNames,
|
||||||
existingNames = (regularClass as? FirJavaClass)?.existingNestedClassifierNames,
|
|
||||||
symbolProvider = this
|
symbolProvider = this
|
||||||
)
|
) else declaredMemberScope(regularClass)
|
||||||
val wrappedDeclaredScope = wrapScopeWithJvmMapped(regularClass, declaredScope, useSiteSession, scopeSession)
|
val wrappedDeclaredScope = wrapScopeWithJvmMapped(regularClass, declaredScope, useSiteSession, scopeSession)
|
||||||
val superTypeEnhancementScopes =
|
val superTypeEnhancementScopes =
|
||||||
lookupSuperTypes(regularClass, lookupInterfaces = true, deep = false, useSiteSession = useSiteSession)
|
lookupSuperTypes(regularClass, lookupInterfaces = true, deep = false, useSiteSession = useSiteSession)
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ class FirClassDeclaredMemberScope(
|
|||||||
symbolProvider: FirSymbolProvider? = null
|
symbolProvider: FirSymbolProvider? = null
|
||||||
) : FirScope() {
|
) : FirScope() {
|
||||||
private val nestedClassifierScope = if (useLazyNestedClassifierScope) {
|
private val nestedClassifierScope = if (useLazyNestedClassifierScope) {
|
||||||
nestedClassifierScope(klass.symbol.classId, klass.session, existingNames, symbolProvider)
|
lazyNestedClassifierScope(klass.symbol.classId, existingNames!!, symbolProvider!!)
|
||||||
} else {
|
} else {
|
||||||
nestedClassifierScope(klass)
|
nestedClassifierScope(klass)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-8
@@ -5,9 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.scopes.impl
|
package org.jetbrains.kotlin.fir.scopes.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||||
@@ -19,18 +17,15 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
// (or make possible to calculate nested classifiers on-the-fly)
|
// (or make possible to calculate nested classifiers on-the-fly)
|
||||||
class FirLazyNestedClassifierScope(
|
class FirLazyNestedClassifierScope(
|
||||||
val classId: ClassId,
|
val classId: ClassId,
|
||||||
session: FirSession,
|
private val existingNames: List<Name>,
|
||||||
private val existingNames: List<Name>?,
|
private val symbolProvider: FirSymbolProvider
|
||||||
symbolProvider: FirSymbolProvider?
|
|
||||||
) : FirScope() {
|
) : FirScope() {
|
||||||
|
|
||||||
private val symbolProvider = symbolProvider ?: session.firSymbolProvider
|
|
||||||
|
|
||||||
override fun processClassifiersByName(
|
override fun processClassifiersByName(
|
||||||
name: Name,
|
name: Name,
|
||||||
processor: (FirClassifierSymbol<*>) -> ProcessorAction
|
processor: (FirClassifierSymbol<*>) -> ProcessorAction
|
||||||
): ProcessorAction {
|
): ProcessorAction {
|
||||||
if (existingNames != null && name !in existingNames) {
|
if (name !in existingNames) {
|
||||||
return ProcessorAction.NONE
|
return ProcessorAction.NONE
|
||||||
}
|
}
|
||||||
val child = classId.createNestedClassId(name)
|
val child = classId.createNestedClassId(name)
|
||||||
|
|||||||
+15
-10
@@ -46,16 +46,22 @@ class FirMemberScopeProvider : FirSessionComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun declaredMemberScope(
|
fun declaredMemberScope(klass: FirClass<*>): FirScope {
|
||||||
|
return klass
|
||||||
|
.session
|
||||||
|
.memberScopeProvider
|
||||||
|
.declaredMemberScope(klass, useLazyNestedClassifierScope = false, existingNames = null, symbolProvider = null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun declaredMemberScopeWithLazyNestedScope(
|
||||||
klass: FirClass<*>,
|
klass: FirClass<*>,
|
||||||
useLazyNestedClassifierScope: Boolean = false,
|
existingNames: List<Name>,
|
||||||
existingNames: List<Name>? = null,
|
symbolProvider: FirSymbolProvider
|
||||||
symbolProvider: FirSymbolProvider? = null
|
|
||||||
): FirScope {
|
): FirScope {
|
||||||
return klass
|
return klass
|
||||||
.session
|
.session
|
||||||
.memberScopeProvider
|
.memberScopeProvider
|
||||||
.declaredMemberScope(klass, useLazyNestedClassifierScope, existingNames, symbolProvider)
|
.declaredMemberScope(klass, useLazyNestedClassifierScope = true, existingNames = existingNames, symbolProvider = symbolProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun nestedClassifierScope(klass: FirClass<*>): FirNestedClassifierScope {
|
fun nestedClassifierScope(klass: FirClass<*>): FirNestedClassifierScope {
|
||||||
@@ -65,13 +71,12 @@ fun nestedClassifierScope(klass: FirClass<*>): FirNestedClassifierScope {
|
|||||||
.nestedClassifierScope(klass)
|
.nestedClassifierScope(klass)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun nestedClassifierScope(
|
fun lazyNestedClassifierScope(
|
||||||
classId: ClassId,
|
classId: ClassId,
|
||||||
session: FirSession,
|
existingNames: List<Name>,
|
||||||
existingNames: List<Name>? = null,
|
symbolProvider: FirSymbolProvider
|
||||||
symbolProvider: FirSymbolProvider? = null
|
|
||||||
): FirLazyNestedClassifierScope {
|
): FirLazyNestedClassifierScope {
|
||||||
return FirLazyNestedClassifierScope(classId, session, existingNames, symbolProvider)
|
return FirLazyNestedClassifierScope(classId, existingNames, symbolProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selfImportingScope(fqName: FqName, session: FirSession): FirSelfImportingScope {
|
fun selfImportingScope(fqName: FqName, session: FirSession): FirSelfImportingScope {
|
||||||
|
|||||||
Reference in New Issue
Block a user