Remove BindingContext, KotlinType and *Descriptor from IR plugin dependencies

This commit is contained in:
Leonid Startsev
2022-06-22 21:58:59 +02:00
committed by Space
parent 6f6342dafc
commit cefc372632
27 changed files with 1185 additions and 504 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.scopes.*
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
@@ -41,6 +42,7 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
override val moduleDescriptor: ModuleDescriptor
get() = error(ERROR_MESSAGE)
@Suppress("OVERRIDE_DEPRECATION")
@ObsoleteDescriptorBasedAPI
override val bindingContext: BindingContext
get() = error(ERROR_MESSAGE)
@@ -67,7 +69,8 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
get() = components.session.symbolProvider
override fun referenceClass(classId: ClassId): IrClassSymbol? {
return referenceClassLikeSymbol(classId, symbolProvider::getClassLikeSymbolByClassId, symbolTable::referenceClass)
val firSymbol = symbolProvider.getClassLikeSymbolByClassId(classId) as? FirClassSymbol<*> ?: return null
return components.classifierStorage.getIrClassSymbol(firSymbol)
}
override fun referenceTypeAlias(classId: ClassId): IrTypeAliasSymbol? {
@@ -135,6 +138,8 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
error(ERROR_MESSAGE)
}
@Deprecated("Use classId overload instead")
override fun referenceClass(fqName: FqName): IrClassSymbol? {
error(ERROR_MESSAGE)
}
@@ -147,10 +152,12 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
error(ERROR_MESSAGE)
}
@Deprecated("Use callableId overload instead")
override fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol> {
error(ERROR_MESSAGE)
}
@Deprecated("Use callableId overload instead")
override fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol> {
error(ERROR_MESSAGE)
}
@@ -29,11 +29,13 @@ interface IrPluginContext : IrGeneratorContext {
val moduleDescriptor: ModuleDescriptor
@ObsoleteDescriptorBasedAPI
@Deprecated("", level = DeprecationLevel.ERROR)
val bindingContext: BindingContext
val symbolTable: ReferenceSymbolTable
@ObsoleteDescriptorBasedAPI
// @Deprecated("", level = DeprecationLevel.ERROR)
val typeTranslator: TypeTranslator
val symbols: BuiltinSymbolsBase
@@ -49,10 +51,13 @@ interface IrPluginContext : IrGeneratorContext {
fun createDiagnosticReporter(pluginId: String): IrMessageLogger
// The following API is experimental
@Deprecated("Use classId overload instead")
fun referenceClass(fqName: FqName): IrClassSymbol?
fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol?
fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol>
@Deprecated("Use callableId overload instead")
fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol>
@Deprecated("Use callableId overload instead")
fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol>
// This one is experimental too
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
open class IrPluginContextImpl constructor(
private val module: ModuleDescriptor,
@Deprecated("", level = DeprecationLevel.ERROR)
@OptIn(ObsoleteDescriptorBasedAPI::class)
override val bindingContext: BindingContext,
override val languageVersionSettings: LanguageVersionSettings,
@@ -97,6 +98,7 @@ open class IrPluginContextImpl constructor(
return symbols
}
@Deprecated("Use classId overload instead")
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun referenceClass(fqName: FqName): IrClassSymbol? {
assert(!fqName.isRoot)
@@ -120,10 +122,12 @@ open class IrPluginContextImpl constructor(
}
override fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol> {
@Suppress("DEPRECATION")
val classSymbol = referenceClass(classFqn) ?: error("Cannot find class $classFqn")
return classSymbol.owner.declarations.filterIsInstance<IrConstructor>().map { it.symbol }
}
@Deprecated("Use callableId overload instead")
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol> {
assert(!fqName.isRoot)
@@ -133,6 +137,7 @@ open class IrPluginContextImpl constructor(
}
}
@Deprecated("Use callableId overload instead")
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol> {
assert(!fqName.isRoot)
@@ -143,6 +148,7 @@ open class IrPluginContextImpl constructor(
}
override fun referenceClass(classId: ClassId): IrClassSymbol? {
@Suppress("DEPRECATION")
return referenceClass(classId.asSingleFqName())
}
@@ -155,10 +161,12 @@ open class IrPluginContextImpl constructor(
}
override fun referenceFunctions(callableId: CallableId): Collection<IrSimpleFunctionSymbol> {
@Suppress("DEPRECATION")
return referenceFunctions(callableId.asSingleFqName())
}
override fun referenceProperties(callableId: CallableId): Collection<IrPropertySymbol> {
@Suppress("DEPRECATION")
return referenceProperties(callableId.asSingleFqName())
}