How can you get an IrClass (Reference) from an annotation value used in a IrConstructorCall (via getAnnotation)? getAnnotationValueOrNull tries to cast the value to a IrConst, that misses IrClassReference as well as any const arrays that are valid in a JVM annotation.
if you have the class id of that annotation, cannot you use
pluginContext.referenceClass(classId)
?
h
hfhbd
10/14/2024, 3:19 PM
Thanks for the answers, it was more a question of: should the IR api include an IrConstExpression to model all possible constants annotation values?
i
Ivan Kylchik
10/15/2024, 8:35 AM
This API indeed looks strange. I see that it is mostly used in Koltin/Native. Probably it should be renamed to something like
getConstAnnotationValueOrNull
.
To get an argument from
IrConstructorCall
you can just call
someAnnotation.getValueArgument(index)
. The same way as you do for
IrCall
. But please be aware that this API will change in the nearest future.
h
hfhbd
10/15/2024, 9:22 AM
Yes, I do use
getValueArgument
and changes are fine.
But I still want to highlight if you want to add a IrConstExpression because for (jvm) annotation values, all values must be a compile constant, including const arrays and a class reference. So IMHO
getValueArgument
should not return
IrExpression
but a new
IrConstExpression
. (and maybe this also aligns with the const functions feature some day)
i
Ivan Kylchik
10/15/2024, 10:55 AM
Yep, we are aware of this. Right now designing a new
IrConstExpression
node is not in out plans. As you said, we will get back to it when we start to design const functions because it is aligned.