Serialization of star projections fixed

This commit is contained in:
Andrey Breslav
2015-03-04 14:24:04 +03:00
parent 61989ba245
commit 266485add3
15 changed files with 159 additions and 72 deletions
+1 -1
View File
@@ -121,7 +121,7 @@ message Type {
}
optional Projection projection = 1 [default = INV];
required Type type = 2;
optional Type type = 2; // when projection is STAR, no type is written, otherwise type must be specified
}
repeated Argument argument = 2;
@@ -350,9 +350,9 @@ public class DescriptorSerializer {
if (projection != ProtoBuf.Type.Argument.Projection.INV) {
builder.setProjection(projection);
}
builder.setType(type(typeProjection.getType()));
}
builder.setType(type(typeProjection.getType()));
return builder;
}
@@ -5004,13 +5004,13 @@ public final class ProtoBuf {
*/
org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument.Projection getProjection();
// required .org.jetbrains.kotlin.serialization.Type type = 2;
// optional .org.jetbrains.kotlin.serialization.Type type = 2;
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
boolean hasType();
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
org.jetbrains.kotlin.serialization.ProtoBuf.Type getType();
}
@@ -5196,17 +5196,17 @@ public final class ProtoBuf {
return projection_;
}
// required .org.jetbrains.kotlin.serialization.Type type = 2;
// optional .org.jetbrains.kotlin.serialization.Type type = 2;
public static final int TYPE_FIELD_NUMBER = 2;
private org.jetbrains.kotlin.serialization.ProtoBuf.Type type_;
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public boolean hasType() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.Type getType() {
return type_;
@@ -5221,13 +5221,11 @@ public final class ProtoBuf {
byte isInitialized = memoizedIsInitialized;
if (isInitialized != -1) return isInitialized == 1;
if (!hasType()) {
memoizedIsInitialized = 0;
return false;
}
if (!getType().isInitialized()) {
memoizedIsInitialized = 0;
return false;
if (hasType()) {
if (!getType().isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
memoizedIsInitialized = 1;
return true;
@@ -5400,13 +5398,11 @@ public final class ProtoBuf {
}
public final boolean isInitialized() {
if (!hasType()) {
return false;
}
if (!getType().isInitialized()) {
return false;
if (hasType()) {
if (!getType().isInitialized()) {
return false;
}
}
return true;
}
@@ -5466,22 +5462,22 @@ public final class ProtoBuf {
return this;
}
// required .org.jetbrains.kotlin.serialization.Type type = 2;
// optional .org.jetbrains.kotlin.serialization.Type type = 2;
private org.jetbrains.kotlin.serialization.ProtoBuf.Type type_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public boolean hasType() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.Type getType() {
return type_;
}
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public Builder setType(org.jetbrains.kotlin.serialization.ProtoBuf.Type value) {
if (value == null) {
@@ -5493,7 +5489,7 @@ public final class ProtoBuf {
return this;
}
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public Builder setType(
org.jetbrains.kotlin.serialization.ProtoBuf.Type.Builder builderForValue) {
@@ -5503,7 +5499,7 @@ public final class ProtoBuf {
return this;
}
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public Builder mergeType(org.jetbrains.kotlin.serialization.ProtoBuf.Type value) {
if (((bitField0_ & 0x00000002) == 0x00000002) &&
@@ -5518,7 +5514,7 @@ public final class ProtoBuf {
return this;
}
/**
* <code>required .org.jetbrains.kotlin.serialization.Type type = 2;</code>
* <code>optional .org.jetbrains.kotlin.serialization.Type type = 2;</code>
*/
public Builder clearType() {
type_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList
class DeserializedType(
c: DeserializationContext,
@@ -33,7 +34,12 @@ class DeserializedType(
typeDeserializer.typeConstructor(typeProto)
}
private val arguments = typeDeserializer.typeArguments(typeProto.getArgumentList())
private val arguments = c.storageManager.createLazyValue {
typeProto.getArgumentList().mapIndexed {
index, proto ->
typeDeserializer.typeArgument(getConstructor().getParameters().getOrNull(index), proto)
}.toReadOnlyList()
}
private val memberScope = c.storageManager.createLazyValue {
computeMemberScope()
@@ -41,7 +47,7 @@ class DeserializedType(
override fun getConstructor(): TypeConstructor = constructor()
override fun getArguments(): List<TypeProjection> = arguments
override fun getArguments(): List<TypeProjection> = arguments()
override fun isMarkedNullable(): Boolean = typeProto.getNullable()
@@ -70,4 +76,8 @@ class DeserializedType(
}
override fun getAnnotations(): Annotations = Annotations.EMPTY
private fun <E: Any> List<E>.getOrNull(index: Int): E? {
return if (index in indices) this[index] else null
}
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.serialization.ProtoBuf
@@ -99,13 +100,14 @@ public class TypeDeserializer(
return c.components.moduleDescriptor.findClassAcrossModuleDependencies(id)
}
fun typeArguments(protos: List<ProtoBuf.Type.Argument>): List<TypeProjection> =
protos.map { proto ->
val type = type(proto.getType())
if (proto.getProjection() == ProtoBuf.Type.Argument.Projection.STAR)
TypeBasedStarProjectionImpl(type)
else TypeProjectionImpl(variance(proto.getProjection()), type)
}.toReadOnlyList()
fun typeArgument(parameter: TypeParameterDescriptor?, typeArgumentProto: ProtoBuf.Type.Argument): TypeProjection {
return if (typeArgumentProto.getProjection() == ProtoBuf.Type.Argument.Projection.STAR)
if (parameter == null)
TypeBasedStarProjectionImpl(KotlinBuiltIns.getInstance().getNullableAnyType())
else
StarProjectionImpl(parameter)
else TypeProjectionImpl(variance(typeArgumentProto.getProjection()), type(typeArgumentProto.getType()))
}
override fun toString() = debugName + (if (parent == null) "" else ". Child of ${parent.debugName}")
}