Add @SerializableWith on objects too
to be able to retrieve them via getAssociatedObject and serializer<T>() function. Now object itself is a SerializerFactory.
This commit is contained in:
+1
-1
@@ -110,7 +110,7 @@ class SerializableCompanionIrGenerator(
|
||||
}
|
||||
|
||||
private fun generateSerializerFactoryIfNeeded(getterDescriptor: FunctionDescriptor) {
|
||||
if (serializableDescriptor.declaredTypeParameters.isEmpty()) return
|
||||
if (!companionDescriptor.needSerializerFactory()) return
|
||||
val serialFactoryDescriptor = companionDescriptor.unsubstitutedMemberScope.getContributedFunctions(
|
||||
SerialEntityNames.SERIALIZER_PROVIDER_NAME,
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
|
||||
+10
@@ -22,9 +22,11 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.konan.isNative
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.platform
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.types.*
|
||||
@@ -210,6 +212,14 @@ internal fun getSerializableClassDescriptorByCompanion(thisDescriptor: ClassDesc
|
||||
return classDescriptor
|
||||
}
|
||||
|
||||
internal fun ClassDescriptor.needSerializerFactory(): Boolean {
|
||||
if (this.platform?.isNative() != true) return false
|
||||
val serializableClass = getSerializableClassDescriptorByCompanion(this) ?: return false
|
||||
if (serializableClass.isSerializableObject) return true
|
||||
if (serializableClass.declaredTypeParameters.isEmpty()) return false
|
||||
return true
|
||||
}
|
||||
|
||||
internal fun getSerializableClassDescriptorBySerializer(serializerDescriptor: ClassDescriptor): ClassDescriptor? {
|
||||
val serializerForClass = serializerDescriptor.serializerForClass
|
||||
if (serializerForClass != null) return serializerForClass.toClassDescriptor
|
||||
|
||||
-7
@@ -58,13 +58,6 @@ object KSerializerDescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private fun ClassDescriptor.needSerializerFactory(): Boolean {
|
||||
if (this.platform?.isNative() != true) return false
|
||||
val serializableClass = getSerializableClassDescriptorByCompanion(this) ?: return false
|
||||
if (serializableClass.declaredTypeParameters.isEmpty()) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun addSerializerFactorySuperType(classDescriptor: ClassDescriptor, supertypes: MutableList<KotlinType>) {
|
||||
if (!classDescriptor.needSerializerFactory()) return
|
||||
val serializerFactoryClass =
|
||||
|
||||
Reference in New Issue
Block a user