JS: serialize type of local anonymous class as its denotable supertype. See KT-14888

This commit is contained in:
Alexey Andreev
2016-12-13 12:54:08 +03:00
parent b08afb0e93
commit e6501591fa
9 changed files with 204 additions and 3 deletions
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.resolve.constants.NullValue
import org.jetbrains.kotlin.types.KotlinType
open class KotlinSerializerExtensionBase(private val protocol: SerializerExtensionProtocol) : SerializerExtension() {
override final val stringTable = StringTableImpl()
override val stringTable = StringTableImpl()
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder) {
for (annotation in descriptor.annotations) {
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.utils.Interner
import java.io.OutputStream
class StringTableImpl : StringTable {
open class StringTableImpl : StringTable {
private class FqNameProto(val fqName: QualifiedName.Builder) {
override fun hashCode(): Int {
var result = 13
@@ -72,7 +72,7 @@ class StringTableImpl : StringTable {
is ClassDescriptor -> {
builder.parentQualifiedName = getFqNameIndex(containingDeclaration)
}
else -> throw IllegalStateException("Cannot get FQ name of local class: " + descriptor)
else -> return getFqNameIndexOfLocalAnonymousClass(descriptor)
}
builder.shortName = getStringIndex(descriptor.name.asString())
@@ -80,6 +80,10 @@ class StringTableImpl : StringTable {
return qualifiedNames.intern(FqNameProto(builder))
}
open fun getFqNameIndexOfLocalAnonymousClass(descriptor: ClassifierDescriptorWithTypeParameters): Int {
throw IllegalStateException("Cannot get FQ name of local class: " + descriptor)
}
fun getPackageFqNameIndex(fqName: FqName): Int {
var result = -1
for (segment in fqName.pathSegments()) {