[FIR2IR] Minor fixes in Fir2IrPluginContext

This commit is contained in:
Dmitriy Novozhilov
2022-06-17 10:20:04 +03:00
committed by teamcity
parent f7e0880c34
commit 1a5b6a1bde
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.scopes.* import org.jetbrains.kotlin.fir.scopes.*
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.ir.IrBuiltIns import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
@@ -32,17 +33,21 @@ import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginContext { class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginContext {
companion object {
private const val ERROR_MESSAGE = "This API is not supported for K2"
}
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
override val moduleDescriptor: ModuleDescriptor override val moduleDescriptor: ModuleDescriptor
get() = error("Should not be called") get() = error(ERROR_MESSAGE)
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
override val bindingContext: BindingContext override val bindingContext: BindingContext
get() = error("Should not be called") get() = error(ERROR_MESSAGE)
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
override val typeTranslator: TypeTranslator override val typeTranslator: TypeTranslator
get() = error("Should not be called") get() = error(ERROR_MESSAGE)
override val languageVersionSettings: LanguageVersionSettings override val languageVersionSettings: LanguageVersionSettings
get() = components.session.languageVersionSettings get() = components.session.languageVersionSettings
@@ -94,7 +99,7 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
getCallablesFromScope = { getFunctions(callableId.callableName) }, getCallablesFromScope = { getFunctions(callableId.callableName) },
getCallablesFromProvider = { getTopLevelFunctionSymbols(callableId.packageName, callableId.callableName) }, getCallablesFromProvider = { getTopLevelFunctionSymbols(callableId.packageName, callableId.callableName) },
Fir2IrDeclarationStorage::getIrFunctionSymbol Fir2IrDeclarationStorage::getIrFunctionSymbol
).filterIsInstance<IrSimpleFunctionSymbol>() )
} }
override fun referenceProperties(callableId: CallableId): Collection<IrPropertySymbol> { override fun referenceProperties(callableId: CallableId): Collection<IrPropertySymbol> {
@@ -103,15 +108,15 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
getCallablesFromScope = { getProperties(callableId.callableName).filterIsInstance<FirPropertySymbol>() }, getCallablesFromScope = { getProperties(callableId.callableName).filterIsInstance<FirPropertySymbol>() },
getCallablesFromProvider = { getTopLevelPropertySymbols(callableId.packageName, callableId.callableName) }, getCallablesFromProvider = { getTopLevelPropertySymbols(callableId.packageName, callableId.callableName) },
Fir2IrDeclarationStorage::getIrPropertySymbol Fir2IrDeclarationStorage::getIrPropertySymbol
).filterIsInstance<IrPropertySymbol>() )
} }
private inline fun <F, S> referenceCallableSymbols( private inline fun <F : FirCallableSymbol<*>, S : IrSymbol, reified R : S> referenceCallableSymbols(
classId: ClassId?, classId: ClassId?,
getCallablesFromScope: FirTypeScope.() -> Collection<F>, getCallablesFromScope: FirTypeScope.() -> Collection<F>,
getCallablesFromProvider: FirSymbolProvider.() -> Collection<F>, getCallablesFromProvider: FirSymbolProvider.() -> Collection<F>,
irExtractor: Fir2IrDeclarationStorage.(F) -> S?, irExtractor: Fir2IrDeclarationStorage.(F) -> S?,
): Collection<S> { ): Collection<R> {
val callables = if (classId != null) { val callables = if (classId != null) {
val expandedClass = symbolProvider.getClassLikeSymbolByClassId(classId) val expandedClass = symbolProvider.getClassLikeSymbolByClassId(classId)
?.fullyExpandedClass(components.session) ?.fullyExpandedClass(components.session)
@@ -123,33 +128,31 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
symbolProvider.getCallablesFromProvider() symbolProvider.getCallablesFromProvider()
} }
return callables.mapNotNull { return callables.mapNotNull { components.declarationStorage.irExtractor(it) }.filterIsInstance<R>()
components.declarationStorage.irExtractor(it)
}
} }
override fun createDiagnosticReporter(pluginId: String): IrMessageLogger { override fun createDiagnosticReporter(pluginId: String): IrMessageLogger {
error("Should not be called") error(ERROR_MESSAGE)
} }
override fun referenceClass(fqName: FqName): IrClassSymbol? { override fun referenceClass(fqName: FqName): IrClassSymbol? {
error("Should not be called") error(ERROR_MESSAGE)
} }
override fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol? { override fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol? {
error("Should not be called") error(ERROR_MESSAGE)
} }
override fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol> { override fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol> {
error("Should not be called") error(ERROR_MESSAGE)
} }
override fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol> { override fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol> {
error("Should not be called") error(ERROR_MESSAGE)
} }
override fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol> { override fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol> {
error("Should not be called") error(ERROR_MESSAGE)
} }
override fun referenceTopLevel( override fun referenceTopLevel(
@@ -157,6 +160,6 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
kind: IrDeserializer.TopLevelSymbolKind, kind: IrDeserializer.TopLevelSymbolKind,
moduleDescriptor: ModuleDescriptor moduleDescriptor: ModuleDescriptor
): IrSymbol? { ): IrSymbol? {
error("Should not be called") error(ERROR_MESSAGE)
} }
} }