[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:
Dmitriy Novozhilov
2021-10-11 15:36:34 +03:00
committed by TeamCityServer
parent 5f625f3c16
commit b4d955838e
27 changed files with 159 additions and 116 deletions
@@ -12,8 +12,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
import org.jetbrains.kotlin.name.Name
class FirCompositeScope(val scopes: Iterable<FirScope>) : FirContainingNamesAwareScope() {
class FirCompositeScope(val scopes: Iterable<FirScope>) : FirScope() {
override fun processClassifiersByNameWithSubstitution(
name: Name,
processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit
@@ -64,15 +63,41 @@ class FirCompositeScope(val scopes: Iterable<FirScope>) : FirContainingNamesAwar
processComposite(FirScope::processDeclaredConstructors, processor)
}
override fun getCallableNames(): Set<Name> {
return scopes.flatMapTo(hashSetOf()) { it.getContainingCallableNamesIfPresent() }
}
override fun getClassifierNames(): Set<Name> {
return scopes.flatMapTo(hashSetOf()) { it.getContainingClassifierNamesIfPresent() }
}
override val scopeOwnerLookupNames: List<String> by lazy(LazyThreadSafetyMode.PUBLICATION) {
scopes.flatMap { it.scopeOwnerLookupNames }
}
}
class FirNameAwareCompositeScope(val scopes: Iterable<FirContainingNamesAwareScope>) : FirContainingNamesAwareScope() {
private val delegate = FirCompositeScope(scopes)
override fun processClassifiersByNameWithSubstitution(
name: Name,
processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit
) {
delegate.processClassifiersByNameWithSubstitution(name, processor)
}
override fun processFunctionsByName(name: Name, processor: (FirNamedFunctionSymbol) -> Unit) {
delegate.processFunctionsByName(name, processor)
}
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
delegate.processPropertiesByName(name, processor)
}
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
delegate.processDeclaredConstructors(processor)
}
override val scopeOwnerLookupNames: List<String>
get() = delegate.scopeOwnerLookupNames
override fun getCallableNames(): Set<Name> {
return scopes.flatMapTo(hashSetOf()) { it.getCallableNames() }
}
override fun getClassifierNames(): Set<Name> {
return scopes.flatMapTo(hashSetOf()) { it.getClassifierNames() }
}
}
@@ -15,12 +15,6 @@ abstract class FirContainingNamesAwareScope : FirScope() {
abstract fun getClassifierNames(): Set<Name>
}
fun FirScope.getContainingCallableNamesIfPresent(): Set<Name> =
if (this is FirContainingNamesAwareScope) getCallableNames() else emptySet()
fun FirScope.getContainingClassifierNamesIfPresent(): Set<Name> =
if (this is FirContainingNamesAwareScope) getClassifierNames() else emptySet()
fun FirContainingNamesAwareScope.processAllFunctions(processor: (FirNamedFunctionSymbol) -> Unit) {
for (name in getCallableNames()) {
processFunctionsByName(name, processor)
@@ -20,25 +20,25 @@ abstract class FirScopeProvider {
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirScope?
): FirContainingNamesAwareScope?
abstract fun getNestedClassifierScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirScope?
): FirContainingNamesAwareScope?
fun getStaticScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirScope? {
): FirContainingNamesAwareScope? {
val nestedClassifierScope = getNestedClassifierScope(klass, useSiteSession, scopeSession)
val callableScope = getStaticMemberScopeForCallables(klass, useSiteSession, scopeSession)
return when {
nestedClassifierScope != null && callableScope != null ->
FirCompositeScope(listOf(nestedClassifierScope, callableScope))
FirNameAwareCompositeScope(listOf(nestedClassifierScope, callableScope))
else -> nestedClassifierScope ?: callableScope
}
}
@@ -102,11 +102,11 @@ class FirUnstableSmartcastTypeScope(
}
override fun getCallableNames(): Set<Name> {
return scopes.flatMapTo(hashSetOf()) { it.getContainingCallableNamesIfPresent() }
return scopes.flatMapTo(hashSetOf()) { it.getCallableNames() }
}
override fun getClassifierNames(): Set<Name> {
return scopes.flatMapTo(hashSetOf()) { it.getContainingClassifierNamesIfPresent() }
return scopes.flatMapTo(hashSetOf()) { it.getClassifierNames() }
}
override val scopeOwnerLookupNames: List<String> by lazy(LazyThreadSafetyMode.PUBLICATION) {