Do not store ClassDescriptor in EnumValue
Only store the ClassId of the enum class and the Name of the entry, and resolve the needed descriptor in getType() instead, which now takes the module instance where that descriptor should be resolved
This commit is contained in:
+2
-14
@@ -21,13 +21,13 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.constants.AnnotationValue
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValueFactory
|
||||
import org.jetbrains.kotlin.resolve.constants.EnumValue
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Annotation
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument.Value
|
||||
@@ -85,7 +85,7 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n
|
||||
resolveClassLiteralValue(nameResolver.getClassId(value.classId))
|
||||
}
|
||||
Type.ENUM -> {
|
||||
resolveEnumValue(nameResolver.getClassId(value.classId), nameResolver.getName(value.enumValueId))
|
||||
EnumValue(nameResolver.getClassId(value.classId), nameResolver.getName(value.enumValueId))
|
||||
}
|
||||
Type.ANNOTATION -> {
|
||||
AnnotationValue(deserializeAnnotation(value.annotation, nameResolver))
|
||||
@@ -137,18 +137,6 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n
|
||||
return ConstantValueFactory.createKClassValue(type)
|
||||
}
|
||||
|
||||
// NOTE: see analogous code in BinaryClassAnnotationAndConstantLoaderImpl
|
||||
private fun resolveEnumValue(enumClassId: ClassId, enumEntryName: Name): ConstantValue<*> {
|
||||
val enumClass = resolveClass(enumClassId)
|
||||
if (enumClass.kind == ClassKind.ENUM_CLASS) {
|
||||
val enumEntry = enumClass.unsubstitutedInnerClassesScope.getContributedClassifier(enumEntryName, NoLookupLocation.FROM_DESERIALIZATION)
|
||||
if (enumEntry is ClassDescriptor) {
|
||||
return ConstantValueFactory.createEnumValue(enumEntry)
|
||||
}
|
||||
}
|
||||
return ConstantValueFactory.createErrorValue("Unresolved enum entry: $enumClassId.$enumEntryName")
|
||||
}
|
||||
|
||||
private fun resolveArrayElementType(value: Value, nameResolver: NameResolver): SimpleType =
|
||||
with(builtIns) {
|
||||
when (value.type) {
|
||||
|
||||
Reference in New Issue
Block a user