Improve hack in BuiltInsSerializerExtension for ranges
Serialize class names as qualified names in the string table, not as simple strings. Otherwise NameResolverImpl crashes on deserialization because it expects that all class names are indices into QualifiedName table
This commit is contained in:
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||
|
||||
import java.io.OutputStream
|
||||
|
||||
interface StringTable {
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.utils.Interner
|
||||
@@ -58,24 +58,19 @@ open class StringTableImpl : StringTable {
|
||||
throw IllegalStateException("Cannot get FQ name of error class: $descriptor")
|
||||
}
|
||||
|
||||
val classId = descriptor.classId ?: return getFqNameIndexOfLocalAnonymousClass(descriptor)
|
||||
return getClassIdIndex(classId)
|
||||
}
|
||||
|
||||
fun getClassIdIndex(classId: ClassId): Int {
|
||||
val builder = QualifiedName.newBuilder()
|
||||
builder.kind = QualifiedName.Kind.CLASS
|
||||
|
||||
val containingDeclaration = descriptor.containingDeclaration
|
||||
when (containingDeclaration) {
|
||||
is PackageFragmentDescriptor -> {
|
||||
val packageFqName = containingDeclaration.fqName
|
||||
if (!packageFqName.isRoot) {
|
||||
builder.parentQualifiedName = getPackageFqNameIndex(packageFqName)
|
||||
}
|
||||
}
|
||||
is ClassDescriptor -> {
|
||||
builder.parentQualifiedName = getFqNameIndex(containingDeclaration)
|
||||
}
|
||||
else -> return getFqNameIndexOfLocalAnonymousClass(descriptor)
|
||||
}
|
||||
builder.parentQualifiedName =
|
||||
classId.outerClassId?.let(this::getClassIdIndex)
|
||||
?: getPackageFqNameIndex(classId.packageFqName)
|
||||
|
||||
builder.shortName = getStringIndex(descriptor.name.asString())
|
||||
builder.shortName = getStringIndex(classId.shortClassName.asString())
|
||||
|
||||
return qualifiedNames.intern(FqNameProto(builder))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user