[PLUGIN API] Add referenceTypeAlias API to IrPluginContext

- attempt to fix KT-40193
This commit is contained in:
Roman Artemev
2020-07-21 16:35:28 +03:00
committed by romanart
parent c4b4912a71
commit edab3e3ba9
2 changed files with 12 additions and 4 deletions
@@ -9,10 +9,7 @@ import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.builders.IrGeneratorContext
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.TypeTranslator
import org.jetbrains.kotlin.name.FqName
@@ -40,6 +37,7 @@ interface IrPluginContext : IrGeneratorContext {
// The following API is experimental
fun referenceClass(fqName: FqName): IrClassSymbol?
fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol?
fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol>
fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol>
fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol>
@@ -85,6 +85,16 @@ open class IrPluginContextImpl(
}
}
override fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol? {
assert(!fqName.isRoot)
return resolveSymbol(fqName.parent()) { scope ->
val aliasDescriptor = scope.getContributedClassifier(fqName.shortName(), NoLookupLocation.FROM_BACKEND) as? TypeAliasDescriptor?
aliasDescriptor?.let {
st.referenceTypeAlias(it)
}
}
}
override fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol> {
val classSymbol = referenceClass(classFqn) ?: error("Cannot find class $classFqn")
return classSymbol.owner.declarations.filterIsInstance<IrConstructor>().map { it.symbol }