Remove type capability AbbreviatedType.

This commit is contained in:
Stanislav Erokhin
2016-06-03 18:44:41 +03:00
parent 203c4cd94d
commit a5c1e009c3
10 changed files with 50 additions and 42 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -94,12 +94,12 @@ public class PossiblyBareType {
KotlinType nullableActualType = TypeUtils.makeNullable(getActualType());
KotlinType abbreviatedType = TypeCapabilitiesKt.getAbbreviatedType(getActualType());
KotlinType abbreviatedType = KotlinTypeKt.getAbbreviatedType(getActualType());
if (abbreviatedType == null) {
return type(nullableActualType);
}
else {
return type(TypeCapabilitiesKt.withAbbreviatedType(nullableActualType, TypeUtils.makeNullable(abbreviatedType)));
return type(KotlinTypeKt.withAbbreviatedType(KotlinTypeKt.asSimpleType(nullableActualType), KotlinTypeKt.asSimpleType(TypeUtils.makeNullable(abbreviatedType))));
}
}
@@ -548,7 +548,7 @@ public class DescriptorSerializer {
builder.setNullable(type.isMarkedNullable());
}
KotlinType abbreviatedType = TypeCapabilitiesKt.getAbbreviatedType(type);
KotlinType abbreviatedType = KotlinTypeKt.getAbbreviatedType(type);
if (abbreviatedType != null) {
if (useTypeTable()) {
builder.setAbbreviatedTypeId(typeId(abbreviatedType));
@@ -87,4 +87,10 @@ public abstract class AbstractKotlinType implements KotlinType, SimpleType { //
return sb.toString();
}
@Nullable
@Override
public SimpleType getAbbreviatedType() {
return null;
}
}
@@ -91,4 +91,10 @@ public abstract class DelegatingType implements KotlinType, SimpleType { // TODO
public String toString() {
return getDelegate().toString();
}
@Nullable
@Override
public SimpleType getAbbreviatedType() {
return null;
}
}
@@ -553,6 +553,12 @@ public class ErrorUtils {
public String toString() {
return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "...", null));
}
@Nullable
@Override
public SimpleType getAbbreviatedType() {
return null;
}
}
@NotNull
@@ -54,7 +54,9 @@ fun KotlinType.unwrap(): KotlinType {
return this
}
interface SimpleType : KotlinType
interface SimpleType : KotlinType {
val abbreviatedType : SimpleType? get() = null
}
interface TypeWithCustomReplacement : KotlinType {
fun makeNullableAsSpecified(nullable: Boolean): KotlinType
@@ -111,6 +113,13 @@ fun SimpleType.lazyReplaceAnnotations(newAnnotations: Annotations): SimpleType {
}
}
fun KotlinType.getAbbreviatedType(): SimpleType? = (unwrap() as? SimpleType)?.abbreviatedType
fun SimpleType.withAbbreviatedType(abbreviatedType: SimpleType): SimpleType {
if (isError) return this
return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities, abbreviatedType)
}
private class WrappedSimpleType(
override val delegate: SimpleType,
val newAnnotations: Annotations? = null,
@@ -124,7 +133,7 @@ private class WrappedSimpleType(
override fun unwrap(): KotlinType {
if (delegate.isError) return delegate // todo
return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities)
return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities, abbreviatedType)
}
override fun toString(): String {
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
open class KotlinTypeImpl
private constructor(
internal constructor(
override val annotations: Annotations,
final override val constructor: TypeConstructor,
override val isMarkedNullable: Boolean,
@@ -45,10 +45,11 @@ private constructor(
nullable: Boolean,
arguments: List<TypeProjection>,
memberScope: MemberScope,
capabilities: TypeCapabilities
capabilities: TypeCapabilities,
abbreviatedType: SimpleType? = null
): KotlinTypeImpl {
if (capabilities !== TypeCapabilities.NONE) {
return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, capabilities)
if (capabilities !== TypeCapabilities.NONE || abbreviatedType != null) {
return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, capabilities, abbreviatedType)
}
return KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
}
@@ -70,7 +71,8 @@ private constructor(
nullable: Boolean,
arguments: List<TypeProjection>,
memberScope: MemberScope,
override val capabilities: TypeCapabilities
override val capabilities: TypeCapabilities,
override val abbreviatedType: SimpleType?
) : KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
init {
@@ -47,14 +47,6 @@ fun <T : TypeCapability> TypeCapabilities.addCapability(clazz: Class<T>, typeCap
return CompositeTypeCapabilities(this, newCapabilities)
}
fun <T : TypeCapability> TypeCapabilities.overrideCapability(clazz: Class<T>, typeCapability: T): TypeCapabilities {
if (getCapability(clazz) === typeCapability) return this
val newCapabilities = SingletonTypeCapabilities(clazz, typeCapability)
if (this === org.jetbrains.kotlin.types.TypeCapabilities.NONE) return newCapabilities
return CompositeTypeCapabilities(newCapabilities, this)
}
inline fun <reified T : TypeCapability> KotlinType.getCapability(): T? = getCapability(T::class.java)
@@ -92,20 +84,3 @@ fun sameTypeConstructors(first: KotlinType, second: KotlinType): Boolean {
|| (second.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(first) ?: false
}
interface AbbreviatedType : TypeCapability {
val abbreviatedType : KotlinType
}
fun KotlinType.hasAbbreviatedType(): Boolean =
getCapability(AbbreviatedType::class.java) != null
fun KotlinType.getAbbreviatedType(): KotlinType? =
getCapability(AbbreviatedType::class.java)?.abbreviatedType
private class AbbreviatedTypeImpl(override val abbreviatedType: KotlinType): AbbreviatedType
fun TypeCapabilities.withAbbreviatedType(abbreviatedType: KotlinType): TypeCapabilities =
overrideCapability(AbbreviatedType::class.java, AbbreviatedTypeImpl(abbreviatedType))
fun KotlinType.withAbbreviatedType(abbreviatedType: KotlinType): KotlinType =
if (!isError) replace(newCapabilities = capabilities.withAbbreviatedType(abbreviatedType)) else this
@@ -93,6 +93,12 @@ public class TypeUtils {
public String toString() {
return name;
}
@Nullable
@Override
public SimpleType getAbbreviatedType() {
return null;
}
}
@NotNull
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList
@@ -53,12 +54,9 @@ class DeserializedType(
return descriptor != null && ErrorUtils.isError(descriptor)
}
override val capabilities: TypeCapabilities get() = typeCapabilities()
override val abbreviatedType by c.storageManager.createNullableLazyValue {
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return@createNullableLazyValue null
private val typeCapabilities = c.storageManager.createLazyValue {
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return@createLazyValue TypeCapabilities.NONE
val abbreviatedType = c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations)
TypeCapabilities.NONE.withAbbreviatedType(abbreviatedType)
c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations).asSimpleType()
}
}