[FIR/IR] Introduce an ability to propagate generated IR annotation to metadata
^KT-58638 Fixed
This commit is contained in:
committed by
Space Team
parent
24e07fdfe0
commit
5717b59f52
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.extensions
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
|
||||
abstract class IrAnnotationsFromPluginRegistrar {
|
||||
abstract fun addMetadataVisibleAnnotationsToElement(declaration: IrDeclaration, annotations: List<IrConstructorCall>)
|
||||
|
||||
fun addMetadataVisibleAnnotationsToElement(declaration: IrDeclaration, vararg annotations: IrConstructorCall) {
|
||||
addMetadataVisibleAnnotationsToElement(declaration, annotations.toList())
|
||||
}
|
||||
}
|
||||
+6
@@ -56,6 +56,12 @@ interface IrPluginContext : IrGeneratorContext {
|
||||
|
||||
val platform: TargetPlatform?
|
||||
|
||||
/**
|
||||
* Use this service to add annotations to declarations if those annotations should be saved into metadata
|
||||
* This service properly works only in K2 compiler
|
||||
*/
|
||||
val annotationsRegistrar: IrAnnotationsFromPluginRegistrar
|
||||
|
||||
/**
|
||||
* Returns a logger instance to post diagnostic messages from plugin
|
||||
*
|
||||
|
||||
+11
-1
@@ -14,6 +14,8 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
@@ -51,6 +53,9 @@ open class IrPluginContextImpl constructor(
|
||||
|
||||
override val symbolTable: ReferenceSymbolTable = st
|
||||
|
||||
final override val annotationsRegistrar: IrAnnotationsFromPluginRegistrar
|
||||
get() = DummyIrAnnotationsFromPluginRegistrar
|
||||
|
||||
private fun resolveMemberScope(fqName: FqName): MemberScope? {
|
||||
val pkg = module.getPackage(fqName)
|
||||
|
||||
@@ -124,7 +129,6 @@ open class IrPluginContextImpl constructor(
|
||||
|
||||
@OptIn(FirIncompatiblePluginAPI::class)
|
||||
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 }
|
||||
}
|
||||
@@ -176,4 +180,10 @@ open class IrPluginContextImpl constructor(
|
||||
linker.postProcess(inOrAfterLinkageStep = false)
|
||||
return symbol
|
||||
}
|
||||
|
||||
private object DummyIrAnnotationsFromPluginRegistrar : IrAnnotationsFromPluginRegistrar() {
|
||||
override fun addMetadataVisibleAnnotationsToElement(declaration: IrDeclaration, annotations: List<IrConstructorCall>) {
|
||||
declaration.annotations += annotations
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user