Serialize error type to proto when generating stubs

This commit is contained in:
Alexey Tsvetkov
2016-04-28 16:45:36 +03:00
parent 8d189bae55
commit f2ca788ea3
3 changed files with 23 additions and 3 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen.serialization;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.codegen.ClassBuilderMode;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
@@ -43,6 +44,7 @@ public class JvmSerializerExtension extends SerializerExtension {
private final AnnotationSerializer annotationSerializer;
private final boolean useTypeTable;
private final String moduleName;
private final ClassBuilderMode classBuilderMode;
public JvmSerializerExtension(@NotNull JvmSerializationBindings bindings, @NotNull GenerationState state) {
this.bindings = bindings;
@@ -50,6 +52,7 @@ public class JvmSerializerExtension extends SerializerExtension {
this.annotationSerializer = new AnnotationSerializer(stringTable);
this.useTypeTable = state.getUseTypeTableInSerializer();
this.moduleName = state.getModuleName();
this.classBuilderMode = state.getClassBuilderMode();
}
@NotNull
@@ -144,6 +147,16 @@ public class JvmSerializerExtension extends SerializerExtension {
proto.setExtension(JvmProtoBuf.propertySignature, signature);
}
@Override
public void serializeErrorType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder builder) {
if (classBuilderMode == ClassBuilderMode.LIGHT_CLASSES_WITH_METADATA) {
builder.setClassName(stringTable.getStringIndex("error.NonExistingClass"));
return;
}
super.serializeErrorType(type, builder);
}
private class SignatureSerializer {
@Nullable
public JvmProtoBuf.JvmMethodSignature methodSignature(@Nullable FunctionDescriptor descriptor, @NotNull Method method) {
@@ -459,7 +459,12 @@ public class DescriptorSerializer {
@NotNull
private ProtoBuf.Type.Builder type(@NotNull KotlinType type) {
assert !type.isError() : "Can't serialize error types: " + type; // TODO
ProtoBuf.Type.Builder builder = ProtoBuf.Type.newBuilder();
if (type.isError()) {
extension.serializeErrorType(type, builder);
return builder;
}
if (FlexibleTypesKt.isFlexible(type)) {
Flexibility flexibility = FlexibleTypesKt.flexibility(type);
@@ -475,8 +480,6 @@ public class DescriptorSerializer {
return lowerBound;
}
ProtoBuf.Type.Builder builder = ProtoBuf.Type.newBuilder();
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor) {
PossiblyInnerType possiblyInnerType = TypeParameterUtilsKt.buildPossiblyInnerType(type);
@@ -54,4 +54,8 @@ public abstract class SerializerExtension {
public void serializeTypeParameter(@NotNull TypeParameterDescriptor typeParameter, @NotNull ProtoBuf.TypeParameter.Builder proto) {
}
public void serializeErrorType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder builder) {
throw new IllegalStateException("Cannot serialize error type: " + type);
}
}