Refactor KClassValue to store ClassLiteralValue internally
Only invariant array projections and non-null element types will be supported soon (see KT-26568), so it makes no sense to store the complete type in KClassValue. What we need is only the ClassId of the class, and the number of times it's wrapped into kotlin/Array, which is exactly what ClassLiteralValue represents. This change helps in decoupling annotation values from descriptors/types. The only constant value that depends on descriptors is now AnnotationValue. #KT-26582 Fixed
This commit is contained in:
+3
-16
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
@@ -100,22 +98,11 @@ class AnnotationSerializer(private val stringTable: DescriptorAwareStringTable)
|
||||
}
|
||||
|
||||
override fun visitKClassValue(value: KClassValue, data: Unit) {
|
||||
var kotlinType = value.value
|
||||
var arrayDimensions = 0
|
||||
while (KotlinBuiltIns.isArray(kotlinType)) {
|
||||
// We only support invariant projections and non-null array element types, see KT-26568
|
||||
kotlinType = kotlinType.arguments.single().type
|
||||
arrayDimensions++
|
||||
}
|
||||
|
||||
val descriptor = kotlinType.constructor.declarationDescriptor as? ClassDescriptor
|
||||
?: throw UnsupportedOperationException("Class literal annotation argument should be a class: $value")
|
||||
|
||||
type = Type.CLASS
|
||||
classId = stringTable.getFqNameIndex(descriptor)
|
||||
classId = stringTable.getQualifiedClassNameIndex(value.classId)
|
||||
|
||||
if (arrayDimensions > 0) {
|
||||
arrayDimensionCount = arrayDimensions
|
||||
if (value.arrayDimensions > 0) {
|
||||
arrayDimensionCount = value.arrayDimensions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user