Load new proto messages for functions and properties
This commit is contained in:
+2
-68
@@ -66,8 +66,6 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
|
||||
@Override
|
||||
public void serializeCallable(@NotNull CallableMemberDescriptor callable, @NotNull ProtoBuf.Callable.Builder proto) {
|
||||
saveSignature(callable, proto);
|
||||
saveImplClassName(callable, proto);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,7 +107,7 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
if (descriptor instanceof DeserializedSimpleFunctionDescriptor) {
|
||||
DeserializedSimpleFunctionDescriptor deserialized = (DeserializedSimpleFunctionDescriptor) descriptor;
|
||||
signature = signatureSerializer.copyMethodSignature(
|
||||
deserialized.getProto().getExtension(JvmProtoBuf.oldMethodSignature), deserialized.getNameResolver()
|
||||
deserialized.getProto().getExtension(JvmProtoBuf.methodSignature), deserialized.getNameResolver()
|
||||
);
|
||||
}
|
||||
else {
|
||||
@@ -154,7 +152,7 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
if (descriptor instanceof DeserializedPropertyDescriptor) {
|
||||
DeserializedPropertyDescriptor deserializedCallable = (DeserializedPropertyDescriptor) descriptor;
|
||||
signature = signatureSerializer.copyPropertySignature(
|
||||
deserializedCallable.getProto().getExtension(JvmProtoBuf.oldPropertySignature),
|
||||
deserializedCallable.getProto().getExtension(JvmProtoBuf.propertySignature),
|
||||
deserializedCallable.getNameResolver()
|
||||
);
|
||||
}
|
||||
@@ -172,70 +170,6 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
saveImplClassName(descriptor, proto);
|
||||
}
|
||||
|
||||
// TODO: delete
|
||||
private void saveSignature(@NotNull CallableMemberDescriptor callable, @NotNull ProtoBuf.Callable.Builder proto) {
|
||||
SignatureSerializer signatureSerializer = new SignatureSerializer();
|
||||
if (callable instanceof FunctionDescriptor) {
|
||||
JvmProtoBuf.JvmMethodSignature signature;
|
||||
if (callable instanceof DeserializedSimpleFunctionDescriptor) {
|
||||
DeserializedSimpleFunctionDescriptor deserialized = (DeserializedSimpleFunctionDescriptor) callable;
|
||||
signature = signatureSerializer.copyMethodSignature(
|
||||
deserialized.getProto().getExtension(JvmProtoBuf.oldMethodSignature), deserialized.getNameResolver()
|
||||
);
|
||||
}
|
||||
else {
|
||||
Method method = bindings.get(METHOD_FOR_FUNCTION, (FunctionDescriptor) callable);
|
||||
signature = method != null ? signatureSerializer.methodSignature(method) : null;
|
||||
}
|
||||
if (signature != null) {
|
||||
proto.setExtension(JvmProtoBuf.oldMethodSignature, signature);
|
||||
}
|
||||
}
|
||||
else if (callable instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor property = (PropertyDescriptor) callable;
|
||||
|
||||
PropertyGetterDescriptor getter = property.getGetter();
|
||||
PropertySetterDescriptor setter = property.getSetter();
|
||||
Method getterMethod = getter == null ? null : bindings.get(METHOD_FOR_FUNCTION, getter);
|
||||
Method setterMethod = setter == null ? null : bindings.get(METHOD_FOR_FUNCTION, setter);
|
||||
|
||||
Pair<Type, String> field = bindings.get(FIELD_FOR_PROPERTY, property);
|
||||
String fieldName;
|
||||
String fieldDesc;
|
||||
boolean isStaticInOuter;
|
||||
if (field != null) {
|
||||
fieldName = field.second;
|
||||
fieldDesc = field.first.getDescriptor();
|
||||
isStaticInOuter = bindings.get(STATIC_FIELD_IN_OUTER_CLASS, property);
|
||||
}
|
||||
else {
|
||||
fieldName = null;
|
||||
fieldDesc = null;
|
||||
isStaticInOuter = false;
|
||||
}
|
||||
|
||||
Method syntheticMethod = bindings.get(SYNTHETIC_METHOD_FOR_PROPERTY, property);
|
||||
|
||||
JvmProtoBuf.JvmPropertySignature signature;
|
||||
if (callable instanceof DeserializedPropertyDescriptor) {
|
||||
DeserializedPropertyDescriptor deserializedCallable = (DeserializedPropertyDescriptor) callable;
|
||||
signature = signatureSerializer.copyPropertySignature(
|
||||
deserializedCallable.getProto().getExtension(JvmProtoBuf.oldPropertySignature),
|
||||
deserializedCallable.getNameResolver()
|
||||
);
|
||||
}
|
||||
else {
|
||||
signature = signatureSerializer.propertySignature(
|
||||
fieldName, fieldDesc, isStaticInOuter,
|
||||
syntheticMethod != null ? signatureSerializer.methodSignature(syntheticMethod) : null,
|
||||
getterMethod != null ? signatureSerializer.methodSignature(getterMethod) : null,
|
||||
setterMethod != null ? signatureSerializer.methodSignature(setterMethod) : null
|
||||
);
|
||||
}
|
||||
proto.setExtension(JvmProtoBuf.oldPropertySignature, signature);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveImplClassName(@NotNull CallableMemberDescriptor callable, @NotNull MessageLite.Builder proto) {
|
||||
String name = bindings.get(IMPL_CLASS_NAME_FOR_CALLABLE, callable);
|
||||
if (name == null) return;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
||||
|
||||
@@ -68,9 +69,13 @@ public object JvmFileClassUtil {
|
||||
@JvmStatic
|
||||
public fun getImplClassName(callable: DeserializedCallableMemberDescriptor): Name? =
|
||||
with(callable) {
|
||||
if (proto.hasExtension(JvmProtoBuf.oldImplClassName))
|
||||
nameResolver.getName(proto.getExtension(JvmProtoBuf.oldImplClassName))
|
||||
else null
|
||||
val proto = proto
|
||||
when (proto) {
|
||||
is ProtoBuf.Constructor -> null
|
||||
is ProtoBuf.Function -> proto.getExtension(JvmProtoBuf.methodImplClassName)
|
||||
is ProtoBuf.Property -> proto.getExtension(JvmProtoBuf.propertyImplClassName)
|
||||
else -> error("Unknown message: $proto")
|
||||
}?.let { nameResolver.getName(it) }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
+19
-6
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin.incremental
|
||||
|
||||
import com.google.protobuf.MessageLite
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import org.apache.log4j.Logger
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
@@ -166,16 +167,28 @@ public class IncrementalPackageFragmentProvider(
|
||||
this@IncrementalPackageFragment, packageData.packageProto, packageData.nameResolver, deserializationComponents,
|
||||
{ listOf() }
|
||||
) {
|
||||
override fun filteredMemberProtos(allMemberProtos: Collection<ProtoBuf.Callable>): Collection<ProtoBuf.Callable> {
|
||||
fun getPackagePart(callable: ProtoBuf.Callable) =
|
||||
callable.getExtension(JvmProtoBuf.oldImplClassName)?.let { packageData.nameResolver.getName(it) }
|
||||
override fun filteredFunctionProtos(protos: Collection<ProtoBuf.Function>): Collection<ProtoBuf.Function> {
|
||||
return filteredMemberProtos(protos) {
|
||||
it.getExtension(JvmProtoBuf.methodImplClassName)?.let { packageData.nameResolver.getName(it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun filteredPropertyProtos(protos: Collection<ProtoBuf.Property>): Collection<ProtoBuf.Property> {
|
||||
return filteredMemberProtos(protos) {
|
||||
it.getExtension(JvmProtoBuf.propertyImplClassName)?.let { packageData.nameResolver.getName(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun <M : MessageLite> filteredMemberProtos(
|
||||
allMemberProtos: Collection<M>,
|
||||
getPackagePart: (M) -> Name?
|
||||
): Collection<M> {
|
||||
fun shouldSkipPackagePart(name: Name) =
|
||||
JvmClassName.byFqNameWithoutInnerClasses(fqName.child(name)).getInternalName() in obsoletePackageParts
|
||||
JvmClassName.byFqNameWithoutInnerClasses(fqName.child(name)).internalName in obsoletePackageParts
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
if (LOG.isDebugEnabled) {
|
||||
val allPackageParts = allMemberProtos
|
||||
.map (::getPackagePart)
|
||||
.map(getPackagePart)
|
||||
.filterNotNull()
|
||||
.toSet()
|
||||
val skippedPackageParts = allPackageParts.filter { shouldSkipPackagePart(it) }
|
||||
|
||||
@@ -8,7 +8,11 @@ public final class DebugJsProtoBuf {
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistry registry) {
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.classAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.callableAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.oldCallableAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.oldCompileTimeValue);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.constructorAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.functionAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.propertyAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.compileTimeValue);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.parameterAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.typeAnnotation);
|
||||
@@ -1812,24 +1816,68 @@ public final class DebugJsProtoBuf {
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.class,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
|
||||
public static final int CALLABLE_ANNOTATION_FIELD_NUMBER = 130;
|
||||
public static final int OLD_CALLABLE_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Callable { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessage.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>> callableAnnotation = com.google.protobuf.GeneratedMessage
|
||||
java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>> oldCallableAnnotation = com.google.protobuf.GeneratedMessage
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.class,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
|
||||
public static final int OLD_COMPILE_TIME_VALUE_FIELD_NUMBER = 131;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Callable { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessage.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Argument.Value> oldCompileTimeValue = com.google.protobuf.GeneratedMessage
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Argument.Value.class,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Argument.Value.getDefaultInstance());
|
||||
public static final int CONSTRUCTOR_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Constructor { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessage.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Constructor,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>> constructorAnnotation = com.google.protobuf.GeneratedMessage
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.class,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
|
||||
public static final int FUNCTION_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Function { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessage.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Function,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>> functionAnnotation = com.google.protobuf.GeneratedMessage
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.class,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
|
||||
public static final int PROPERTY_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Property { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessage.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Property,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>> propertyAnnotation = com.google.protobuf.GeneratedMessage
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.class,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
|
||||
public static final int COMPILE_TIME_VALUE_FIELD_NUMBER = 131;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Callable { ... }</code>
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Property { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessage.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Property,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Argument.Value> compileTimeValue = com.google.protobuf.GeneratedMessage
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Argument.Value.class,
|
||||
@@ -1890,20 +1938,33 @@ public final class DebugJsProtoBuf {
|
||||
"ent\030\002 \002(\014:t\n\020class_annotation\022).org.jetb" +
|
||||
"rains.kotlin.serialization.Class\030\202\001 \003(\0132" +
|
||||
"..org.jetbrains.kotlin.serialization.Ann",
|
||||
"otation:z\n\023callable_annotation\022,.org.jet" +
|
||||
"brains.kotlin.serialization.Callable\030\202\001 " +
|
||||
"\003(\0132..org.jetbrains.kotlin.serialization" +
|
||||
".Annotation:\210\001\n\022compile_time_value\022,.org" +
|
||||
"otation:~\n\027old_callable_annotation\022,.org" +
|
||||
".jetbrains.kotlin.serialization.Callable" +
|
||||
"\030\203\001 \001(\0132=.org.jetbrains.kotlin.serializa" +
|
||||
"tion.Annotation.Argument.Value:\201\001\n\024param" +
|
||||
"eter_annotation\0222.org.jetbrains.kotlin.s" +
|
||||
"erialization.ValueParameter\030\202\001 \003(\0132..org" +
|
||||
".jetbrains.kotlin.serialization.Annotati",
|
||||
"on:r\n\017type_annotation\022(.org.jetbrains.ko" +
|
||||
"tlin.serialization.Type\030\202\001 \003(\0132..org.jet" +
|
||||
"brains.kotlin.serialization.AnnotationB\021" +
|
||||
"B\017DebugJsProtoBuf"
|
||||
"\030\202\001 \003(\0132..org.jetbrains.kotlin.serializa" +
|
||||
"tion.Annotation:\214\001\n\026old_compile_time_val" +
|
||||
"ue\022,.org.jetbrains.kotlin.serialization." +
|
||||
"Callable\030\203\001 \001(\0132=.org.jetbrains.kotlin.s" +
|
||||
"erialization.Annotation.Argument.Value:\200" +
|
||||
"\001\n\026constructor_annotation\022/.org.jetbrain" +
|
||||
"s.kotlin.serialization.Constructor\030\202\001 \003(" +
|
||||
"\0132..org.jetbrains.kotlin.serialization.A",
|
||||
"nnotation:z\n\023function_annotation\022,.org.j" +
|
||||
"etbrains.kotlin.serialization.Function\030\202" +
|
||||
"\001 \003(\0132..org.jetbrains.kotlin.serializati" +
|
||||
"on.Annotation:z\n\023property_annotation\022,.o" +
|
||||
"rg.jetbrains.kotlin.serialization.Proper" +
|
||||
"ty\030\202\001 \003(\0132..org.jetbrains.kotlin.seriali" +
|
||||
"zation.Annotation:\210\001\n\022compile_time_value" +
|
||||
"\022,.org.jetbrains.kotlin.serialization.Pr" +
|
||||
"operty\030\203\001 \001(\0132=.org.jetbrains.kotlin.ser" +
|
||||
"ialization.Annotation.Argument.Value:\201\001\n",
|
||||
"\024parameter_annotation\0222.org.jetbrains.ko" +
|
||||
"tlin.serialization.ValueParameter\030\202\001 \003(\013" +
|
||||
"2..org.jetbrains.kotlin.serialization.An" +
|
||||
"notation:r\n\017type_annotation\022(.org.jetbra" +
|
||||
"ins.kotlin.serialization.Type\030\202\001 \003(\0132..o" +
|
||||
"rg.jetbrains.kotlin.serialization.Annota" +
|
||||
"tionB\021B\017DebugJsProtoBuf"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
@@ -1929,10 +1990,14 @@ public final class DebugJsProtoBuf {
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Library_FileEntry_descriptor,
|
||||
new java.lang.String[] { "Path", "Content", });
|
||||
classAnnotation.internalInit(descriptor.getExtensions().get(0));
|
||||
callableAnnotation.internalInit(descriptor.getExtensions().get(1));
|
||||
compileTimeValue.internalInit(descriptor.getExtensions().get(2));
|
||||
parameterAnnotation.internalInit(descriptor.getExtensions().get(3));
|
||||
typeAnnotation.internalInit(descriptor.getExtensions().get(4));
|
||||
oldCallableAnnotation.internalInit(descriptor.getExtensions().get(1));
|
||||
oldCompileTimeValue.internalInit(descriptor.getExtensions().get(2));
|
||||
constructorAnnotation.internalInit(descriptor.getExtensions().get(3));
|
||||
functionAnnotation.internalInit(descriptor.getExtensions().get(4));
|
||||
propertyAnnotation.internalInit(descriptor.getExtensions().get(5));
|
||||
compileTimeValue.internalInit(descriptor.getExtensions().get(6));
|
||||
parameterAnnotation.internalInit(descriptor.getExtensions().get(7));
|
||||
typeAnnotation.internalInit(descriptor.getExtensions().get(8));
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -183,7 +183,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
||||
return type.getExtension(JvmProtoBuf.typeAnnotation).map { loadTypeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
override fun loadPropertyConstant(container: ProtoContainer, proto: ProtoBuf.Callable, expectedType: JetType): C? {
|
||||
override fun loadPropertyConstant(container: ProtoContainer, proto: ProtoBuf.Property, expectedType: JetType): C? {
|
||||
val nameResolver = container.nameResolver
|
||||
val signature = getCallableSignature(proto, nameResolver, AnnotatedCallableKind.PROPERTY) ?: return null
|
||||
|
||||
|
||||
+2
-2
@@ -73,10 +73,10 @@ class BuiltInsAnnotationAndConstantLoader(
|
||||
|
||||
override fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Callable,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: JetType
|
||||
): ConstantValue<*>? {
|
||||
val value = proto.getExtension(BuiltInsProtoBuf.oldCompileTimeValue)
|
||||
val value = proto.getExtension(BuiltInsProtoBuf.compileTimeValue)
|
||||
return deserializer.resolveValue(expectedType, value, container.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public interface AnnotationAndConstantLoader<A, C, T> {
|
||||
@Nullable
|
||||
C loadPropertyConstant(
|
||||
@NotNull ProtoContainer container,
|
||||
@NotNull ProtoBuf.Callable proto,
|
||||
@NotNull ProtoBuf.Property proto,
|
||||
@NotNull JetType expectedType
|
||||
);
|
||||
}
|
||||
|
||||
+27
-33
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import com.google.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
|
||||
@@ -27,23 +28,11 @@ import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.serialization.Flags
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Callable
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.CallableKind.FUN
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.CallableKind.VAL
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.CallableKind.VAR
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
|
||||
public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
public fun loadCallable(proto: Callable): CallableMemberDescriptor {
|
||||
val callableKind = Flags.CALLABLE_KIND.get(proto.getFlags())
|
||||
return when (callableKind) {
|
||||
FUN -> loadFunction(proto)
|
||||
VAL, VAR -> loadProperty(proto)
|
||||
else -> throw IllegalArgumentException("Unsupported callable kind: $callableKind")
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadProperty(proto: Callable): PropertyDescriptor {
|
||||
public fun loadProperty(proto: ProtoBuf.Property): PropertyDescriptor {
|
||||
val flags = proto.getFlags()
|
||||
|
||||
val property = DeserializedPropertyDescriptor(
|
||||
@@ -63,7 +52,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
val local = c.childContext(property, proto.getTypeParameterList())
|
||||
|
||||
val hasGetter = Flags.OLD_HAS_GETTER.get(flags)
|
||||
val receiverAnnotations = if (hasGetter)
|
||||
val receiverAnnotations = if (hasGetter && proto.hasReceiverType())
|
||||
getReceiverParameterAnnotations(proto, AnnotatedCallableKind.PROPERTY_GETTER)
|
||||
else
|
||||
Annotations.EMPTY
|
||||
@@ -113,7 +102,9 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
property.getKind(), null, SourceElement.NO_SOURCE
|
||||
)
|
||||
val setterLocal = local.childContext(setter, listOf())
|
||||
val valueParameters = setterLocal.memberDeserializer.valueParameters(proto, AnnotatedCallableKind.PROPERTY_SETTER)
|
||||
val valueParameters = setterLocal.memberDeserializer.valueParameters(
|
||||
listOf(proto.setterValueParameter), proto, AnnotatedCallableKind.PROPERTY_SETTER
|
||||
)
|
||||
setter.initialize(valueParameters.single())
|
||||
setter
|
||||
}
|
||||
@@ -139,16 +130,18 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
return property
|
||||
}
|
||||
|
||||
private fun loadFunction(proto: Callable): CallableMemberDescriptor {
|
||||
public fun loadFunction(proto: ProtoBuf.Function): FunctionDescriptor {
|
||||
val annotations = getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION)
|
||||
val receiverAnnotations = getReceiverParameterAnnotations(proto, AnnotatedCallableKind.FUNCTION)
|
||||
val receiverAnnotations = if (proto.hasReceiverType())
|
||||
getReceiverParameterAnnotations(proto, AnnotatedCallableKind.FUNCTION)
|
||||
else Annotations.EMPTY
|
||||
val function = DeserializedSimpleFunctionDescriptor.create(c.containingDeclaration, proto, c.nameResolver, annotations)
|
||||
val local = c.childContext(function, proto.getTypeParameterList())
|
||||
function.initialize(
|
||||
if (proto.hasReceiverType()) local.typeDeserializer.type(proto.getReceiverType(), receiverAnnotations) else null,
|
||||
getDispatchReceiverParameter(),
|
||||
local.typeDeserializer.ownTypeParameters,
|
||||
local.memberDeserializer.valueParameters(proto, AnnotatedCallableKind.FUNCTION),
|
||||
local.memberDeserializer.valueParameters(proto.valueParameterList, proto, AnnotatedCallableKind.FUNCTION),
|
||||
local.typeDeserializer.type(proto.returnType),
|
||||
Deserialization.modality(Flags.MODALITY.get(proto.flags)),
|
||||
Deserialization.visibility(Flags.VISIBILITY.get(proto.flags))
|
||||
@@ -166,19 +159,19 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
val classDescriptor = c.containingDeclaration as ClassDescriptor
|
||||
val descriptor = DeserializedConstructorDescriptor(
|
||||
classDescriptor, null, getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION),
|
||||
isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver
|
||||
isPrimary, CallableMemberDescriptor.Kind.DECLARATION, TODO("proto"), c.nameResolver
|
||||
)
|
||||
val local = c.childContext(descriptor, listOf())
|
||||
descriptor.initialize(
|
||||
classDescriptor.getTypeConstructor().getParameters(),
|
||||
local.memberDeserializer.valueParameters(proto, AnnotatedCallableKind.FUNCTION),
|
||||
local.memberDeserializer.valueParameters(proto.valueParameterList, proto, AnnotatedCallableKind.FUNCTION),
|
||||
Deserialization.visibility(Flags.VISIBILITY.get(proto.getFlags()))
|
||||
)
|
||||
descriptor.setReturnType(local.typeDeserializer.type(proto.getReturnType()))
|
||||
return descriptor
|
||||
}
|
||||
|
||||
private fun getAnnotations(proto: Callable, flags: Int, kind: AnnotatedCallableKind): Annotations {
|
||||
private fun getAnnotations(proto: MessageLite, flags: Int, kind: AnnotatedCallableKind): Annotations {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(flags)) {
|
||||
return Annotations.EMPTY
|
||||
}
|
||||
@@ -190,27 +183,28 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
}
|
||||
|
||||
private fun getReceiverParameterAnnotations(
|
||||
proto: Callable,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
receiverTargetedKind: AnnotatedCallableKind = kind
|
||||
): Annotations {
|
||||
return DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
|
||||
if (proto.hasReceiverType()) {
|
||||
c.containingDeclaration.asProtoContainer()?.let {
|
||||
c.components.annotationAndConstantLoader
|
||||
.loadExtensionReceiverParameterAnnotations(it, proto, receiverTargetedKind)
|
||||
.map { AnnotationWithTarget(it, AnnotationUseSiteTarget.RECEIVER) }
|
||||
}.orEmpty()
|
||||
}
|
||||
else emptyList()
|
||||
c.containingDeclaration.asProtoContainer()?.let {
|
||||
c.components.annotationAndConstantLoader
|
||||
.loadExtensionReceiverParameterAnnotations(it, proto, receiverTargetedKind)
|
||||
.map { AnnotationWithTarget(it, AnnotationUseSiteTarget.RECEIVER) }
|
||||
}.orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List<ValueParameterDescriptor> {
|
||||
private fun valueParameters(
|
||||
valueParameters: List<ProtoBuf.ValueParameter>,
|
||||
callable: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<ValueParameterDescriptor> {
|
||||
val callableDescriptor = c.containingDeclaration as CallableDescriptor
|
||||
val containerOfCallable = callableDescriptor.containingDeclaration.asProtoContainer()
|
||||
|
||||
return callable.valueParameterList.mapIndexed { i, proto ->
|
||||
return valueParameters.mapIndexed { i, proto ->
|
||||
val flags = if (proto.hasFlags()) proto.flags else 0
|
||||
ValueParameterDescriptorImpl(
|
||||
callableDescriptor, null, i,
|
||||
@@ -226,7 +220,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
|
||||
private fun getParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
callable: Callable,
|
||||
callable: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
index: Int,
|
||||
valueParameter: ProtoBuf.ValueParameter
|
||||
|
||||
+6
-5
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import com.google.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
|
||||
public interface DeserializedCallableMemberDescriptor: CallableMemberDescriptor {
|
||||
public val proto: ProtoBuf.Callable
|
||||
public val nameResolver: NameResolver
|
||||
interface DeserializedCallableMemberDescriptor : CallableMemberDescriptor {
|
||||
val proto: MessageLite
|
||||
|
||||
val nameResolver: NameResolver
|
||||
}
|
||||
|
||||
+1
-1
@@ -186,7 +186,7 @@ public class DeserializedClassDescriptor(
|
||||
override fun toString() = getName().toString()
|
||||
}
|
||||
|
||||
private inner class DeserializedClassMemberScope : DeserializedMemberScope(c, classProto.getMemberList()) {
|
||||
private inner class DeserializedClassMemberScope : DeserializedMemberScope(c, classProto.functionList, classProto.propertyList) {
|
||||
private val classDescriptor: DeserializedClassDescriptor get() = this@DeserializedClassDescriptor
|
||||
private val allDescriptors = c.storageManager.createLazyValue {
|
||||
computeDescriptors(DescriptorKindFilter.ALL, JetScope.ALL_NAME_FILTER, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class DeserializedConstructorDescriptor(
|
||||
annotations: Annotations,
|
||||
isPrimary: Boolean,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
override val proto: ProtoBuf.Callable,
|
||||
override val proto: ProtoBuf.Constructor,
|
||||
override val nameResolver: NameResolver
|
||||
) : ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE),
|
||||
DeserializedCallableMemberDescriptor {
|
||||
|
||||
+45
-56
@@ -16,14 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.descriptors
|
||||
|
||||
import com.google.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
||||
import org.jetbrains.kotlin.serialization.Flags
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.CallableKind
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
@@ -31,59 +30,49 @@ import java.util.*
|
||||
|
||||
public abstract class DeserializedMemberScope protected constructor(
|
||||
protected val c: DeserializationContext,
|
||||
membersList: Collection<ProtoBuf.Callable>
|
||||
functionList: Collection<ProtoBuf.Function>,
|
||||
propertyList: Collection<ProtoBuf.Property>
|
||||
) : JetScopeImpl() {
|
||||
|
||||
private data class ProtoKey(val name: Name, val kind: Kind, val isExtension: Boolean)
|
||||
private enum class Kind { FUNCTION, PROPERTY }
|
||||
private data class ProtoKey(val name: Name, val isExtension: Boolean)
|
||||
|
||||
private fun CallableKind.toKind(): Kind {
|
||||
return when (this) {
|
||||
CallableKind.FUN -> Kind.FUNCTION
|
||||
CallableKind.VAL, CallableKind.VAR -> Kind.PROPERTY
|
||||
else -> throw IllegalStateException("Unexpected CallableKind $this")
|
||||
}
|
||||
}
|
||||
private val functionProtos =
|
||||
c.storageManager.createLazyValue {
|
||||
groupByKey(filteredFunctionProtos(functionList), { it.name }) { it.hasReceiverType() }
|
||||
}
|
||||
private val propertyProtos =
|
||||
c.storageManager.createLazyValue {
|
||||
groupByKey(filteredPropertyProtos(propertyList), { it.name }) { it.hasReceiverType() }
|
||||
}
|
||||
|
||||
private val membersProtos =
|
||||
c.storageManager.createLazyValue { groupByKey(filteredMemberProtos(membersList)) }
|
||||
private val functions =
|
||||
c.storageManager.createMemoizedFunction<Name, Collection<FunctionDescriptor>> { computeFunctions(it) }
|
||||
private val properties =
|
||||
c.storageManager.createMemoizedFunction<Name, Collection<VariableDescriptor>> { computeProperties(it) }
|
||||
|
||||
protected open fun filteredMemberProtos(allMemberProtos: Collection<ProtoBuf.Callable>): Collection<ProtoBuf.Callable> = allMemberProtos
|
||||
protected open fun filteredFunctionProtos(protos: Collection<ProtoBuf.Function>): Collection<ProtoBuf.Function> = protos
|
||||
|
||||
private fun groupByKey(membersList: Collection<ProtoBuf.Callable>): Map<ProtoKey, List<ProtoBuf.Callable>> {
|
||||
val map = LinkedHashMap<ProtoKey, MutableList<ProtoBuf.Callable>>()
|
||||
for (memberProto in membersList) {
|
||||
val key = ProtoKey(
|
||||
c.nameResolver.getName(memberProto.getName()),
|
||||
Flags.CALLABLE_KIND[memberProto.getFlags()].toKind(),
|
||||
memberProto.hasReceiverType()
|
||||
)
|
||||
var protos = map[key]
|
||||
if (protos == null) {
|
||||
protos = ArrayList(1)
|
||||
map.put(key, protos)
|
||||
}
|
||||
protos.add(memberProto)
|
||||
protected open fun filteredPropertyProtos(protos: Collection<ProtoBuf.Property>): Collection<ProtoBuf.Property> = protos
|
||||
|
||||
private fun <M : MessageLite> groupByKey(
|
||||
protos: Collection<M>, getNameIndex: (M) -> Int, isExtension: (M) -> Boolean
|
||||
): Map<ProtoKey, List<M>> {
|
||||
val map = LinkedHashMap<ProtoKey, MutableList<M>>()
|
||||
for (proto in protos) {
|
||||
val key = ProtoKey(c.nameResolver.getName(getNameIndex(proto)), isExtension(proto))
|
||||
map.getOrPut(key) { ArrayList(1) }.add(proto)
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
private fun <D : CallableMemberDescriptor> computeMembers(name: Name, kind: Kind): LinkedHashSet<D> {
|
||||
val memberProtos = membersProtos()[ProtoKey(name, kind, isExtension = false)].orEmpty() +
|
||||
membersProtos()[ProtoKey(name, kind, isExtension = true)].orEmpty()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return memberProtos.mapTo(LinkedHashSet<D>()) { memberProto ->
|
||||
c.memberDeserializer.loadCallable(memberProto) as D
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeFunctions(name: Name): Collection<FunctionDescriptor> {
|
||||
val descriptors = computeMembers<FunctionDescriptor>(name, Kind.FUNCTION)
|
||||
val protos = functionProtos()[ProtoKey(name, isExtension = false)].orEmpty() +
|
||||
functionProtos()[ProtoKey(name, isExtension = true)].orEmpty()
|
||||
|
||||
val descriptors = protos.mapTo(linkedSetOf()) {
|
||||
c.memberDeserializer.loadFunction(it)
|
||||
}
|
||||
|
||||
computeNonDeclaredFunctions(name, descriptors)
|
||||
return descriptors.toReadOnlyList()
|
||||
}
|
||||
@@ -94,7 +83,13 @@ public abstract class DeserializedMemberScope protected constructor(
|
||||
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> = functions(name)
|
||||
|
||||
private fun computeProperties(name: Name): Collection<VariableDescriptor> {
|
||||
val descriptors = computeMembers<PropertyDescriptor>(name, Kind.PROPERTY)
|
||||
val protos = propertyProtos()[ProtoKey(name, isExtension = false)].orEmpty() +
|
||||
propertyProtos()[ProtoKey(name, isExtension = true)].orEmpty()
|
||||
|
||||
val descriptors = protos.mapTo(linkedSetOf()) {
|
||||
c.memberDeserializer.loadProperty(it)
|
||||
}
|
||||
|
||||
computeNonDeclaredProperties(name, descriptors)
|
||||
return descriptors.toReadOnlyList()
|
||||
}
|
||||
@@ -142,32 +137,26 @@ public abstract class DeserializedMemberScope protected constructor(
|
||||
nameFilter: (Name) -> Boolean,
|
||||
location: LookupLocation
|
||||
) {
|
||||
val acceptsProperties = kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)
|
||||
val acceptsFunctions = kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)
|
||||
if (!(acceptsFunctions || acceptsProperties)) {
|
||||
return
|
||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) {
|
||||
val keys = propertyProtos().keySet().filter { nameFilter(it.name) }
|
||||
addMembers(result, keys) { getProperties(it, location) }
|
||||
}
|
||||
|
||||
val keys = membersProtos().keySet().filter { nameFilter(it.name) }
|
||||
if (acceptsProperties) {
|
||||
addMembers(result, keys, Kind.PROPERTY) { getProperties(it, location) }
|
||||
}
|
||||
if (acceptsFunctions) {
|
||||
addMembers(result, keys, Kind.FUNCTION) { getFunctions(it, location) }
|
||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
|
||||
val keys = functionProtos().keySet().filter { nameFilter(it.name) }
|
||||
addMembers(result, keys) { getFunctions(it, location) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun addMembers(
|
||||
result: MutableCollection<DeclarationDescriptor>,
|
||||
keys: Collection<ProtoKey>,
|
||||
kind: Kind,
|
||||
getMembers: (Name) -> Collection<CallableDescriptor>
|
||||
) {
|
||||
val filteredByKind = keys.filter { it.kind == kind }
|
||||
listOf(false, true).forEach { isExtension ->
|
||||
filteredByKind.filter { it.isExtension == isExtension }
|
||||
keys.filter { it.isExtension == isExtension }
|
||||
.flatMap { getMembers(it.name) }
|
||||
.filterTo(result) { (it.getExtensionReceiverParameter() != null) == isExtension }
|
||||
.filterTo(result) { (it.extensionReceiverParameter != null) == isExtension }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +174,7 @@ public abstract class DeserializedMemberScope protected constructor(
|
||||
override fun getOwnDeclaredDescriptors() = getAllDescriptors()
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.getSimpleName(), " {")
|
||||
p.println(javaClass.simpleName, " {")
|
||||
p.pushIndent()
|
||||
|
||||
p.println("containingDeclaration = " + getContainingDeclaration())
|
||||
|
||||
+1
-2
@@ -39,8 +39,7 @@ public open class DeserializedPackageMemberScope(
|
||||
nameResolver: NameResolver,
|
||||
components: DeserializationComponents,
|
||||
classNames: () -> Collection<Name>
|
||||
) : DeserializedMemberScope(components.createContext(packageDescriptor, nameResolver), proto.getMemberList()) {
|
||||
|
||||
) : DeserializedMemberScope(components.createContext(packageDescriptor, nameResolver), proto.functionList, proto.propertyList) {
|
||||
private val packageFqName = packageDescriptor.fqName
|
||||
|
||||
internal val classNames by c.storageManager.createLazyValue { classNames().toSet() }
|
||||
|
||||
+9
-13
@@ -16,19 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
|
||||
public class DeserializedPropertyDescriptor(
|
||||
class DeserializedPropertyDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
original: PropertyDescriptor?,
|
||||
annotations: Annotations,
|
||||
@@ -37,8 +33,8 @@ public class DeserializedPropertyDescriptor(
|
||||
isVar: Boolean,
|
||||
name: Name,
|
||||
kind: Kind,
|
||||
override public val proto: ProtoBuf.Callable,
|
||||
override public val nameResolver: NameResolver,
|
||||
override val proto: ProtoBuf.Property,
|
||||
override val nameResolver: NameResolver,
|
||||
lateInit: Boolean,
|
||||
isConst: Boolean
|
||||
) : DeserializedCallableMemberDescriptor,
|
||||
|
||||
+4
-5
@@ -29,12 +29,11 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.serialization.Flags;
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.Deserialization;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationPackage;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver;
|
||||
|
||||
public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescriptorImpl implements DeserializedCallableMemberDescriptor {
|
||||
|
||||
private final ProtoBuf.Callable proto;
|
||||
private final ProtoBuf.Function proto;
|
||||
private final NameResolver nameResolver;
|
||||
|
||||
private DeserializedSimpleFunctionDescriptor(
|
||||
@@ -43,7 +42,7 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind,
|
||||
@NotNull ProtoBuf.Callable proto,
|
||||
@NotNull ProtoBuf.Function proto,
|
||||
@NotNull NameResolver nameResolver
|
||||
) {
|
||||
super(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE);
|
||||
@@ -77,7 +76,7 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ProtoBuf.Callable getProto() {
|
||||
public ProtoBuf.Function getProto() {
|
||||
return proto;
|
||||
}
|
||||
|
||||
@@ -90,7 +89,7 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
||||
@NotNull
|
||||
public static DeserializedSimpleFunctionDescriptor create(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull ProtoBuf.Callable proto,
|
||||
@NotNull ProtoBuf.Function proto,
|
||||
@NotNull NameResolver nameResolver,
|
||||
@NotNull Annotations annotations
|
||||
) {
|
||||
|
||||
@@ -157,7 +157,6 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
||||
|
||||
// TODO: check resulting method's return type
|
||||
fun findMethodBySignature(
|
||||
@Suppress("UNUSED_PARAMETER") proto: ProtoBuf.Callable,
|
||||
signature: JvmProtoBuf.JvmMethodSignature,
|
||||
nameResolver: NameResolver,
|
||||
declared: Boolean
|
||||
@@ -270,7 +269,7 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
||||
|
||||
// TODO: check resulting field's type
|
||||
fun findFieldBySignature(
|
||||
proto: ProtoBuf.Callable,
|
||||
proto: ProtoBuf.Property,
|
||||
signature: JvmProtoBuf.JvmFieldSignature,
|
||||
nameResolver: NameResolver
|
||||
): Field? {
|
||||
@@ -293,12 +292,12 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
||||
|
||||
// Returns the JVM class which contains this callable. This class may be different from the one represented by descriptors
|
||||
// in case of top level functions (their bodies are in package parts), methods with implementations in interfaces, etc.
|
||||
private fun implClassForCallable(nameResolver: NameResolver, proto: ProtoBuf.Callable): Class<*>? {
|
||||
if (!proto.hasExtension(JvmProtoBuf.oldImplClassName)) return null
|
||||
private fun implClassForCallable(nameResolver: NameResolver, proto: ProtoBuf.Property): Class<*>? {
|
||||
if (!proto.hasExtension(JvmProtoBuf.propertyImplClassName)) return null
|
||||
|
||||
val implClassName = nameResolver.getName(proto.getExtension(JvmProtoBuf.oldImplClassName))
|
||||
val implClassName = nameResolver.getName(proto.getExtension(JvmProtoBuf.propertyImplClassName))
|
||||
// TODO: store fq name of impl class name in jvm_descriptors.proto
|
||||
val classId = ClassId(jClass.classId.getPackageFqName(), implClassName)
|
||||
val classId = ClassId(jClass.classId.packageFqName, implClassName)
|
||||
return jClass.safeClassLoader.loadClass(classId.asSingleFqName().asString())
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,7 @@ import java.lang.reflect.Method
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.jvm.internal.FunctionImpl
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.internal.JvmFunctionSignature.BuiltInFunction
|
||||
import kotlin.reflect.jvm.internal.JvmFunctionSignature.JavaConstructor
|
||||
import kotlin.reflect.jvm.internal.JvmFunctionSignature.JavaMethod
|
||||
import kotlin.reflect.jvm.internal.JvmFunctionSignature.KotlinFunction
|
||||
import kotlin.reflect.jvm.internal.JvmFunctionSignature.*
|
||||
|
||||
internal open class KFunctionImpl protected constructor(
|
||||
private val container: KDeclarationContainerImpl,
|
||||
@@ -54,9 +51,8 @@ internal open class KFunctionImpl protected constructor(
|
||||
override val caller: FunctionCaller<*> by ReflectProperties.lazySoft {
|
||||
val jvmSignature = RuntimeTypeMapper.mapSignature(descriptor)
|
||||
val member: Member? = when (jvmSignature) {
|
||||
is KotlinFunction ->
|
||||
if (name == "<init>") container.findConstructorBySignature(jvmSignature.signature, jvmSignature.nameResolver, isDeclared())
|
||||
else container.findMethodBySignature(jvmSignature.proto, jvmSignature.signature, jvmSignature.nameResolver, isDeclared())
|
||||
is KotlinConstructor -> container.findConstructorBySignature(jvmSignature.signature, jvmSignature.nameResolver, isDeclared())
|
||||
is KotlinFunction -> container.findMethodBySignature(jvmSignature.signature, jvmSignature.nameResolver, isDeclared())
|
||||
is JavaMethod -> jvmSignature.method
|
||||
is JavaConstructor -> jvmSignature.constructor
|
||||
is BuiltInFunction -> jvmSignature.getMember(container)
|
||||
@@ -80,13 +76,11 @@ internal open class KFunctionImpl protected constructor(
|
||||
val jvmSignature = RuntimeTypeMapper.mapSignature(descriptor)
|
||||
val member: Member? = when (jvmSignature) {
|
||||
is KotlinFunction -> {
|
||||
if (name == "<init>") {
|
||||
container.findDefaultConstructor(jvmSignature.signature, jvmSignature.nameResolver, isDeclared())
|
||||
}
|
||||
else {
|
||||
val isMember = !Modifier.isStatic(caller.member.modifiers)
|
||||
container.findDefaultMethod(jvmSignature.signature, jvmSignature.nameResolver, isMember, isDeclared())
|
||||
}
|
||||
container.findDefaultMethod(jvmSignature.signature, jvmSignature.nameResolver,
|
||||
!Modifier.isStatic(caller.member.modifiers), isDeclared())
|
||||
}
|
||||
is KotlinConstructor -> {
|
||||
container.findDefaultConstructor(jvmSignature.signature, jvmSignature.nameResolver, isDeclared())
|
||||
}
|
||||
else -> {
|
||||
// Java methods, Java constructors and built-ins don't have $default methods
|
||||
|
||||
@@ -116,9 +116,7 @@ private fun KPropertyImpl.Accessor<*>.computeCallerForAccessor(isGetter: Boolean
|
||||
}
|
||||
|
||||
val accessor = accessorSignature?.let { signature ->
|
||||
property.container.findMethodBySignature(
|
||||
jvmSignature.proto, signature, jvmSignature.nameResolver, Visibilities.isPrivate(descriptor.visibility)
|
||||
)
|
||||
property.container.findMethodBySignature(signature, jvmSignature.nameResolver, Visibilities.isPrivate(descriptor.visibility))
|
||||
}
|
||||
|
||||
when {
|
||||
|
||||
@@ -46,7 +46,16 @@ internal sealed class JvmFunctionSignature {
|
||||
abstract fun asString(): String
|
||||
|
||||
class KotlinFunction(
|
||||
val proto: ProtoBuf.Callable,
|
||||
val proto: ProtoBuf.Function,
|
||||
val signature: JvmProtoBuf.JvmMethodSignature,
|
||||
val nameResolver: NameResolver
|
||||
) : JvmFunctionSignature() {
|
||||
override fun asString(): String =
|
||||
nameResolver.getString(signature.name) + nameResolver.getString(signature.desc)
|
||||
}
|
||||
|
||||
class KotlinConstructor(
|
||||
val proto: ProtoBuf.Constructor,
|
||||
val signature: JvmProtoBuf.JvmMethodSignature,
|
||||
val nameResolver: NameResolver
|
||||
) : JvmFunctionSignature() {
|
||||
@@ -87,7 +96,7 @@ internal sealed class JvmPropertySignature {
|
||||
abstract fun asString(): String
|
||||
|
||||
class KotlinProperty(
|
||||
val proto: ProtoBuf.Callable,
|
||||
val proto: ProtoBuf.Property,
|
||||
val signature: JvmProtoBuf.JvmPropertySignature,
|
||||
val nameResolver: NameResolver
|
||||
) : JvmPropertySignature() {
|
||||
@@ -124,10 +133,14 @@ internal object RuntimeTypeMapper {
|
||||
when (function) {
|
||||
is DeserializedCallableMemberDescriptor -> {
|
||||
val proto = function.proto
|
||||
if (proto.hasExtension(JvmProtoBuf.oldMethodSignature)) {
|
||||
val signature = proto.getExtension(JvmProtoBuf.oldMethodSignature)
|
||||
if (proto is ProtoBuf.Function && proto.hasExtension(JvmProtoBuf.methodSignature)) {
|
||||
val signature = proto.getExtension(JvmProtoBuf.methodSignature)
|
||||
return JvmFunctionSignature.KotlinFunction(proto, signature, function.nameResolver)
|
||||
}
|
||||
if (proto is ProtoBuf.Constructor && proto.hasExtension(JvmProtoBuf.constructorSignature)) {
|
||||
val signature = proto.getExtension(JvmProtoBuf.constructorSignature)
|
||||
return JvmFunctionSignature.KotlinConstructor(proto, signature, function.nameResolver)
|
||||
}
|
||||
// If it's a deserialized function but has no JVM signature, it must be from built-ins
|
||||
return mapIntrinsicFunctionSignature(function) ?:
|
||||
throw KotlinReflectionInternalError("Reflection on built-in Kotlin types is not yet fully supported. " +
|
||||
@@ -153,10 +166,10 @@ internal object RuntimeTypeMapper {
|
||||
val property = DescriptorUtils.unwrapFakeOverride(possiblyOverriddenProperty)
|
||||
if (property is DeserializedPropertyDescriptor) {
|
||||
val proto = property.proto
|
||||
if (!proto.hasExtension(JvmProtoBuf.oldPropertySignature)) {
|
||||
if (!proto.hasExtension(JvmProtoBuf.propertySignature)) {
|
||||
throw KotlinReflectionInternalError("No metadata found for $property")
|
||||
}
|
||||
return JvmPropertySignature.KotlinProperty(proto, proto.getExtension(JvmProtoBuf.oldPropertySignature), property.nameResolver)
|
||||
return JvmPropertySignature.KotlinProperty(proto, proto.getExtension(JvmProtoBuf.propertySignature), property.nameResolver)
|
||||
}
|
||||
else if (property is JavaPropertyDescriptor) {
|
||||
val field = ((property.source as? JavaSourceElement)?.javaElement as? ReflectJavaField)?.member ?:
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package kotlin.reflect.jvm
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmNameResolver
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
|
||||
@@ -42,11 +41,11 @@ public fun <R> Function<R>.reflect(): KFunction<R>? {
|
||||
JvmProtoBuf.StringTableTypes.parseDelimitedFrom(input, JvmProtoBufUtil.EXTENSION_REGISTRY),
|
||||
callable.strings
|
||||
)
|
||||
val proto = ProtoBuf.Callable.parseFrom(input, JvmProtoBufUtil.EXTENSION_REGISTRY)
|
||||
val proto = ProtoBuf.Function.parseFrom(input, JvmProtoBufUtil.EXTENSION_REGISTRY)
|
||||
val moduleData = javaClass.getOrCreateModule()
|
||||
val context = DeserializationContext(moduleData.deserialization, nameResolver, moduleData.module,
|
||||
parentTypeDeserializer = null, typeParameters = listOf())
|
||||
val descriptor = MemberDeserializer(context).loadCallable(proto) as FunctionDescriptor
|
||||
val descriptor = MemberDeserializer(context).loadFunction(proto)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return KFunctionImpl(EmptyContainerForLocal, descriptor) as KFunction<R>
|
||||
}
|
||||
|
||||
+8
-4
@@ -39,9 +39,13 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<ClassIdWithTarget> {
|
||||
proto as ProtoBuf.Callable // TODO
|
||||
|
||||
return proto.getExtension(JsProtoBuf.callableAnnotation).orEmpty().map {
|
||||
val annotations = when (proto) {
|
||||
is ProtoBuf.Constructor -> proto.getExtension(JsProtoBuf.constructorAnnotation)
|
||||
is ProtoBuf.Function -> proto.getExtension(JsProtoBuf.functionAnnotation)
|
||||
is ProtoBuf.Property -> proto.getExtension(JsProtoBuf.propertyAnnotation)
|
||||
else -> error("Unknown message: $proto")
|
||||
}.orEmpty()
|
||||
return annotations.map {
|
||||
ClassIdWithTarget(container.nameResolver.getClassId(it.id), null)
|
||||
}
|
||||
}
|
||||
@@ -71,7 +75,7 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon
|
||||
|
||||
override fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Callable,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: JetType
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,20 @@ extend Class {
|
||||
}
|
||||
|
||||
extend Callable {
|
||||
repeated Annotation callable_annotation = 130;
|
||||
repeated Annotation old_callable_annotation = 130;
|
||||
optional Annotation.Argument.Value old_compile_time_value = 131;
|
||||
}
|
||||
|
||||
extend Constructor {
|
||||
repeated Annotation constructor_annotation = 130;
|
||||
}
|
||||
|
||||
extend Function {
|
||||
repeated Annotation function_annotation = 130;
|
||||
}
|
||||
|
||||
extend Property {
|
||||
repeated Annotation property_annotation = 130;
|
||||
optional Annotation.Argument.Value compile_time_value = 131;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,11 @@ public final class JsProtoBuf {
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.classAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.callableAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.oldCallableAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.oldCompileTimeValue);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.constructorAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.functionAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.propertyAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.compileTimeValue);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.parameterAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.typeAnnotation);
|
||||
@@ -1477,14 +1481,14 @@ public final class JsProtoBuf {
|
||||
130,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE,
|
||||
false);
|
||||
public static final int CALLABLE_ANNOTATION_FIELD_NUMBER = 130;
|
||||
public static final int OLD_CALLABLE_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Callable { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Callable,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>> callableAnnotation = com.google.protobuf.GeneratedMessageLite
|
||||
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>> oldCallableAnnotation = com.google.protobuf.GeneratedMessageLite
|
||||
.newRepeatedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Callable.getDefaultInstance(),
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.getDefaultInstance(),
|
||||
@@ -1492,14 +1496,14 @@ public final class JsProtoBuf {
|
||||
130,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE,
|
||||
false);
|
||||
public static final int COMPILE_TIME_VALUE_FIELD_NUMBER = 131;
|
||||
public static final int OLD_COMPILE_TIME_VALUE_FIELD_NUMBER = 131;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Callable { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Callable,
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument.Value> compileTimeValue = com.google.protobuf.GeneratedMessageLite
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument.Value> oldCompileTimeValue = com.google.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Callable.getDefaultInstance(),
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument.Value.getDefaultInstance(),
|
||||
@@ -1507,6 +1511,66 @@ public final class JsProtoBuf {
|
||||
null,
|
||||
131,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE);
|
||||
public static final int CONSTRUCTOR_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Constructor { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Constructor,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>> constructorAnnotation = com.google.protobuf.GeneratedMessageLite
|
||||
.newRepeatedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Constructor.getDefaultInstance(),
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.getDefaultInstance(),
|
||||
null,
|
||||
130,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE,
|
||||
false);
|
||||
public static final int FUNCTION_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Function { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Function,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>> functionAnnotation = com.google.protobuf.GeneratedMessageLite
|
||||
.newRepeatedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Function.getDefaultInstance(),
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.getDefaultInstance(),
|
||||
null,
|
||||
130,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE,
|
||||
false);
|
||||
public static final int PROPERTY_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Property { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Property,
|
||||
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>> propertyAnnotation = com.google.protobuf.GeneratedMessageLite
|
||||
.newRepeatedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Property.getDefaultInstance(),
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.getDefaultInstance(),
|
||||
null,
|
||||
130,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE,
|
||||
false);
|
||||
public static final int COMPILE_TIME_VALUE_FIELD_NUMBER = 131;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Property { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Property,
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument.Value> compileTimeValue = com.google.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Property.getDefaultInstance(),
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument.Value.getDefaultInstance(),
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Argument.Value.getDefaultInstance(),
|
||||
null,
|
||||
131,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE);
|
||||
public static final int PARAMETER_ANNOTATION_FIELD_NUMBER = 130;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.ValueParameter { ... }</code>
|
||||
|
||||
+7
-4
@@ -43,9 +43,12 @@ class KotlinJavascriptAnnotationAndConstantLoader(
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<AnnotationWithTarget> {
|
||||
proto as ProtoBuf.Callable // TODO
|
||||
|
||||
val annotations = proto.getExtension(JsProtoBuf.callableAnnotation).orEmpty()
|
||||
val annotations = when (proto) {
|
||||
is ProtoBuf.Constructor -> proto.getExtension(JsProtoBuf.constructorAnnotation)
|
||||
is ProtoBuf.Function -> proto.getExtension(JsProtoBuf.functionAnnotation)
|
||||
is ProtoBuf.Property -> proto.getExtension(JsProtoBuf.propertyAnnotation)
|
||||
else -> error("Unknown message: $proto")
|
||||
}.orEmpty()
|
||||
return annotations.map { proto -> AnnotationWithTarget(deserializer.deserializeAnnotation(proto, container.nameResolver), null) }
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ class KotlinJavascriptAnnotationAndConstantLoader(
|
||||
|
||||
override fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Callable,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: JetType
|
||||
): ConstantValue<*>? {
|
||||
val value = proto.getExtension(JsProtoBuf.compileTimeValue)
|
||||
|
||||
+18
-10
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||
import org.jetbrains.kotlin.serialization.AnnotationSerializer
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
@@ -39,13 +36,24 @@ public class KotlinJavascriptSerializerExtension : SerializerExtension() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeCallable(callable: CallableMemberDescriptor, proto: ProtoBuf.Callable.Builder) {
|
||||
for (annotation in callable.annotations) {
|
||||
proto.addExtension(JsProtoBuf.callableAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||
override fun serializeConstructor(descriptor: ConstructorDescriptor, proto: ProtoBuf.Constructor.Builder) {
|
||||
for (annotation in descriptor.annotations) {
|
||||
proto.addExtension(JsProtoBuf.constructorAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||
}
|
||||
val propertyDescriptor = callable as? PropertyDescriptor ?: return
|
||||
val constantInitializer = propertyDescriptor.compileTimeInitializer
|
||||
if (constantInitializer != null && constantInitializer !is NullValue) {
|
||||
}
|
||||
|
||||
override fun serializeFunction(descriptor: FunctionDescriptor, proto: ProtoBuf.Function.Builder) {
|
||||
for (annotation in descriptor.annotations) {
|
||||
proto.addExtension(JsProtoBuf.functionAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeProperty(descriptor: PropertyDescriptor, proto: ProtoBuf.Property.Builder) {
|
||||
for (annotation in descriptor.annotations) {
|
||||
proto.addExtension(JsProtoBuf.propertyAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||
}
|
||||
val constantInitializer = descriptor.compileTimeInitializer ?: return
|
||||
if (constantInitializer !is NullValue) {
|
||||
proto.setExtension(JsProtoBuf.compileTimeValue, annotationSerializer.valueProto(constantInitializer).build())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user