Deserialize property and field annotations

This commit is contained in:
Yan Zhulanow
2015-08-06 15:53:29 +03:00
parent f86fe6a8d5
commit 1b9dab47ec
7 changed files with 67 additions and 30 deletions
@@ -34,6 +34,9 @@ import org.jetbrains.kotlin.types.JetType
import java.util.ArrayList
import java.util.HashMap
import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind.PROPERTY_SYNTHETIC_FUNCTION
import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind.PROPERTY_FIELD
public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any>(
storageManager: StorageManager,
private val kotlinClassFinder: KotlinClassFinder,
@@ -182,11 +185,14 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
val classProto = container.classProto!!
val classKind = Flags.CLASS_KIND[classProto.getFlags()]
val classId = nameResolver.getClassId(classProto.getFqName())
if (classKind == ProtoBuf.Class.Kind.CLASS_OBJECT && isStaticFieldInOuter(proto)) {
if (classKind == ProtoBuf.Class.Kind.CLASS_OBJECT && isStaticFieldInOuter(proto)
&& annotatedCallableKind != AnnotatedCallableKind.PROPERTY_SYNTHETIC_FUNCTION) {
// Backing fields of properties of a companion object are generated in the outer class
return kotlinClassFinder.findKotlinClass(classId.getOuterClassId())
}
else if (classKind == ProtoBuf.Class.Kind.TRAIT && annotatedCallableKind == AnnotatedCallableKind.PROPERTY) {
else if (classKind == ProtoBuf.Class.Kind.TRAIT &&
(annotatedCallableKind == PROPERTY_SYNTHETIC_FUNCTION || annotatedCallableKind == PROPERTY_FIELD)) {
if (proto.hasExtension(implClassName)) {
val parentPackageFqName = classId.getPackageFqName()
val tImplName = nameResolver.getName(proto.getExtension(implClassName))
@@ -282,6 +288,25 @@ private fun getCallableSignature(
kind: AnnotatedCallableKind
): MemberSignature? {
val deserializer = SignatureDeserializer(nameResolver)
fun getPropertySignature(handleField: Boolean = false, handleSynthetic: Boolean = false): MemberSignature? {
if (!proto.hasExtension(propertySignature)) return null
val propertySignature = proto.getExtension(propertySignature)
if (handleField && propertySignature.hasField()) {
val field = propertySignature.getField()
val type = deserializer.typeDescriptor(field.getType())
val name = nameResolver.getName(field.getName())
return MemberSignature.fromFieldNameAndDesc(name, type)
}
else if (handleSynthetic && propertySignature.hasSyntheticMethod()) {
return deserializer.methodSignature(propertySignature.getSyntheticMethod())
}
return null
}
when (kind) {
AnnotatedCallableKind.FUNCTION -> if (proto.hasExtension(methodSignature)) {
return deserializer.methodSignature(proto.getExtension(methodSignature))
@@ -292,19 +317,9 @@ private fun getCallableSignature(
AnnotatedCallableKind.PROPERTY_SETTER -> if (proto.hasExtension(propertySignature)) {
return deserializer.methodSignature(proto.getExtension(propertySignature).getSetter())
}
AnnotatedCallableKind.PROPERTY -> if (proto.hasExtension(propertySignature)) {
val propertySignature = proto.getExtension(propertySignature)
if (propertySignature.hasField()) {
val field = propertySignature.getField()
val type = deserializer.typeDescriptor(field.getType())
val name = nameResolver.getName(field.getName())
return MemberSignature.fromFieldNameAndDesc(name, type)
}
else if (propertySignature.hasSyntheticMethod()) {
return deserializer.methodSignature(propertySignature.getSyntheticMethod())
}
}
AnnotatedCallableKind.PROPERTY -> return getPropertySignature(true, true)
AnnotatedCallableKind.PROPERTY_FIELD -> return getPropertySignature(handleField = true)
AnnotatedCallableKind.PROPERTY_SYNTHETIC_FUNCTION -> return getPropertySignature(handleSynthetic = true)
}
return null
}