[Plugin API] Provide diagnostic API for IR plugins
This commit is contained in:
+9
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.builders.IrGeneratorContext
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -36,6 +37,14 @@ interface IrPluginContext : IrGeneratorContext {
|
||||
|
||||
val platform: TargetPlatform?
|
||||
|
||||
/**
|
||||
* Returns a logger instance to post diagnostic messages from plugin
|
||||
*
|
||||
* @param pluginId the unique plugin ID to make it easy to distinguish in log
|
||||
* @return the logger associated with specified ID
|
||||
*/
|
||||
fun createDiagnosticReporter(pluginId: String): IrMessageLogger
|
||||
|
||||
// The following API is experimental
|
||||
fun referenceClass(fqName: FqName): IrClassSymbol?
|
||||
fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol?
|
||||
|
||||
+14
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -33,6 +34,7 @@ open class IrPluginContextImpl constructor(
|
||||
override val typeTranslator: TypeTranslator,
|
||||
override val irBuiltIns: IrBuiltIns,
|
||||
val linker: IrDeserializer,
|
||||
private val diagnosticReporter: IrMessageLogger,
|
||||
override val symbols: BuiltinSymbolsBase = BuiltinSymbolsBase(irBuiltIns, irBuiltIns.builtIns, st)
|
||||
) : IrPluginContext {
|
||||
|
||||
@@ -68,6 +70,18 @@ open class IrPluginContextImpl constructor(
|
||||
return symbol
|
||||
}
|
||||
|
||||
override fun createDiagnosticReporter(pluginId: String): IrMessageLogger {
|
||||
return object : IrMessageLogger {
|
||||
override fun report(
|
||||
severity: IrMessageLogger.Severity,
|
||||
message: String,
|
||||
location: IrMessageLogger.Location?
|
||||
) {
|
||||
diagnosticReporter.report(severity, "[Plugin $pluginId] $message", location)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <S : IrSymbol> resolveSymbolCollection(fqName: FqName, referencer: (MemberScope) -> Collection<S>): Collection<S> {
|
||||
val memberScope = resolveMemberScope(fqName) ?: return emptyList()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user