[FIR] Refactoring: Introduce base implementations for delegating scopes

- The implementations of some FIR scopes contain a significant amount of
  delegation to some original scope. This pollutes the implementation of
  such scopes and makes them harder to read.
  `FirDelegatingContainingNamesAwareScope` and `FirDelegatingTypeScope`
  can be used as base classes which delegate by default.
This commit is contained in:
Marco Pennekamp
2023-08-23 14:08:04 +02:00
committed by Space Team
parent 3c73331821
commit f64cc184f4
9 changed files with 122 additions and 139 deletions
@@ -329,38 +329,14 @@ internal class KtFirScopeProvider(
private class FirTypeScopeWithSyntheticProperties(
val typeScope: FirTypeScope,
val syntheticPropertiesScope: FirSyntheticPropertiesScope,
) : FirTypeScope() {
) : FirDelegatingTypeScope(typeScope) {
override fun getCallableNames(): Set<Name> = typeScope.getCallableNames() + syntheticPropertiesScope.getCallableNames()
override fun getClassifierNames(): Set<Name> = typeScope.getClassifierNames()
override fun mayContainName(name: Name): Boolean = typeScope.mayContainName(name) || syntheticPropertiesScope.mayContainName(name)
override val scopeOwnerLookupNames: List<String> get() = typeScope.scopeOwnerLookupNames
override fun processDirectOverriddenFunctionsWithBaseScope(
functionSymbol: FirNamedFunctionSymbol,
processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction,
): ProcessorAction = typeScope.processDirectOverriddenFunctionsWithBaseScope(functionSymbol, processor)
override fun processDirectOverriddenPropertiesWithBaseScope(
propertySymbol: FirPropertySymbol,
processor: (FirPropertySymbol, FirTypeScope) -> ProcessorAction,
): ProcessorAction = typeScope.processDirectOverriddenPropertiesWithBaseScope(propertySymbol, processor)
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
typeScope.processClassifiersByNameWithSubstitution(name, processor)
}
override fun processFunctionsByName(name: Name, processor: (FirNamedFunctionSymbol) -> Unit) {
typeScope.processFunctionsByName(name, processor)
}
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
typeScope.processPropertiesByName(name, processor)
syntheticPropertiesScope.processPropertiesByName(name, processor)
}
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
typeScope.processDeclaredConstructors(processor)
}
}
private class EnumEntryContainingNamesAwareScope(private val originalScope: FirContainingNamesAwareScope) : FirContainingNamesAwareScope() {