Improve API of annotation arguments in kotlinx-metadata
See changes in ChangeLog.md for more information
This commit is contained in:
+5
-5
@@ -534,28 +534,28 @@ private class MappingExtensions(
|
|||||||
TypeArgument.Variance.OUT -> KmVariance.OUT
|
TypeArgument.Variance.OUT -> KmVariance.OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ConstantStub.mapToAnnotationArgument(): KmAnnotationArgument<*> = when (this) {
|
fun ConstantStub.mapToAnnotationArgument(): KmAnnotationArgument = when (this) {
|
||||||
is StringConstantStub -> KmAnnotationArgument.StringValue(value)
|
is StringConstantStub -> KmAnnotationArgument.StringValue(value)
|
||||||
is IntegralConstantStub -> when (size) {
|
is IntegralConstantStub -> when (size) {
|
||||||
1 -> if (isSigned) {
|
1 -> if (isSigned) {
|
||||||
KmAnnotationArgument.ByteValue(value.toByte())
|
KmAnnotationArgument.ByteValue(value.toByte())
|
||||||
} else {
|
} else {
|
||||||
KmAnnotationArgument.UByteValue(value.toByte())
|
KmAnnotationArgument.UByteValue(value.toUByte())
|
||||||
}
|
}
|
||||||
2 -> if (isSigned) {
|
2 -> if (isSigned) {
|
||||||
KmAnnotationArgument.ShortValue(value.toShort())
|
KmAnnotationArgument.ShortValue(value.toShort())
|
||||||
} else {
|
} else {
|
||||||
KmAnnotationArgument.UShortValue(value.toShort())
|
KmAnnotationArgument.UShortValue(value.toUShort())
|
||||||
}
|
}
|
||||||
4 -> if (isSigned) {
|
4 -> if (isSigned) {
|
||||||
KmAnnotationArgument.IntValue(value.toInt())
|
KmAnnotationArgument.IntValue(value.toInt())
|
||||||
} else {
|
} else {
|
||||||
KmAnnotationArgument.UIntValue(value.toInt())
|
KmAnnotationArgument.UIntValue(value.toUInt())
|
||||||
}
|
}
|
||||||
8 -> if (isSigned) {
|
8 -> if (isSigned) {
|
||||||
KmAnnotationArgument.LongValue(value)
|
KmAnnotationArgument.LongValue(value)
|
||||||
} else {
|
} else {
|
||||||
KmAnnotationArgument.ULongValue(value)
|
KmAnnotationArgument.ULongValue(value.toULong())
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> error("Integral constant of value $value with unexpected size of $size.")
|
else -> error("Integral constant of value $value with unexpected size of $size.")
|
||||||
|
|||||||
@@ -4,6 +4,14 @@
|
|||||||
|
|
||||||
- Update to Kotlin 1.5 with metadata version 1.5.
|
- Update to Kotlin 1.5 with metadata version 1.5.
|
||||||
Note: metadata of version 1.5 is readable by Kotlin compiler/reflection of versions 1.4 and later.
|
Note: metadata of version 1.5 is readable by Kotlin compiler/reflection of versions 1.4 and later.
|
||||||
|
- Breaking change: improve API of annotation arguments.
|
||||||
|
`KmAnnotationArgument` doesn't have `val value: T` anymore, it was moved to a subclass named `KmAnnotationArgument.LiteralValue<T>`.
|
||||||
|
The property `value` is:
|
||||||
|
- renamed to `annotation` in `AnnotationValue`
|
||||||
|
- renamed to `elements` in `ArrayValue`
|
||||||
|
- removed in favor of `enumClassName`/`enumEntryName` in `EnumValue`
|
||||||
|
- removed in favor of `className`/`arrayDimensionCount` in `KClassValue`
|
||||||
|
- changed type from signed to unsigned integer types in `UByteValue`, `UShortValue`, `UIntValue`, `ULongValue`
|
||||||
- [`KT-44783`](https://youtrack.jetbrains.com/issue/KT-44783) Add Flag.IS_VALUE for value classes
|
- [`KT-44783`](https://youtrack.jetbrains.com/issue/KT-44783) Add Flag.IS_VALUE for value classes
|
||||||
- Breaking change: `Flag.IS_INLINE` is deprecated, use `Flag.IS_VALUE` instead
|
- Breaking change: `Flag.IS_INLINE` is deprecated, use `Flag.IS_VALUE` instead
|
||||||
- Breaking change: deprecate `KotlinClassHeader.bytecodeVersion` and `KotlinClassHeader`'s constructor that takes a bytecode version array.
|
- Breaking change: deprecate `KotlinClassHeader.bytecodeVersion` and `KotlinClassHeader`'s constructor that takes a bytecode version array.
|
||||||
|
|||||||
+2
-2
@@ -118,7 +118,7 @@ internal class KlibPropertyExtension : KlibPropertyExtensionVisitor(), KmPropert
|
|||||||
val setterAnnotations: MutableList<KmAnnotation> = mutableListOf()
|
val setterAnnotations: MutableList<KmAnnotation> = mutableListOf()
|
||||||
var uniqId: UniqId? = null
|
var uniqId: UniqId? = null
|
||||||
var file: Int? = null
|
var file: Int? = null
|
||||||
var compileTimeValue: KmAnnotationArgument<*>? = null
|
var compileTimeValue: KmAnnotationArgument? = null
|
||||||
|
|
||||||
override fun visitAnnotation(annotation: KmAnnotation) {
|
override fun visitAnnotation(annotation: KmAnnotation) {
|
||||||
annotations += annotation
|
annotations += annotation
|
||||||
@@ -140,7 +140,7 @@ internal class KlibPropertyExtension : KlibPropertyExtensionVisitor(), KmPropert
|
|||||||
this.uniqId = uniqId
|
this.uniqId = uniqId
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCompileTimeValue(value: KmAnnotationArgument<*>) {
|
override fun visitCompileTimeValue(value: KmAnnotationArgument) {
|
||||||
this.compileTimeValue = value
|
this.compileTimeValue = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -299,7 +299,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCompileTimeValue(value: KmAnnotationArgument<*>) {
|
override fun visitCompileTimeValue(value: KmAnnotationArgument) {
|
||||||
proto.setExtension(
|
proto.setExtension(
|
||||||
KlibMetadataProtoBuf.compileTimeValue,
|
KlibMetadataProtoBuf.compileTimeValue,
|
||||||
value.writeAnnotationArgument(c.strings).build()
|
value.writeAnnotationArgument(c.strings).build()
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ var KmProperty.file: Int?
|
|||||||
klibExtensions.file = value
|
klibExtensions.file = value
|
||||||
}
|
}
|
||||||
|
|
||||||
var KmProperty.compileTimeValue: KmAnnotationArgument<*>?
|
var KmProperty.compileTimeValue: KmAnnotationArgument?
|
||||||
get() = klibExtensions.compileTimeValue
|
get() = klibExtensions.compileTimeValue
|
||||||
set(value) {
|
set(value) {
|
||||||
klibExtensions.compileTimeValue = value
|
klibExtensions.compileTimeValue = value
|
||||||
|
|||||||
+1
-1
@@ -65,7 +65,7 @@ abstract class KlibPropertyExtensionVisitor : KmPropertyExtensionVisitor {
|
|||||||
|
|
||||||
abstract fun visitUniqId(uniqId: UniqId)
|
abstract fun visitUniqId(uniqId: UniqId)
|
||||||
|
|
||||||
abstract fun visitCompileTimeValue(value: KmAnnotationArgument<*>)
|
abstract fun visitCompileTimeValue(value: KmAnnotationArgument)
|
||||||
|
|
||||||
override val type: KmExtensionType
|
override val type: KmExtensionType
|
||||||
get() = TYPE
|
get() = TYPE
|
||||||
|
|||||||
@@ -15,43 +15,53 @@ package kotlinx.metadata
|
|||||||
* @param arguments explicitly specified arguments to the annotation; does not include default values for annotation parameters
|
* @param arguments explicitly specified arguments to the annotation; does not include default values for annotation parameters
|
||||||
* (specified in the annotation class declaration)
|
* (specified in the annotation class declaration)
|
||||||
*/
|
*/
|
||||||
data class KmAnnotation(val className: ClassName, val arguments: Map<String, KmAnnotationArgument<*>>)
|
data class KmAnnotation(val className: ClassName, val arguments: Map<String, KmAnnotationArgument>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an argument to the annotation.
|
* Represents an argument to the annotation.
|
||||||
*
|
|
||||||
* @param T the type of the value of this argument
|
|
||||||
*/
|
*/
|
||||||
sealed class KmAnnotationArgument<out T : Any> {
|
sealed class KmAnnotationArgument {
|
||||||
/**
|
/**
|
||||||
* The value of this argument.
|
* A kind of annotation argument, whose value is directly accessible via [value].
|
||||||
|
* This is possible for annotation arguments of primitive types, unsigned types and strings.
|
||||||
|
*
|
||||||
|
* @param T the type of the value of this argument
|
||||||
*/
|
*/
|
||||||
abstract val value: T
|
sealed class LiteralValue<out T : Any> : KmAnnotationArgument() {
|
||||||
|
/**
|
||||||
data class ByteValue(override val value: Byte) : KmAnnotationArgument<Byte>()
|
* The value of this argument.
|
||||||
data class CharValue(override val value: Char) : KmAnnotationArgument<Char>()
|
*/
|
||||||
data class ShortValue(override val value: Short) : KmAnnotationArgument<Short>()
|
abstract val value: T
|
||||||
data class IntValue(override val value: Int) : KmAnnotationArgument<Int>()
|
|
||||||
data class LongValue(override val value: Long) : KmAnnotationArgument<Long>()
|
|
||||||
data class FloatValue(override val value: Float) : KmAnnotationArgument<Float>()
|
|
||||||
data class DoubleValue(override val value: Double) : KmAnnotationArgument<Double>()
|
|
||||||
data class BooleanValue(override val value: Boolean) : KmAnnotationArgument<Boolean>()
|
|
||||||
|
|
||||||
data class UByteValue(override val value: Byte) : KmAnnotationArgument<Byte>()
|
|
||||||
data class UShortValue(override val value: Short) : KmAnnotationArgument<Short>()
|
|
||||||
data class UIntValue(override val value: Int) : KmAnnotationArgument<Int>()
|
|
||||||
data class ULongValue(override val value: Long) : KmAnnotationArgument<Long>()
|
|
||||||
|
|
||||||
data class StringValue(override val value: String) : KmAnnotationArgument<String>()
|
|
||||||
|
|
||||||
data class KClassValue(val className: ClassName, val arrayDimensionCount: Int) : KmAnnotationArgument<String>() {
|
|
||||||
override val value: String = className + "[]".repeat(arrayDimensionCount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class EnumValue(val enumClassName: ClassName, val enumEntryName: String) : KmAnnotationArgument<String>() {
|
data class ByteValue(override val value: Byte) : LiteralValue<Byte>()
|
||||||
override val value: String = "$enumClassName.$enumEntryName"
|
data class CharValue(override val value: Char) : LiteralValue<Char>()
|
||||||
}
|
data class ShortValue(override val value: Short) : LiteralValue<Short>()
|
||||||
|
data class IntValue(override val value: Int) : LiteralValue<Int>()
|
||||||
|
data class LongValue(override val value: Long) : LiteralValue<Long>()
|
||||||
|
data class FloatValue(override val value: Float) : LiteralValue<Float>()
|
||||||
|
data class DoubleValue(override val value: Double) : LiteralValue<Double>()
|
||||||
|
data class BooleanValue(override val value: Boolean) : LiteralValue<Boolean>()
|
||||||
|
|
||||||
data class AnnotationValue(override val value: KmAnnotation) : KmAnnotationArgument<KmAnnotation>()
|
// TODO: remove @ExperimentalUnsignedTypes once bootstrap stdlib has stable unsigned types.
|
||||||
data class ArrayValue(override val value: List<KmAnnotationArgument<*>>) : KmAnnotationArgument<List<KmAnnotationArgument<*>>>()
|
@ExperimentalUnsignedTypes
|
||||||
|
data class UByteValue(override val value: UByte) : LiteralValue<UByte>()
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
|
data class UShortValue(override val value: UShort) : LiteralValue<UShort>()
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
|
data class UIntValue(override val value: UInt) : LiteralValue<UInt>()
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
|
data class ULongValue(override val value: ULong) : LiteralValue<ULong>()
|
||||||
|
|
||||||
|
data class StringValue(override val value: String) : LiteralValue<String>()
|
||||||
|
|
||||||
|
data class KClassValue(val className: ClassName, val arrayDimensionCount: Int) : KmAnnotationArgument()
|
||||||
|
|
||||||
|
data class EnumValue(val enumClassName: ClassName, val enumEntryName: String) : KmAnnotationArgument()
|
||||||
|
|
||||||
|
data class AnnotationValue(val annotation: KmAnnotation) : KmAnnotationArgument()
|
||||||
|
data class ArrayValue(val elements: List<KmAnnotationArgument>) : KmAnnotationArgument()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,14 @@ fun ProtoBuf.Annotation.readAnnotation(strings: NameResolver): KmAnnotation =
|
|||||||
}.toMap()
|
}.toMap()
|
||||||
)
|
)
|
||||||
|
|
||||||
fun ProtoBuf.Annotation.Argument.Value.readAnnotationArgument(strings: NameResolver): KmAnnotationArgument<*>? {
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
|
fun ProtoBuf.Annotation.Argument.Value.readAnnotationArgument(strings: NameResolver): KmAnnotationArgument? {
|
||||||
if (Flags.IS_UNSIGNED[flags]) {
|
if (Flags.IS_UNSIGNED[flags]) {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
BYTE -> KmAnnotationArgument.UByteValue(intValue.toByte())
|
BYTE -> KmAnnotationArgument.UByteValue(intValue.toByte().toUByte())
|
||||||
SHORT -> KmAnnotationArgument.UShortValue(intValue.toShort())
|
SHORT -> KmAnnotationArgument.UShortValue(intValue.toShort().toUShort())
|
||||||
INT -> KmAnnotationArgument.UIntValue(intValue.toInt())
|
INT -> KmAnnotationArgument.UIntValue(intValue.toInt().toUInt())
|
||||||
LONG -> KmAnnotationArgument.ULongValue(intValue)
|
LONG -> KmAnnotationArgument.ULongValue(intValue.toULong())
|
||||||
else -> error("Cannot read value of unsigned type: $type")
|
else -> error("Cannot read value of unsigned type: $type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ fun KmAnnotation.writeAnnotation(strings: StringTable): ProtoBuf.Annotation.Buil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KmAnnotationArgument<*>.writeAnnotationArgument(strings: StringTable): ProtoBuf.Annotation.Argument.Value.Builder =
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
|
fun KmAnnotationArgument.writeAnnotationArgument(strings: StringTable): ProtoBuf.Annotation.Argument.Value.Builder =
|
||||||
ProtoBuf.Annotation.Argument.Value.newBuilder().apply {
|
ProtoBuf.Annotation.Argument.Value.newBuilder().apply {
|
||||||
when (this@writeAnnotationArgument) {
|
when (this@writeAnnotationArgument) {
|
||||||
is KmAnnotationArgument.ByteValue -> {
|
is KmAnnotationArgument.ByteValue -> {
|
||||||
@@ -76,7 +77,7 @@ fun KmAnnotationArgument<*>.writeAnnotationArgument(strings: StringTable): Proto
|
|||||||
}
|
}
|
||||||
is KmAnnotationArgument.ULongValue -> {
|
is KmAnnotationArgument.ULongValue -> {
|
||||||
this.type = ProtoBuf.Annotation.Argument.Value.Type.LONG
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.LONG
|
||||||
this.intValue = value
|
this.intValue = value.toLong()
|
||||||
this.flags = Flags.IS_UNSIGNED.toFlags(true)
|
this.flags = Flags.IS_UNSIGNED.toFlags(true)
|
||||||
}
|
}
|
||||||
is KmAnnotationArgument.StringValue -> {
|
is KmAnnotationArgument.StringValue -> {
|
||||||
@@ -95,11 +96,11 @@ fun KmAnnotationArgument<*>.writeAnnotationArgument(strings: StringTable): Proto
|
|||||||
}
|
}
|
||||||
is KmAnnotationArgument.AnnotationValue -> {
|
is KmAnnotationArgument.AnnotationValue -> {
|
||||||
this.type = ProtoBuf.Annotation.Argument.Value.Type.ANNOTATION
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.ANNOTATION
|
||||||
this.annotation = value.writeAnnotation(strings).build()
|
this.annotation = this@writeAnnotationArgument.annotation.writeAnnotation(strings).build()
|
||||||
}
|
}
|
||||||
is KmAnnotationArgument.ArrayValue -> {
|
is KmAnnotationArgument.ArrayValue -> {
|
||||||
this.type = ProtoBuf.Annotation.Argument.Value.Type.ARRAY
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.ARRAY
|
||||||
for (element in value) {
|
for (element in elements) {
|
||||||
this.addArrayElement(element.writeAnnotationArgument(strings))
|
this.addArrayElement(element.writeAnnotationArgument(strings))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ private fun renderAnnotation(annotation: KmAnnotation): String =
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalUnsignedTypes::class)
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
private fun renderAnnotationArgument(arg: KmAnnotationArgument<*>): String =
|
private fun renderAnnotationArgument(arg: KmAnnotationArgument): String =
|
||||||
when (arg) {
|
when (arg) {
|
||||||
is KmAnnotationArgument.ByteValue -> arg.value.toString() + ".toByte()"
|
is KmAnnotationArgument.ByteValue -> arg.value.toString() + ".toByte()"
|
||||||
is KmAnnotationArgument.CharValue -> "'${arg.value.toString().sanitize(quote = '\'')}'"
|
is KmAnnotationArgument.CharValue -> "'${arg.value.toString().sanitize(quote = '\'')}'"
|
||||||
@@ -455,10 +455,10 @@ private fun renderAnnotationArgument(arg: KmAnnotationArgument<*>): String =
|
|||||||
is KmAnnotationArgument.LongValue -> arg.value.toString() + "L"
|
is KmAnnotationArgument.LongValue -> arg.value.toString() + "L"
|
||||||
is KmAnnotationArgument.FloatValue -> arg.value.toString() + "f"
|
is KmAnnotationArgument.FloatValue -> arg.value.toString() + "f"
|
||||||
is KmAnnotationArgument.DoubleValue -> arg.value.toString()
|
is KmAnnotationArgument.DoubleValue -> arg.value.toString()
|
||||||
is KmAnnotationArgument.UByteValue -> arg.value.toUByte().toString() + ".toUByte()"
|
is KmAnnotationArgument.UByteValue -> arg.value.toString() + ".toUByte()"
|
||||||
is KmAnnotationArgument.UShortValue -> arg.value.toUShort().toString() + ".toUShort()"
|
is KmAnnotationArgument.UShortValue -> arg.value.toString() + ".toUShort()"
|
||||||
is KmAnnotationArgument.UIntValue -> arg.value.toUInt().toString() + "u"
|
is KmAnnotationArgument.UIntValue -> arg.value.toString() + "u"
|
||||||
is KmAnnotationArgument.ULongValue -> arg.value.toULong().toString() + "uL"
|
is KmAnnotationArgument.ULongValue -> arg.value.toString() + "uL"
|
||||||
is KmAnnotationArgument.BooleanValue -> arg.value.toString()
|
is KmAnnotationArgument.BooleanValue -> arg.value.toString()
|
||||||
is KmAnnotationArgument.StringValue -> "\"${arg.value.sanitize(quote = '"')}\""
|
is KmAnnotationArgument.StringValue -> "\"${arg.value.sanitize(quote = '"')}\""
|
||||||
is KmAnnotationArgument.KClassValue -> buildString {
|
is KmAnnotationArgument.KClassValue -> buildString {
|
||||||
@@ -466,14 +466,14 @@ private fun renderAnnotationArgument(arg: KmAnnotationArgument<*>): String =
|
|||||||
append(arg.className).append("::class")
|
append(arg.className).append("::class")
|
||||||
repeat(arg.arrayDimensionCount) { append(">") }
|
repeat(arg.arrayDimensionCount) { append(">") }
|
||||||
}
|
}
|
||||||
is KmAnnotationArgument.EnumValue -> arg.value
|
is KmAnnotationArgument.EnumValue -> "${arg.enumClassName}.${arg.enumEntryName}"
|
||||||
is KmAnnotationArgument.AnnotationValue -> arg.value.let { annotation ->
|
is KmAnnotationArgument.AnnotationValue -> arg.annotation.let { annotation ->
|
||||||
val args = annotation.arguments.entries.joinToString { (name, argument) ->
|
val args = annotation.arguments.entries.joinToString { (name, argument) ->
|
||||||
"$name = ${renderAnnotationArgument(argument)}"
|
"$name = ${renderAnnotationArgument(argument)}"
|
||||||
}
|
}
|
||||||
"${annotation.className}($args)"
|
"${annotation.className}($args)"
|
||||||
}
|
}
|
||||||
is KmAnnotationArgument.ArrayValue -> arg.value.joinToString(prefix = "[", postfix = "]", transform = ::renderAnnotationArgument)
|
is KmAnnotationArgument.ArrayValue -> arg.elements.joinToString(prefix = "[", postfix = "]", transform = ::renderAnnotationArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.sanitize(quote: Char): String =
|
private fun String.sanitize(quote: Char): String =
|
||||||
|
|||||||
@@ -16,10 +16,17 @@ sealed class CirConstantValue<out T> {
|
|||||||
data class IntValue(override val value: Int) : CirConstantValue<Int>()
|
data class IntValue(override val value: Int) : CirConstantValue<Int>()
|
||||||
data class LongValue(override val value: Long) : CirConstantValue<Long>()
|
data class LongValue(override val value: Long) : CirConstantValue<Long>()
|
||||||
|
|
||||||
data class UByteValue(override val value: Byte) : CirConstantValue<Byte>()
|
@ExperimentalUnsignedTypes
|
||||||
data class UShortValue(override val value: Short) : CirConstantValue<Short>()
|
data class UByteValue(override val value: UByte) : CirConstantValue<UByte>()
|
||||||
data class UIntValue(override val value: Int) : CirConstantValue<Int>()
|
|
||||||
data class ULongValue(override val value: Long) : CirConstantValue<Long>()
|
@ExperimentalUnsignedTypes
|
||||||
|
data class UShortValue(override val value: UShort) : CirConstantValue<UShort>()
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
|
data class UIntValue(override val value: UInt) : CirConstantValue<UInt>()
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
|
data class ULongValue(override val value: ULong) : CirConstantValue<ULong>()
|
||||||
|
|
||||||
data class FloatValue(override val value: Float) : CirConstantValue<Float>()
|
data class FloatValue(override val value: Float) : CirConstantValue<Float>()
|
||||||
data class DoubleValue(override val value: Double) : CirConstantValue<Double>()
|
data class DoubleValue(override val value: Double) : CirConstantValue<Double>()
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import kotlinx.metadata.klib.annotations
|
|||||||
import kotlinx.metadata.klib.compileTimeValue
|
import kotlinx.metadata.klib.compileTimeValue
|
||||||
import kotlinx.metadata.klib.getterAnnotations
|
import kotlinx.metadata.klib.getterAnnotations
|
||||||
import kotlinx.metadata.klib.setterAnnotations
|
import kotlinx.metadata.klib.setterAnnotations
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
|
||||||
import org.jetbrains.kotlin.commonizer.cir.*
|
import org.jetbrains.kotlin.commonizer.cir.*
|
||||||
import org.jetbrains.kotlin.commonizer.mergedtree.CirProvided
|
import org.jetbrains.kotlin.commonizer.mergedtree.CirProvided
|
||||||
import org.jetbrains.kotlin.commonizer.utils.*
|
import org.jetbrains.kotlin.commonizer.utils.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
object CirDeserializers {
|
object CirDeserializers {
|
||||||
@@ -45,7 +45,7 @@ object CirDeserializers {
|
|||||||
isMarkedNullable = false
|
isMarkedNullable = false
|
||||||
)
|
)
|
||||||
|
|
||||||
val allValueArguments: Map<String, KmAnnotationArgument<*>> = source.arguments
|
val allValueArguments: Map<String, KmAnnotationArgument> = source.arguments
|
||||||
if (allValueArguments.isEmpty())
|
if (allValueArguments.isEmpty())
|
||||||
return CirAnnotation.createInterned(type = type, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap())
|
return CirAnnotation.createInterned(type = type, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap())
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ object CirDeserializers {
|
|||||||
allValueArguments.forEach { (name, constantValue) ->
|
allValueArguments.forEach { (name, constantValue) ->
|
||||||
val cirName = CirName.create(name)
|
val cirName = CirName.create(name)
|
||||||
if (constantValue is KmAnnotationArgument.AnnotationValue)
|
if (constantValue is KmAnnotationArgument.AnnotationValue)
|
||||||
annotationValueArguments[cirName] = annotation(source = constantValue.value, typeResolver)
|
annotationValueArguments[cirName] = annotation(source = constantValue.annotation, typeResolver)
|
||||||
else
|
else
|
||||||
constantValueArguments[cirName] = constantValue(
|
constantValueArguments[cirName] = constantValue(
|
||||||
constantValue = constantValue,
|
constantValue = constantValue,
|
||||||
@@ -205,7 +205,7 @@ object CirDeserializers {
|
|||||||
)
|
)
|
||||||
|
|
||||||
private fun constantValue(
|
private fun constantValue(
|
||||||
constantValue: KmAnnotationArgument<*>?,
|
constantValue: KmAnnotationArgument?,
|
||||||
constantName: CirName? = null,
|
constantName: CirName? = null,
|
||||||
owner: Any,
|
owner: Any,
|
||||||
): CirConstantValue<*> = constantValue(
|
): CirConstantValue<*> = constantValue(
|
||||||
@@ -213,8 +213,9 @@ object CirDeserializers {
|
|||||||
location = { "${owner::class.java}, $owner" + constantName?.toString()?.let { "[$it]" } }
|
location = { "${owner::class.java}, $owner" + constantName?.toString()?.let { "[$it]" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
private fun constantValue(
|
private fun constantValue(
|
||||||
constantValue: KmAnnotationArgument<*>?,
|
constantValue: KmAnnotationArgument?,
|
||||||
location: () -> String
|
location: () -> String
|
||||||
): CirConstantValue<*> = when (constantValue) {
|
): CirConstantValue<*> = when (constantValue) {
|
||||||
null -> CirConstantValue.NullValue
|
null -> CirConstantValue.NullValue
|
||||||
@@ -242,7 +243,7 @@ object CirDeserializers {
|
|||||||
)
|
)
|
||||||
|
|
||||||
is KmAnnotationArgument.ArrayValue -> CirConstantValue.ArrayValue(
|
is KmAnnotationArgument.ArrayValue -> CirConstantValue.ArrayValue(
|
||||||
constantValue.value.compactMapIndexed { index, innerConstantValue ->
|
constantValue.elements.compactMapIndexed { index, innerConstantValue ->
|
||||||
constantValue(
|
constantValue(
|
||||||
constantValue = innerConstantValue,
|
constantValue = innerConstantValue,
|
||||||
location = { "${location()}[$index]" }
|
location = { "${location()}[$index]" }
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ package org.jetbrains.kotlin.commonizer.metadata
|
|||||||
import kotlinx.metadata.*
|
import kotlinx.metadata.*
|
||||||
import kotlinx.metadata.klib.*
|
import kotlinx.metadata.klib.*
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.DynamicTypeDeserializer
|
import org.jetbrains.kotlin.backend.common.serialization.metadata.DynamicTypeDeserializer
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
|
||||||
import org.jetbrains.kotlin.commonizer.cir.*
|
import org.jetbrains.kotlin.commonizer.cir.*
|
||||||
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
||||||
import org.jetbrains.kotlin.commonizer.metadata.TypeAliasExpansion.*
|
import org.jetbrains.kotlin.commonizer.metadata.TypeAliasExpansion.*
|
||||||
import org.jetbrains.kotlin.commonizer.utils.DEFAULT_SETTER_VALUE_NAME
|
import org.jetbrains.kotlin.commonizer.utils.DEFAULT_SETTER_VALUE_NAME
|
||||||
import org.jetbrains.kotlin.commonizer.utils.SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_NAMES
|
import org.jetbrains.kotlin.commonizer.utils.SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_NAMES
|
||||||
import org.jetbrains.kotlin.commonizer.utils.compactMap
|
import org.jetbrains.kotlin.commonizer.utils.compactMap
|
||||||
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
internal fun CirModule.serializeModule(
|
internal fun CirModule.serializeModule(
|
||||||
@@ -195,7 +195,7 @@ internal fun CirFunction.serializeFunction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun CirAnnotation.serializeAnnotation(): KmAnnotation {
|
private fun CirAnnotation.serializeAnnotation(): KmAnnotation {
|
||||||
val arguments = LinkedHashMap<String, KmAnnotationArgument<*>>(constantValueArguments.size + annotationValueArguments.size, 1F)
|
val arguments = LinkedHashMap<String, KmAnnotationArgument>(constantValueArguments.size + annotationValueArguments.size, 1F)
|
||||||
|
|
||||||
constantValueArguments.forEach { (name: CirName, value: CirConstantValue<*>) ->
|
constantValueArguments.forEach { (name: CirName, value: CirConstantValue<*>) ->
|
||||||
arguments[name.name] = value.serializeConstantValue()
|
arguments[name.name] = value.serializeConstantValue()
|
||||||
@@ -212,7 +212,8 @@ private fun CirAnnotation.serializeAnnotation(): KmAnnotation {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirConstantValue<*>.serializeConstantValue(): KmAnnotationArgument<*>? = when (this) {
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
|
private fun CirConstantValue<*>.serializeConstantValue(): KmAnnotationArgument? = when (this) {
|
||||||
is CirConstantValue.StringValue -> KmAnnotationArgument.StringValue(value)
|
is CirConstantValue.StringValue -> KmAnnotationArgument.StringValue(value)
|
||||||
is CirConstantValue.CharValue -> KmAnnotationArgument.CharValue(value)
|
is CirConstantValue.CharValue -> KmAnnotationArgument.CharValue(value)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user