prepare to retire Type.Constructor message in descriptors.proto after M13
This commit is contained in:
@@ -39,6 +39,8 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeConstructorKind
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getTypeConstructorData
|
||||
import java.lang.reflect.GenericDeclaration
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.Constructor
|
||||
@@ -158,9 +160,10 @@ class LazyOperationsLog(
|
||||
val typeDeserializer = o.field<TypeDeserializer>("typeDeserializer")
|
||||
val context = typeDeserializer.field<DeserializationContext>("c")
|
||||
val typeProto = o.field<ProtoBuf.Type>("typeProto")
|
||||
val text = when (typeProto.getConstructor().getKind()) {
|
||||
ProtoBuf.Type.Constructor.Kind.CLASS -> context.nameResolver.getFqName(typeProto.getConstructor().getId()).asString()
|
||||
ProtoBuf.Type.Constructor.Kind.TYPE_PARAMETER -> {
|
||||
val typeConstructorData = typeProto.getTypeConstructorData()
|
||||
val text = when (typeConstructorData.kind) {
|
||||
TypeConstructorKind.CLASS -> context.nameResolver.getFqName(typeConstructorData.id).asString()
|
||||
TypeConstructorKind.TYPE_PARAMETER -> {
|
||||
val classifier = (o as JetType).getConstructor().getDeclarationDescriptor()!!
|
||||
"" + classifier.getName() + " in " + DescriptorUtils.getFqName(classifier.getContainingDeclaration())
|
||||
}
|
||||
|
||||
+36
-12
@@ -25,6 +25,31 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
public enum class TypeConstructorKind {
|
||||
CLASS,
|
||||
TYPE_PARAMETER
|
||||
}
|
||||
|
||||
public data class TypeConstructorData(val kind: TypeConstructorKind, val id: Int)
|
||||
|
||||
public fun ProtoBuf.Type.getTypeConstructorData(): TypeConstructorData {
|
||||
if (hasConstructorClassName()) {
|
||||
assert(!hasConstructorTypeParameter(), "constructor_class_name already presents, so constructor_type_parameter should not be here")
|
||||
return TypeConstructorData(TypeConstructorKind.CLASS, constructorClassName)
|
||||
}
|
||||
else if (hasConstructorTypeParameter()) {
|
||||
assert(!hasConstructorClassName(), "constructor_type_parameter already presents, so constructor_class_name should not be here")
|
||||
return TypeConstructorData(TypeConstructorKind.TYPE_PARAMETER, constructorTypeParameter)
|
||||
}
|
||||
else {
|
||||
return when (constructor.kind) {
|
||||
ProtoBuf.Type.Constructor.Kind.CLASS -> TypeConstructorData(TypeConstructorKind.CLASS, constructor.id)
|
||||
ProtoBuf.Type.Constructor.Kind.TYPE_PARAMETER -> TypeConstructorData(TypeConstructorKind.TYPE_PARAMETER, constructor.id)
|
||||
else -> throw IllegalStateException("Unknown kind ${constructor.kind}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeDeserializer(
|
||||
private val c: DeserializationContext,
|
||||
private val parent: TypeDeserializer?,
|
||||
@@ -71,25 +96,24 @@ public class TypeDeserializer(
|
||||
}
|
||||
|
||||
fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor {
|
||||
val constructorProto = proto.getConstructor()
|
||||
val id = constructorProto.getId()
|
||||
return typeConstructor(constructorProto) ?: ErrorUtils.createErrorType(
|
||||
if (constructorProto.getKind() == ProtoBuf.Type.Constructor.Kind.CLASS)
|
||||
val typeConstructorData = proto.getTypeConstructorData()
|
||||
val id = typeConstructorData.id
|
||||
return typeConstructor(typeConstructorData) ?: ErrorUtils.createErrorType(
|
||||
if (typeConstructorData.kind == TypeConstructorKind.CLASS)
|
||||
c.nameResolver.getClassId(id).asSingleFqName().asString()
|
||||
else
|
||||
"Unknown type parameter $id"
|
||||
).getConstructor()
|
||||
).constructor
|
||||
}
|
||||
|
||||
private fun typeConstructor(proto: ProtoBuf.Type.Constructor): TypeConstructor? = when (proto.getKind()) {
|
||||
ProtoBuf.Type.Constructor.Kind.CLASS -> classDescriptors(proto.getId())?.getTypeConstructor()
|
||||
ProtoBuf.Type.Constructor.Kind.TYPE_PARAMETER -> typeParameterTypeConstructor(proto)
|
||||
else -> throw IllegalStateException("Unknown kind ${proto.getKind()}")
|
||||
private fun typeConstructor(data: TypeConstructorData): TypeConstructor? = when (data.kind) {
|
||||
TypeConstructorKind.CLASS -> classDescriptors(data.id)?.typeConstructor
|
||||
TypeConstructorKind.TYPE_PARAMETER -> typeParameterTypeConstructor(data.id)
|
||||
}
|
||||
|
||||
private fun typeParameterTypeConstructor(proto: ProtoBuf.Type.Constructor): TypeConstructor? =
|
||||
typeParameterDescriptors().get(proto.getId())?.getTypeConstructor() ?:
|
||||
parent?.typeParameterTypeConstructor(proto)
|
||||
private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? =
|
||||
typeParameterDescriptors().get(typeParameterId)?.typeConstructor ?:
|
||||
parent?.typeParameterTypeConstructor(typeParameterId)
|
||||
|
||||
private fun computeClassDescriptor(fqNameIndex: Int): ClassDescriptor? {
|
||||
val id = c.nameResolver.getClassId(fqNameIndex)
|
||||
|
||||
+5
-3
@@ -36,8 +36,9 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinObjectStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl
|
||||
import org.jetbrains.kotlin.serialization.Flags
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Type
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeConstructorKind
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getTypeConstructorData
|
||||
|
||||
|
||||
fun createClassStub(parent: StubElement<out PsiElement>, classProto: ProtoBuf.Class, classId: ClassId, context: ClsStubBuilderContext) {
|
||||
@@ -55,8 +56,9 @@ private class ClassClsStubBuilder(
|
||||
private val classKind = Flags.CLASS_KIND[classProto.getFlags()]
|
||||
private val supertypeIds = classProto.getSupertypeList().map {
|
||||
type ->
|
||||
assert(type.getConstructor().getKind() == Type.Constructor.Kind.CLASS)
|
||||
c.nameResolver.getClassId(type.getConstructor().getId())
|
||||
val typeConstructorData = type.getTypeConstructorData()
|
||||
assert(typeConstructorData.kind == TypeConstructorKind.CLASS)
|
||||
c.nameResolver.getClassId(typeConstructorData.id)
|
||||
}.let {
|
||||
supertypeIds ->
|
||||
//empty supertype list if single supertype is Any
|
||||
|
||||
+11
-8
@@ -36,6 +36,8 @@ import org.jetbrains.kotlin.serialization.ProtoBuf.Type
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument.Projection
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.Variance
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeConstructorKind
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getTypeConstructorData
|
||||
import org.jetbrains.kotlin.types.DynamicTypeCapabilities
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.ArrayList
|
||||
@@ -54,13 +56,14 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
if (type.getNullable()) KotlinPlaceHolderStubImpl<JetNullableType>(typeReference, JetStubElementTypes.NULLABLE_TYPE)
|
||||
else typeReference
|
||||
|
||||
when (type.getConstructor().getKind()) {
|
||||
Type.Constructor.Kind.CLASS -> {
|
||||
val typeConstructorData = type.getTypeConstructorData()
|
||||
when (typeConstructorData.kind) {
|
||||
TypeConstructorKind.CLASS -> {
|
||||
createClassReferenceTypeStub(effectiveParent, type, annotations)
|
||||
}
|
||||
Type.Constructor.Kind.TYPE_PARAMETER -> {
|
||||
TypeConstructorKind.TYPE_PARAMETER -> {
|
||||
createTypeAnnotationStubs(effectiveParent, annotations)
|
||||
val typeParameterName = c.typeParameters[type.getConstructor().getId()]
|
||||
val typeParameterName = c.typeParameters[typeConstructorData.id]
|
||||
createStubForTypeName(ClassId.topLevel(FqName.topLevel(typeParameterName)), effectiveParent)
|
||||
}
|
||||
}
|
||||
@@ -237,11 +240,11 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
}
|
||||
|
||||
private fun Type.isDefaultUpperBound(): Boolean {
|
||||
val constructor = getConstructor()
|
||||
if (constructor.getKind() != Type.Constructor.Kind.CLASS) {
|
||||
val typeConstructorData = getTypeConstructorData()
|
||||
if (typeConstructorData.kind != TypeConstructorKind.CLASS) {
|
||||
return false
|
||||
}
|
||||
val classId = c.nameResolver.getClassId(constructor.getId())
|
||||
return KotlinBuiltIns.isAny(classId.asSingleFqName().toUnsafe()) && this.getNullable()
|
||||
val classId = c.nameResolver.getClassId(typeConstructorData.id)
|
||||
return KotlinBuiltIns.isAny(classId.asSingleFqName().toUnsafe()) && this.nullable
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user