Refactoring. Removed all usages of asSimpleType except related to TypeSubstitution.
This commit is contained in:
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
interface TypeAliasDescriptor : ClassifierDescriptorWithTypeParameters, MemberDescriptor {
|
||||
val underlyingType: KotlinType
|
||||
val underlyingType: SimpleType
|
||||
|
||||
val expandedType: KotlinType
|
||||
val expandedType: SimpleType
|
||||
|
||||
val classDescriptor: ClassDescriptor?
|
||||
|
||||
|
||||
@@ -123,12 +123,12 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
private fun renderNormalizedType(type: KotlinType): String {
|
||||
val abbreviated = type.getAbbreviatedType()
|
||||
val abbreviated = (type.unwrap() as? AbbreviatedType)
|
||||
|
||||
if (abbreviated != null) {
|
||||
// TODO nullability is lost for abbreviated type?
|
||||
val abbreviatedRendered = renderNormalizedTypeAsIs(abbreviated)
|
||||
val unabbreviatedRendered = renderNormalizedTypeAsIs(type)
|
||||
val abbreviatedRendered = renderNormalizedTypeAsIs(abbreviated.abbreviation)
|
||||
val unabbreviatedRendered = renderNormalizedTypeAsIs(abbreviated.expandedType)
|
||||
return "$abbreviatedRendered [= $unabbreviatedRendered]"
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,3 @@ abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleTy
|
||||
override fun toString(): String = DescriptorRenderer.DEBUG_TEXT.renderType(this)
|
||||
}
|
||||
|
||||
@Deprecated("Temporary marker method for refactoring")
|
||||
fun KotlinType.asSimpleType(): SimpleType {
|
||||
return unwrap() as SimpleType
|
||||
}
|
||||
|
||||
@@ -29,19 +29,21 @@ abstract class DelegatingSimpleType : SimpleType() {
|
||||
override val memberScope: MemberScope get() = delegate.memberScope
|
||||
}
|
||||
|
||||
private class AbbreviatedType(override val delegate: SimpleType, val abbreviatedType: SimpleType) : DelegatingSimpleType() {
|
||||
class AbbreviatedType(override val delegate: SimpleType, val abbreviation: SimpleType) : DelegatingSimpleType() {
|
||||
val expandedType: SimpleType get() = delegate
|
||||
|
||||
override fun replaceAnnotations(newAnnotations: Annotations)
|
||||
= AbbreviatedType(delegate.replaceAnnotations(newAnnotations), abbreviatedType)
|
||||
= AbbreviatedType(delegate.replaceAnnotations(newAnnotations), abbreviation)
|
||||
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean)
|
||||
= AbbreviatedType(delegate.makeNullableAsSpecified(newNullability), abbreviatedType.makeNullableAsSpecified(newNullability))
|
||||
= AbbreviatedType(delegate.makeNullableAsSpecified(newNullability), abbreviation.makeNullableAsSpecified(newNullability))
|
||||
|
||||
override val isError: Boolean get() = false
|
||||
}
|
||||
|
||||
fun KotlinType.getAbbreviatedType(): SimpleType? = (unwrap() as? AbbreviatedType)?.abbreviatedType
|
||||
fun KotlinType.getAbbreviatedType(): AbbreviatedType? = (unwrap() as? AbbreviatedType)
|
||||
|
||||
fun SimpleType.withAbbreviatedType(abbreviatedType: SimpleType): SimpleType {
|
||||
fun SimpleType.withAbbreviation(abbreviatedType: SimpleType): SimpleType {
|
||||
if (isError) return this
|
||||
return AbbreviatedType(this, abbreviatedType)
|
||||
}
|
||||
|
||||
@@ -173,3 +173,8 @@ open class DelegatedTypeSubstitution(val substitution: TypeSubstitution): TypeSu
|
||||
|
||||
override fun filterAnnotations(annotations: Annotations) = substitution.filterAnnotations(annotations)
|
||||
}
|
||||
|
||||
// This method used for transform type to simple type afler substitution
|
||||
fun KotlinType.asSimpleType(): SimpleType {
|
||||
return unwrap() as? SimpleType ?: error("This is should be simple type: $this")
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class TypeSubstitutor {
|
||||
"Unexpected substituted projection kind: " + substitutedProjectionKind + "; original: " + originalProjectionKind;
|
||||
|
||||
KotlinType substitutedFlexibleType = KotlinTypeFactory.flexibleType(
|
||||
KotlinTypeKt.asSimpleType(substitutedLower.getType()), KotlinTypeKt.asSimpleType(substitutedUpper.getType()));
|
||||
TypeSubstitutionKt.asSimpleType(substitutedLower.getType()), TypeSubstitutionKt.asSimpleType(substitutedUpper.getType()));
|
||||
return new TypeProjectionImpl(substitutedProjectionKind, substitutedFlexibleType);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets
|
||||
import org.jetbrains.kotlin.types.AbstractLazyType
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.withAbbreviatedType
|
||||
import org.jetbrains.kotlin.types.withAbbreviation
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
|
||||
class DeserializedType private constructor(
|
||||
@@ -58,7 +58,7 @@ class DeserializedType private constructor(
|
||||
val deserializedType = DeserializedType(c, typeProto, additionalAnnotations)
|
||||
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return deserializedType
|
||||
|
||||
return deserializedType.withAbbreviatedType(DeserializedType(c, abbreviatedTypeProto, additionalAnnotations))
|
||||
return deserializedType.withAbbreviation(DeserializedType(c, abbreviatedTypeProto, additionalAnnotations))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -180,8 +180,8 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
val local = c.childContext(typeAlias, proto.typeParameterList)
|
||||
typeAlias.initialize(
|
||||
local.typeDeserializer.ownTypeParameters,
|
||||
local.typeDeserializer.type(proto.underlyingType(c.typeTable)),
|
||||
local.typeDeserializer.type(proto.expandedType(c.typeTable))
|
||||
local.typeDeserializer.simpleType(proto.underlyingType(c.typeTable)),
|
||||
local.typeDeserializer.simpleType(proto.expandedType(c.typeTable))
|
||||
)
|
||||
|
||||
return typeAlias
|
||||
|
||||
+6
-3
@@ -58,14 +58,17 @@ class TypeDeserializer(
|
||||
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
|
||||
if (proto.hasFlexibleTypeCapabilitiesId()) {
|
||||
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
|
||||
val lowerBound = DeserializedType.create(c, proto, additionalAnnotations)
|
||||
val upperBound = DeserializedType.create(c, proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
|
||||
val lowerBound = simpleType(proto, additionalAnnotations)
|
||||
val upperBound = simpleType(proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
|
||||
return c.components.flexibleTypeDeserializer.create(proto, id, lowerBound, upperBound)
|
||||
}
|
||||
|
||||
return DeserializedType.create(c, proto, additionalAnnotations)
|
||||
return simpleType(proto, additionalAnnotations)
|
||||
}
|
||||
|
||||
fun simpleType(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY)
|
||||
= DeserializedType.create(c, proto, additionalAnnotations)
|
||||
|
||||
fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor =
|
||||
when {
|
||||
proto.hasClassName() -> {
|
||||
|
||||
+7
-9
@@ -24,9 +24,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
interface DeserializedMemberDescriptor : MemberDescriptor {
|
||||
val proto: MessageLite
|
||||
@@ -154,14 +152,14 @@ class DeserializedTypeAliasDescriptor(
|
||||
) : AbstractTypeAliasDescriptor(containingDeclaration, annotations, name, SourceElement.NO_SOURCE, visibility),
|
||||
DeserializedMemberDescriptor {
|
||||
|
||||
override lateinit var underlyingType: KotlinType private set
|
||||
override lateinit var expandedType: KotlinType private set
|
||||
override lateinit var underlyingType: SimpleType private set
|
||||
override lateinit var expandedType: SimpleType private set
|
||||
private lateinit var typeConstructorParameters: List<TypeParameterDescriptor>
|
||||
|
||||
fun initialize(
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
underlyingType: KotlinType,
|
||||
expandedType: KotlinType
|
||||
underlyingType: SimpleType,
|
||||
expandedType: SimpleType
|
||||
) {
|
||||
initialize(declaredTypeParameters)
|
||||
this.underlyingType = underlyingType
|
||||
@@ -173,8 +171,8 @@ class DeserializedTypeAliasDescriptor(
|
||||
if (substitutor.isEmpty) return this
|
||||
val substituted = DeserializedTypeAliasDescriptor(containingDeclaration, annotations, name, visibility, proto, nameResolver, typeTable, containerSource)
|
||||
substituted.initialize(declaredTypeParameters,
|
||||
substitutor.safeSubstitute(underlyingType, Variance.INVARIANT),
|
||||
substitutor.safeSubstitute(expandedType, Variance.INVARIANT))
|
||||
substitutor.safeSubstitute(underlyingType, Variance.INVARIANT).asSimpleType(),
|
||||
substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType())
|
||||
|
||||
return substituted
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user