Improve API of annotation arguments in kotlinx-metadata
See changes in ChangeLog.md for more information
This commit is contained in:
@@ -16,10 +16,17 @@ sealed class CirConstantValue<out T> {
|
||||
data class IntValue(override val value: Int) : CirConstantValue<Int>()
|
||||
data class LongValue(override val value: Long) : CirConstantValue<Long>()
|
||||
|
||||
data class UByteValue(override val value: Byte) : CirConstantValue<Byte>()
|
||||
data class UShortValue(override val value: Short) : CirConstantValue<Short>()
|
||||
data class UIntValue(override val value: Int) : CirConstantValue<Int>()
|
||||
data class ULongValue(override val value: Long) : CirConstantValue<Long>()
|
||||
@ExperimentalUnsignedTypes
|
||||
data class UByteValue(override val value: UByte) : CirConstantValue<UByte>()
|
||||
|
||||
@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 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.getterAnnotations
|
||||
import kotlinx.metadata.klib.setterAnnotations
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.commonizer.cir.*
|
||||
import org.jetbrains.kotlin.commonizer.mergedtree.CirProvided
|
||||
import org.jetbrains.kotlin.commonizer.utils.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
object CirDeserializers {
|
||||
@@ -45,7 +45,7 @@ object CirDeserializers {
|
||||
isMarkedNullable = false
|
||||
)
|
||||
|
||||
val allValueArguments: Map<String, KmAnnotationArgument<*>> = source.arguments
|
||||
val allValueArguments: Map<String, KmAnnotationArgument> = source.arguments
|
||||
if (allValueArguments.isEmpty())
|
||||
return CirAnnotation.createInterned(type = type, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap())
|
||||
|
||||
@@ -55,7 +55,7 @@ object CirDeserializers {
|
||||
allValueArguments.forEach { (name, constantValue) ->
|
||||
val cirName = CirName.create(name)
|
||||
if (constantValue is KmAnnotationArgument.AnnotationValue)
|
||||
annotationValueArguments[cirName] = annotation(source = constantValue.value, typeResolver)
|
||||
annotationValueArguments[cirName] = annotation(source = constantValue.annotation, typeResolver)
|
||||
else
|
||||
constantValueArguments[cirName] = constantValue(
|
||||
constantValue = constantValue,
|
||||
@@ -205,7 +205,7 @@ object CirDeserializers {
|
||||
)
|
||||
|
||||
private fun constantValue(
|
||||
constantValue: KmAnnotationArgument<*>?,
|
||||
constantValue: KmAnnotationArgument?,
|
||||
constantName: CirName? = null,
|
||||
owner: Any,
|
||||
): CirConstantValue<*> = constantValue(
|
||||
@@ -213,8 +213,9 @@ object CirDeserializers {
|
||||
location = { "${owner::class.java}, $owner" + constantName?.toString()?.let { "[$it]" } }
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
private fun constantValue(
|
||||
constantValue: KmAnnotationArgument<*>?,
|
||||
constantValue: KmAnnotationArgument?,
|
||||
location: () -> String
|
||||
): CirConstantValue<*> = when (constantValue) {
|
||||
null -> CirConstantValue.NullValue
|
||||
@@ -242,7 +243,7 @@ object CirDeserializers {
|
||||
)
|
||||
|
||||
is KmAnnotationArgument.ArrayValue -> CirConstantValue.ArrayValue(
|
||||
constantValue.value.compactMapIndexed { index, innerConstantValue ->
|
||||
constantValue.elements.compactMapIndexed { index, innerConstantValue ->
|
||||
constantValue(
|
||||
constantValue = innerConstantValue,
|
||||
location = { "${location()}[$index]" }
|
||||
|
||||
@@ -8,13 +8,13 @@ package org.jetbrains.kotlin.commonizer.metadata
|
||||
import kotlinx.metadata.*
|
||||
import kotlinx.metadata.klib.*
|
||||
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.mergedtree.*
|
||||
import org.jetbrains.kotlin.commonizer.metadata.TypeAliasExpansion.*
|
||||
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.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
internal fun CirModule.serializeModule(
|
||||
@@ -195,7 +195,7 @@ internal fun CirFunction.serializeFunction(
|
||||
}
|
||||
|
||||
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<*>) ->
|
||||
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.CharValue -> KmAnnotationArgument.CharValue(value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user