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
@@ -471,7 +471,11 @@ public class DescriptorSerializer {
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor) {
builder.setClassName(getClassId((ClassDescriptor) descriptor));
PossiblyInnerType possiblyInnerType = TypeParameterUtilsKt.buildPossiblyInnerType(type);
assert possiblyInnerType != null : "possiblyInnerType should not be null in case of class";
fillFromPossiblyInnerType(builder, possiblyInnerType);
}
if (descriptor instanceof TypeParameterDescriptor) {
TypeParameterDescriptor typeParameter = (TypeParameterDescriptor) descriptor;
@@ -481,10 +485,8 @@ public class DescriptorSerializer {
else {
builder.setTypeParameter(getTypeParameterId(typeParameter));
}
}
for (TypeProjection projection : type.getArguments()) {
builder.addArgument(typeArgument(projection));
assert type.getArguments().isEmpty() : "Found arguments for type constructor build on type parameter: " + descriptor;
}
if (type.isMarkedNullable() != builder.getNullable()) {
@@ -496,6 +498,29 @@ public class DescriptorSerializer {
return builder;
}
private void fillFromPossiblyInnerType(
@NotNull ProtoBuf.Type.Builder builder,
@NotNull PossiblyInnerType type
) {
builder.setClassName(getClassId(type.getClassDescriptor()));
for (TypeProjection projection : type.getArguments()) {
builder.addArgument(typeArgument(projection));
}
if (type.getOuterType() != null) {
ProtoBuf.Type.Builder outerBuilder = ProtoBuf.Type.newBuilder();
fillFromPossiblyInnerType(outerBuilder, type.getOuterType());
if (useTypeTable()) {
builder.setOuterTypeId(typeTable.get(outerBuilder));
}
else {
builder.setOuterType(outerBuilder);
}
}
}
@NotNull
private ProtoBuf.Type.Argument.Builder typeArgument(@NotNull TypeProjection typeProjection) {
ProtoBuf.Type.Argument.Builder builder = ProtoBuf.Type.Argument.newBuilder();