Implement serialization of inner types

This commit is contained in:
Denis Zharkov
2015-11-11 14:36:31 +03:00
parent 8cb85759c7
commit 7500447e72
13 changed files with 720 additions and 90 deletions
@@ -129,6 +129,9 @@ message Type {
// Name of the type parameter in the immediate owner
optional int32 type_parameter_name = 9 [(name_id_in_table) = true];
optional Type outer_type = 10;
optional int32 outer_type_id = 11;
extensions 100 to 199;
}
@@ -4353,6 +4353,26 @@ public final class ProtoBuf {
* </pre>
*/
int getTypeParameterName();
// optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
boolean hasOuterType();
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
org.jetbrains.kotlin.serialization.ProtoBuf.Type getOuterType();
// optional int32 outer_type_id = 11;
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
boolean hasOuterTypeId();
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
int getOuterTypeId();
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
@@ -4448,6 +4468,24 @@ public final class ProtoBuf {
typeParameterName_ = input.readInt32();
break;
}
case 82: {
org.jetbrains.kotlin.serialization.ProtoBuf.Type.Builder subBuilder = null;
if (((bitField0_ & 0x00000080) == 0x00000080)) {
subBuilder = outerType_.toBuilder();
}
outerType_ = input.readMessage(org.jetbrains.kotlin.serialization.ProtoBuf.Type.PARSER, extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(outerType_);
outerType_ = subBuilder.buildPartial();
}
bitField0_ |= 0x00000080;
break;
}
case 88: {
bitField0_ |= 0x00000100;
outerTypeId_ = input.readInt32();
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -5316,6 +5354,38 @@ public final class ProtoBuf {
return typeParameterName_;
}
// optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;
public static final int OUTER_TYPE_FIELD_NUMBER = 10;
private org.jetbrains.kotlin.serialization.ProtoBuf.Type outerType_;
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public boolean hasOuterType() {
return ((bitField0_ & 0x00000080) == 0x00000080);
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.Type getOuterType() {
return outerType_;
}
// optional int32 outer_type_id = 11;
public static final int OUTER_TYPE_ID_FIELD_NUMBER = 11;
private int outerTypeId_;
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
public boolean hasOuterTypeId() {
return ((bitField0_ & 0x00000100) == 0x00000100);
}
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
public int getOuterTypeId() {
return outerTypeId_;
}
private void initFields() {
argument_ = java.util.Collections.emptyList();
nullable_ = false;
@@ -5325,6 +5395,8 @@ public final class ProtoBuf {
className_ = 0;
typeParameter_ = 0;
typeParameterName_ = 0;
outerType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
outerTypeId_ = 0;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -5343,6 +5415,12 @@ public final class ProtoBuf {
return false;
}
}
if (hasOuterType()) {
if (!getOuterType().isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
if (!extensionsAreInitialized()) {
memoizedIsInitialized = 0;
return false;
@@ -5381,6 +5459,12 @@ public final class ProtoBuf {
if (((bitField0_ & 0x00000040) == 0x00000040)) {
output.writeInt32(9, typeParameterName_);
}
if (((bitField0_ & 0x00000080) == 0x00000080)) {
output.writeMessage(10, outerType_);
}
if (((bitField0_ & 0x00000100) == 0x00000100)) {
output.writeInt32(11, outerTypeId_);
}
extensionWriter.writeUntil(200, output);
}
@@ -5422,6 +5506,14 @@ public final class ProtoBuf {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(9, typeParameterName_);
}
if (((bitField0_ & 0x00000080) == 0x00000080)) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(10, outerType_);
}
if (((bitField0_ & 0x00000100) == 0x00000100)) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(11, outerTypeId_);
}
size += extensionsSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -5529,6 +5621,10 @@ public final class ProtoBuf {
bitField0_ = (bitField0_ & ~0x00000040);
typeParameterName_ = 0;
bitField0_ = (bitField0_ & ~0x00000080);
outerType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000100);
outerTypeId_ = 0;
bitField0_ = (bitField0_ & ~0x00000200);
return this;
}
@@ -5585,6 +5681,14 @@ public final class ProtoBuf {
to_bitField0_ |= 0x00000040;
}
result.typeParameterName_ = typeParameterName_;
if (((from_bitField0_ & 0x00000100) == 0x00000100)) {
to_bitField0_ |= 0x00000080;
}
result.outerType_ = outerType_;
if (((from_bitField0_ & 0x00000200) == 0x00000200)) {
to_bitField0_ |= 0x00000100;
}
result.outerTypeId_ = outerTypeId_;
result.bitField0_ = to_bitField0_;
return result;
}
@@ -5622,6 +5726,12 @@ public final class ProtoBuf {
if (other.hasTypeParameterName()) {
setTypeParameterName(other.getTypeParameterName());
}
if (other.hasOuterType()) {
mergeOuterType(other.getOuterType());
}
if (other.hasOuterTypeId()) {
setOuterTypeId(other.getOuterTypeId());
}
this.mergeExtensionFields(other);
return this;
}
@@ -5639,6 +5749,12 @@ public final class ProtoBuf {
return false;
}
}
if (hasOuterType()) {
if (!getOuterType().isInitialized()) {
return false;
}
}
if (!extensionsAreInitialized()) {
return false;
@@ -6101,6 +6217,100 @@ public final class ProtoBuf {
return this;
}
// optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;
private org.jetbrains.kotlin.serialization.ProtoBuf.Type outerType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public boolean hasOuterType() {
return ((bitField0_ & 0x00000100) == 0x00000100);
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.Type getOuterType() {
return outerType_;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public Builder setOuterType(org.jetbrains.kotlin.serialization.ProtoBuf.Type value) {
if (value == null) {
throw new NullPointerException();
}
outerType_ = value;
bitField0_ |= 0x00000100;
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public Builder setOuterType(
org.jetbrains.kotlin.serialization.ProtoBuf.Type.Builder builderForValue) {
outerType_ = builderForValue.build();
bitField0_ |= 0x00000100;
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public Builder mergeOuterType(org.jetbrains.kotlin.serialization.ProtoBuf.Type value) {
if (((bitField0_ & 0x00000100) == 0x00000100) &&
outerType_ != org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance()) {
outerType_ =
org.jetbrains.kotlin.serialization.ProtoBuf.Type.newBuilder(outerType_).mergeFrom(value).buildPartial();
} else {
outerType_ = value;
}
bitField0_ |= 0x00000100;
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.Type outer_type = 10;</code>
*/
public Builder clearOuterType() {
outerType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000100);
return this;
}
// optional int32 outer_type_id = 11;
private int outerTypeId_ ;
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
public boolean hasOuterTypeId() {
return ((bitField0_ & 0x00000200) == 0x00000200);
}
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
public int getOuterTypeId() {
return outerTypeId_;
}
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
public Builder setOuterTypeId(int value) {
bitField0_ |= 0x00000200;
outerTypeId_ = value;
return this;
}
/**
* <code>optional int32 outer_type_id = 11;</code>
*/
public Builder clearOuterTypeId() {
bitField0_ = (bitField0_ & ~0x00000200);
outerTypeId_ = 0;
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type)
}
@@ -20,9 +20,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets
import org.jetbrains.kotlin.types.AbstractLazyType
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.LazyType
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList
class DeserializedType(
@@ -34,11 +32,16 @@ class DeserializedType(
override fun computeTypeConstructor() = typeDeserializer.typeConstructor(typeProto)
override fun computeArguments() =
typeProto.argumentList.mapIndexed {
index, proto ->
typeDeserializer.typeArgument(constructor.parameters.getOrNull(index), proto)
}.toReadOnlyList()
override fun computeArguments() = typeProto.collectAllArguments().deserialize()
private fun ProtoBuf.Type.collectAllArguments(): List<ProtoBuf.Type.Argument> =
argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty()
private fun List<ProtoBuf.Type.Argument>.deserialize(): List<TypeProjection> =
mapIndexed {
index, proto ->
typeDeserializer.typeArgument(constructor.parameters.getOrNull(index), proto)
}.toReadOnlyList()
private val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
c.components.annotationAndConstantLoader
@@ -78,3 +78,11 @@ fun ProtoBuf.ValueParameter.varargElementType(typeTable: TypeTable): ProtoBuf.Ty
else -> null
}
}
fun ProtoBuf.Type.outerType(typeTable: TypeTable): ProtoBuf.Type? {
return when {
hasOuterType() -> outerType
hasOuterTypeId() -> typeTable[outerTypeId]
else -> null
}
}