Improve API of annotation arguments in kotlinx-metadata

See changes in ChangeLog.md for more information
This commit is contained in:
Alexander Udalov
2021-03-26 20:51:52 +01:00
parent 1a82158472
commit 5f7f4a4ac8
13 changed files with 99 additions and 70 deletions
@@ -534,28 +534,28 @@ private class MappingExtensions(
TypeArgument.Variance.OUT -> KmVariance.OUT
}
fun ConstantStub.mapToAnnotationArgument(): KmAnnotationArgument<*> = when (this) {
fun ConstantStub.mapToAnnotationArgument(): KmAnnotationArgument = when (this) {
is StringConstantStub -> KmAnnotationArgument.StringValue(value)
is IntegralConstantStub -> when (size) {
1 -> if (isSigned) {
KmAnnotationArgument.ByteValue(value.toByte())
} else {
KmAnnotationArgument.UByteValue(value.toByte())
KmAnnotationArgument.UByteValue(value.toUByte())
}
2 -> if (isSigned) {
KmAnnotationArgument.ShortValue(value.toShort())
} else {
KmAnnotationArgument.UShortValue(value.toShort())
KmAnnotationArgument.UShortValue(value.toUShort())
}
4 -> if (isSigned) {
KmAnnotationArgument.IntValue(value.toInt())
} else {
KmAnnotationArgument.UIntValue(value.toInt())
KmAnnotationArgument.UIntValue(value.toUInt())
}
8 -> if (isSigned) {
KmAnnotationArgument.LongValue(value)
} else {
KmAnnotationArgument.ULongValue(value)
KmAnnotationArgument.ULongValue(value.toULong())
}
else -> error("Integral constant of value $value with unexpected size of $size.")