Serialize secondary constructors
This commit is contained in:
@@ -201,7 +201,7 @@ message Class {
|
||||
|
||||
// This field is present if and only if the class has a primary constructor
|
||||
optional PrimaryConstructor primary_constructor = 13;
|
||||
// todo: other constructors?
|
||||
repeated Callable secondary_constructor = 14;
|
||||
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,10 @@ public class DescriptorSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: other constructors
|
||||
for (ConstructorDescriptor constructorDescriptor : classDescriptor.getConstructors()) {
|
||||
if (constructorDescriptor.isPrimary()) continue;
|
||||
builder.addSecondaryConstructor(callableProto(constructorDescriptor));
|
||||
}
|
||||
|
||||
for (DeclarationDescriptor descriptor : sort(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors())) {
|
||||
if (descriptor instanceof CallableMemberDescriptor) {
|
||||
|
||||
+3
-4
@@ -31,7 +31,6 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
return when (callableKind) {
|
||||
FUN -> loadFunction(proto)
|
||||
VAL, VAR -> loadProperty(proto)
|
||||
CONSTRUCTOR -> loadConstructor(proto)
|
||||
else -> throw IllegalArgumentException("Unsupported callable kind: $callableKind")
|
||||
}
|
||||
}
|
||||
@@ -143,11 +142,11 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
return (c.containingDeclaration as? ClassDescriptor)?.getThisAsReceiverParameter()
|
||||
}
|
||||
|
||||
private fun loadConstructor(proto: Callable): CallableMemberDescriptor {
|
||||
public fun loadConstructor(proto: Callable, isPrimary: Boolean): ConstructorDescriptor {
|
||||
val classDescriptor = c.containingDeclaration as ClassDescriptor
|
||||
val descriptor = ConstructorDescriptorImpl.create(
|
||||
classDescriptor, getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION), // TODO: primary
|
||||
true, SourceElement.NO_SOURCE
|
||||
classDescriptor, getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION),
|
||||
isPrimary, SourceElement.NO_SOURCE
|
||||
)
|
||||
val local = c.childContext(descriptor, listOf())
|
||||
descriptor.initialize(
|
||||
|
||||
+12
-6
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.serialization.deserialization
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
public class DeserializedClassDescriptor(
|
||||
@@ -62,6 +63,7 @@ public class DeserializedClassDescriptor(
|
||||
|
||||
private val containingDeclaration = outerContext.containingDeclaration
|
||||
private val primaryConstructor = c.storageManager.createNullableLazyValue { computePrimaryConstructor() }
|
||||
private val constructors = c.storageManager.createLazyValue { computeConstructors() }
|
||||
private val defaultObjectDescriptor = c.storageManager.createNullableLazyValue { computeDefaultObjectDescriptor() }
|
||||
|
||||
private val annotations =
|
||||
@@ -102,16 +104,20 @@ public class DeserializedClassDescriptor(
|
||||
return descriptor
|
||||
}
|
||||
|
||||
return c.memberDeserializer.loadCallable(constructorProto.getData()) as ConstructorDescriptor
|
||||
return c.memberDeserializer.loadConstructor(constructorProto.getData(), true)
|
||||
}
|
||||
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ConstructorDescriptor? = primaryConstructor()
|
||||
|
||||
override fun getConstructors(): Collection<ConstructorDescriptor> {
|
||||
val constructor = getUnsubstitutedPrimaryConstructor() ?: return listOf()
|
||||
// TODO: other constructors
|
||||
return listOf(constructor)
|
||||
}
|
||||
private fun computeConstructors(): Collection<ConstructorDescriptor> =
|
||||
computeSecondaryConstructors() + getUnsubstitutedPrimaryConstructor().singletonOrEmptyList()
|
||||
|
||||
private fun computeSecondaryConstructors(): List<ConstructorDescriptor> =
|
||||
classProto.getSecondaryConstructorList().map {
|
||||
c.memberDeserializer.loadConstructor(it, false)
|
||||
}
|
||||
|
||||
override fun getConstructors() = constructors()
|
||||
|
||||
private fun computeDefaultObjectDescriptor(): ClassDescriptor? {
|
||||
if (!classProto.hasDefaultObjectName()) return null
|
||||
|
||||
Reference in New Issue
Block a user