server
01/17/2022, 1:11 PMdmitriy.novozhilov
01/18/2022, 7:21 AMKtClass?server
01/25/2022, 12:37 AMdmitriy.novozhilov
01/25/2022, 7:03 AMbindingContext[BindingContext.FUNCTION, psiFunction]) and then extract annotations from it (functionDescriptor.annotations)server
01/25/2022, 9:07 AMdmitriy.novozhilov
01/25/2022, 9:08 AMIrGenerationExtension?server
01/25/2022, 9:08 AMdmitriy.novozhilov
01/25/2022, 9:10 AMIrFunction.annotations will suite for youserver
01/25/2022, 9:45 AMval klas = file.declarations[0] as org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
(((klas.declarations[1].annotations[0] as org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl).type as IrTypeBase).kotlinType!! as SimpleType).arguments
is empty
((klas.declarations[1].annotations[0] as org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl).type as IrTypeBase).kotlinType!!.constructor.parameters
is empty
I'd like to get output as Pair("value","annValue"). I'd also like to support custom annotations here as well.
my example code is
class Example5Annotation {
@ExampleAnnotation("annValue")
fun bla(): String =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam non ligula in tellus scelerisque tempor. Pellentesque at blandit purus."
}
annotation class ExampleAnnotation(val value: String = "")server
01/25/2022, 9:46 AMserver
01/25/2022, 9:52 AMdmitriy.novozhilov
01/25/2022, 9:53 AMarguments of some type is generic type arguments of some specific type. E.g. for type List<String> arguments will be [String]
You really want to access arguments of annotation call:
val irClass = irFile.declarations.first() as IrClass
val irFunction = irClass.declarations[1] as IrFunction
val irAnnotationCall = irFunction.annotations.first()
val irAnnotationParameters = irAnnotationCall.symbol.owner.valueParameters
val parameterToArgument = (0..irAnnotationCall.constructorTypeArgumentsCount).map { irAnnotationParameters[it] to irAnnotationCall.getValueArgument(it) }server
01/25/2022, 9:55 AMdmitriy.novozhilov
01/25/2022, 9:55 AMresolve method
Each resolvable entity (like function call or annotation call) has symbol property which is reference to called declaration (and IR of it can be accessed via symbol.owner)server
01/25/2022, 10:22 AM