Fix loading of class literal constant values in reflection
This is an addition to c1ab08c8ce where KT-26582 was fixed. The test
testClassLiteralArguments in JvmRuntimeDescriptorLoaderTestGenerated
failed before this change but went unnoticed because it wasn't run on CI
(see the previous commit)
This commit is contained in:
+15
-6
@@ -16,6 +16,7 @@
|
||||
|
||||
package kotlin.reflect.jvm.internal.components
|
||||
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor
|
||||
@@ -185,17 +186,25 @@ private object ReflectClassStructure {
|
||||
visitor.visitEnd()
|
||||
}
|
||||
|
||||
// See FileBasedKotlinClass.resolveKotlinNameByType
|
||||
private fun Class<*>.classLiteralValue(): ClassLiteralValue {
|
||||
var currentClass = this
|
||||
var nestedness = 0
|
||||
var dimensions = 0
|
||||
while (currentClass.isArray) {
|
||||
nestedness++
|
||||
dimensions++
|
||||
currentClass = currentClass.componentType
|
||||
}
|
||||
val classId =
|
||||
if (!currentClass.isPrimitive) currentClass.classId
|
||||
else ClassId.topLevel(JvmPrimitiveType.get(currentClass.name).primitiveType.typeFqName)
|
||||
return ClassLiteralValue(classId, nestedness)
|
||||
if (currentClass.isPrimitive) {
|
||||
val primitiveType = JvmPrimitiveType.get(currentClass.name).primitiveType
|
||||
if (dimensions > 0) {
|
||||
return ClassLiteralValue(ClassId.topLevel(primitiveType.arrayTypeFqName), dimensions - 1)
|
||||
}
|
||||
return ClassLiteralValue(ClassId.topLevel(primitiveType.typeFqName), dimensions)
|
||||
}
|
||||
|
||||
val javaClassId = currentClass.classId
|
||||
val kotlinClassId = JavaToKotlinClassMap.mapJavaToKotlin(javaClassId.asSingleFqName()) ?: javaClassId
|
||||
return ClassLiteralValue(kotlinClassId, dimensions)
|
||||
}
|
||||
|
||||
private fun processAnnotationArgumentValue(visitor: KotlinJvmBinaryClass.AnnotationArgumentVisitor, name: Name, value: Any) {
|
||||
|
||||
Reference in New Issue
Block a user