[FIR] Inherit FirContainingNamesAwareScope from FirScope

This is needed to simplify FirScope hierarchy, because in
  fact all inheritors of `FirContainingNamesAwareScope` were
  inheritors of `FirScope` too
This commit is contained in:
Dmitriy Novozhilov
2021-09-28 12:53:32 +03:00
committed by TeamCityServer
parent f3a9d70eb6
commit 9bfa6c54b8
20 changed files with 32 additions and 39 deletions
@@ -11,7 +11,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>) : FirScope(), FirContainingNamesAwareScope {
class FirCompositeScope(val scopes: Iterable<FirScope>) : FirContainingNamesAwareScope() {
override fun processClassifiersByNameWithSubstitution(
name: Name,
@@ -5,15 +5,14 @@
package org.jetbrains.kotlin.fir.scopes
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
import org.jetbrains.kotlin.name.Name
interface FirContainingNamesAwareScope {
fun getCallableNames(): Set<Name>
abstract class FirContainingNamesAwareScope : FirScope() {
abstract fun getCallableNames(): Set<Name>
fun getClassifierNames(): Set<Name>
abstract fun getClassifierNames(): Set<Name>
}
fun FirScope.getContainingCallableNamesIfPresent(): Set<Name> =
@@ -22,19 +21,19 @@ fun FirScope.getContainingCallableNamesIfPresent(): Set<Name> =
fun FirScope.getContainingClassifierNamesIfPresent(): Set<Name> =
if (this is FirContainingNamesAwareScope) getClassifierNames() else emptySet()
fun <S> S.processAllFunctions(processor: (FirNamedFunctionSymbol) -> Unit) where S : FirScope, S : FirContainingNamesAwareScope {
fun FirContainingNamesAwareScope.processAllFunctions(processor: (FirNamedFunctionSymbol) -> Unit) {
for (name in getCallableNames()) {
processFunctionsByName(name, processor)
}
}
fun <S> S.processAllProperties(processor: (FirVariableSymbol<*>) -> Unit) where S : FirScope, S : FirContainingNamesAwareScope {
fun FirContainingNamesAwareScope.processAllProperties(processor: (FirVariableSymbol<*>) -> Unit) {
for (name in getCallableNames()) {
processPropertiesByName(name, processor)
}
}
fun <S> S.collectAllProperties(): Collection<FirVariableSymbol<*>> where S : FirScope, S : FirContainingNamesAwareScope {
fun FirContainingNamesAwareScope.collectAllProperties(): Collection<FirVariableSymbol<*>> {
return mutableListOf<FirVariableSymbol<*>>().apply {
processAllProperties(this::add)
}
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.name.Name
abstract class FirTypeScope : FirScope(), FirContainingNamesAwareScope {
abstract class FirTypeScope : FirContainingNamesAwareScope() {
// If the scope instance is the same as the one from which the symbol was originated, this function supplies
// all direct overridden members (each of them comes a base scope where grand-parents [overridden of this overridden] may be obtained from)
//
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.Name
class FirUnstableSmartcastTypeScope(
private val smartcastScope: FirTypeScope,
private val originalScope: FirTypeScope
) : FirTypeScope(), FirContainingNamesAwareScope {
) : FirTypeScope() {
private val scopes = listOf(originalScope, smartcastScope)
private val symbolsFromUnstableSmartcast = mutableSetOf<FirCallableSymbol<*>>()
override fun processClassifiersByNameWithSubstitution(