From 56122460aad78826497063168df597ea6238ddde Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 1 Jun 2016 17:58:32 +0300 Subject: [PATCH] Remove type capabilities. --- .../kotlin/types/AbstractKotlinType.java | 12 ------- .../kotlin/types/DelegatingType.java | 12 ------- .../jetbrains/kotlin/types/ErrorUtils.java | 12 ------- .../org/jetbrains/kotlin/types/KotlinType.kt | 11 ++----- .../jetbrains/kotlin/types/KotlinTypeImpl.kt | 6 ++-- .../kotlin/types/TypeCapabilities.kt | 33 ------------------- .../kotlin/types/TypeSubstitution.kt | 11 +++---- .../org/jetbrains/kotlin/types/TypeUtils.java | 12 ------- .../jetbrains/kotlin/types/flexibleTypes.kt | 4 --- .../changeSignature/changeSignatureUtils.kt | 2 +- 10 files changed, 9 insertions(+), 106 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java index 32c976a6ae8..e11a0eff64e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.types; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget; import org.jetbrains.kotlin.renderer.DescriptorRenderer; @@ -26,17 +25,6 @@ import java.util.Iterator; import java.util.List; public abstract class AbstractKotlinType implements KotlinType, SimpleType { // TODO temporary upper bound - @Nullable - @Override - public T getCapability(@NotNull Class capabilityClass) { - return getCapabilities().getCapability(capabilityClass); - } - - @NotNull - @Override - public TypeCapabilities getCapabilities() { - return TypeCapabilities.NONE.INSTANCE; - } @Override public final int hashCode() { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java b/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java index de94c2e70af..29b3082be70 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java @@ -61,18 +61,6 @@ public abstract class DelegatingType implements KotlinType, SimpleType { // TODO return getDelegate().getAnnotations(); } - @Override - @Nullable - public T getCapability(@NotNull Class capabilityClass) { - return getDelegate().getCapability(capabilityClass); - } - - @NotNull - @Override - public TypeCapabilities getCapabilities() { - return getDelegate().getCapabilities(); - } - @Override public int hashCode() { return getDelegate().hashCode(); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index 4773a94f756..28188dc24df 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -537,18 +537,6 @@ public class ErrorUtils { return Annotations.Companion.getEMPTY(); } - @Nullable - @Override - public T getCapability(@NotNull Class capabilityClass) { - return null; - } - - @NotNull - @Override - public TypeCapabilities getCapabilities() { - return TypeCapabilities.NONE.INSTANCE; - } - @Override public String toString() { return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "...", null)); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt index 6958363ced8..e45fc3ad371 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt @@ -37,11 +37,6 @@ interface KotlinType : Annotated { val isError: Boolean override fun equals(other: Any?): Boolean - - fun getCapability(capabilityClass: Class): T? - - val capabilities: TypeCapabilities - } @Deprecated("Temporary marker method for refactoring") @@ -89,8 +84,6 @@ abstract class WrappedType() : KotlinType, LazyType { // todo: remove this later override val isError: Boolean get() = delegate.isError - override val capabilities: TypeCapabilities get() = delegate.capabilities - override fun getCapability(capabilityClass: Class): T? = delegate.getCapability(capabilityClass) override fun equals(other: Any?): Boolean = unwrap().equals(other) override fun hashCode(): Int = unwrap().hashCode() } @@ -117,7 +110,7 @@ fun KotlinType.getAbbreviatedType(): SimpleType? = (unwrap() as? SimpleType)?.ab fun SimpleType.withAbbreviatedType(abbreviatedType: SimpleType): SimpleType { if (isError) return this - return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities, abbreviatedType) + return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, abbreviatedType) } private class WrappedSimpleType( @@ -134,7 +127,7 @@ private class WrappedSimpleType( override fun unwrap(): KotlinType { if (delegate.isError) return delegate // todo if (delegate is CustomTypeVariable) return delegate // todo - return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities, abbreviatedType) + return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, abbreviatedType) } override fun toString(): String { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt index f438d9d9665..fb8884ff1d9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt @@ -45,11 +45,10 @@ internal constructor( nullable: Boolean, arguments: List, memberScope: MemberScope, - capabilities: TypeCapabilities, abbreviatedType: SimpleType? = null ): KotlinTypeImpl { - if (capabilities !== TypeCapabilities.NONE || abbreviatedType != null) { - return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, capabilities, abbreviatedType) + if (abbreviatedType != null) { + return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, abbreviatedType) } return KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope) } @@ -71,7 +70,6 @@ internal constructor( nullable: Boolean, arguments: List, memberScope: MemberScope, - override val capabilities: TypeCapabilities, override val abbreviatedType: SimpleType? ) : KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt index 5acbe4eb0ae..33924046ca8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt @@ -16,39 +16,6 @@ package org.jetbrains.kotlin.types -interface TypeCapability - -interface TypeCapabilities { - object NONE : TypeCapabilities { - override fun getCapability(capabilityClass: Class): T? = null - } - - fun getCapability(capabilityClass: Class): T? -} - -class CompositeTypeCapabilities(private val first: TypeCapabilities, private val second: TypeCapabilities) : TypeCapabilities { - override fun getCapability(capabilityClass: Class): T? = - first.getCapability(capabilityClass) ?: second.getCapability(capabilityClass) -} - -class SingletonTypeCapabilities(private val clazz: Class<*>, private val typeCapability: TypeCapability) : TypeCapabilities { - override fun getCapability(capabilityClass: Class): T? { - @Suppress("UNCHECKED_CAST") - if (capabilityClass == clazz) return typeCapability as T - return null - } -} - -fun TypeCapabilities.addCapability(clazz: Class, typeCapability: T): TypeCapabilities { - if (getCapability(clazz) === typeCapability) return this - val newCapabilities = SingletonTypeCapabilities(clazz, typeCapability) - if (this === TypeCapabilities.NONE) return newCapabilities - - return CompositeTypeCapabilities(this, newCapabilities) -} - -inline fun KotlinType.getCapability(): T? = getCapability(T::class.java) - // To facilitate laziness, any KotlinType implementation may inherit from this trait, // even if it turns out that the type an instance represents is not actually a type variable diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt index 716db20f361..bef01b8436c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt @@ -116,10 +116,9 @@ class IndexedParametersSubstitution( @JvmOverloads fun KotlinType.replace( newArguments: List = arguments, - newAnnotations: Annotations = annotations, - newCapabilities: TypeCapabilities = capabilities + newAnnotations: Annotations = annotations ): KotlinType { - if (newArguments.isEmpty() && newAnnotations === annotations && newCapabilities === capabilities) return this + if (newArguments.isEmpty() && newAnnotations === annotations) return this if (newArguments.isEmpty()) { return KotlinTypeImpl.create( @@ -127,8 +126,7 @@ fun KotlinType.replace( constructor, isMarkedNullable, arguments, - memberScope, - newCapabilities + memberScope ) } @@ -145,8 +143,7 @@ fun KotlinType.replace( constructor, isMarkedNullable, newArguments, - newScope, - newCapabilities + newScope ) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index db22561bf5e..84545606a88 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -77,18 +77,6 @@ public class TypeUtils { throw new IllegalStateException(name); } - @Nullable - @Override - public T getCapability(@NotNull Class capabilityClass) { - return null; - } - - @NotNull - @Override - public TypeCapabilities getCapabilities() { - return TypeCapabilities.NONE.INSTANCE; - } - @Override public String toString() { return name; diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index 39d85b19bd6..51cd02385a8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -131,10 +131,6 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Delegat override val delegateType: KotlinType get() = lowerBound - override fun getCapability(capabilityClass: Class): T? { - return super.getCapability(capabilityClass) - } - override val isTypeVariable: Boolean get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor && lowerBound.constructor == upperBound.constructor diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt index 8251b94a025..627fed8244b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt @@ -90,7 +90,7 @@ private object ForceTypeCopySubstitution : TypeSubstitution() { with(key) { if (isError) return@with asTypeProjection() KotlinTypeImpl.create( - annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities).asTypeProjection() + annotations, constructor, isMarkedNullable, arguments, memberScope).asTypeProjection() } override fun isEmpty() = false