FIR: move getCallableNames/getClassifierNames from scope to FirContainingNamesAwareScope

This commit is contained in:
Ilya Kirillov
2020-08-07 13:00:43 +03:00
parent 36a161080f
commit f62204fff1
27 changed files with 247 additions and 146 deletions
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
import org.jetbrains.kotlin.name.Name
class FirCompositeScope(val scopes: Iterable<FirScope>) : FirScope() {
class FirCompositeScope(val scopes: Iterable<FirScope>) : FirScope(), FirContainingNamesAwareScope {
override fun processClassifiersByNameWithSubstitution(
name: Name,
@@ -46,10 +46,10 @@ class FirCompositeScope(val scopes: Iterable<FirScope>) : FirScope() {
}
override fun getCallableNames(): Set<Name> {
return scopes.flatMapTo(mutableSetOf()) { it.getCallableNames() }
return scopes.flatMapTo(hashSetOf()) { it.getContainingCallableNamesIfPresent() }
}
override fun getClassifierNames(): Set<Name> {
return scopes.flatMapTo(hashSetOf()) { it.getClassifierNames() }
return scopes.flatMapTo(hashSetOf()) { it.getContainingClassifierNamesIfPresent() }
}
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.scopes
import org.jetbrains.kotlin.name.Name
interface FirContainingNamesAwareScope {
fun getCallableNames(): Set<Name>
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()
@@ -33,10 +33,6 @@ abstract class FirScope {
) {}
open fun mayContainName(name: Name) = true
open fun getCallableNames(): Set<Name> = emptySet()
open fun getClassifierNames(): Set<Name> = emptySet()
}
fun FirTypeScope.processOverriddenFunctionsAndSelf(
@@ -8,8 +8,9 @@ package org.jetbrains.kotlin.fir.scopes
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.name.Name
abstract class FirTypeScope : FirScope() {
abstract class FirTypeScope : FirScope(), FirContainingNamesAwareScope {
// Currently, this function and its property brother both have very weak guarantees
// - It may silently do nothing on symbols originated from different scope instance
// - It may return the same overridden symbols more then once in case of substitution
@@ -96,5 +97,9 @@ abstract class FirTypeScope : FirScope() {
propertySymbol: FirPropertySymbol,
processor: (FirPropertySymbol, Int) -> ProcessorAction
): ProcessorAction = ProcessorAction.NEXT
override fun getCallableNames(): Set<Name> = emptySet()
override fun getClassifierNames(): Set<Name> = emptySet()
}
}