Remove type capabilities.
This commit is contained in:
@@ -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 extends TypeCapability> T getCapability(@NotNull Class<T> capabilityClass) {
|
||||
return getCapabilities().getCapability(capabilityClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeCapabilities getCapabilities() {
|
||||
return TypeCapabilities.NONE.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
|
||||
@@ -61,18 +61,6 @@ public abstract class DelegatingType implements KotlinType, SimpleType { // TODO
|
||||
return getDelegate().getAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T extends TypeCapability> T getCapability(@NotNull Class<T> capabilityClass) {
|
||||
return getDelegate().getCapability(capabilityClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeCapabilities getCapabilities() {
|
||||
return getDelegate().getCapabilities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getDelegate().hashCode();
|
||||
|
||||
@@ -537,18 +537,6 @@ public class ErrorUtils {
|
||||
return Annotations.Companion.getEMPTY();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends TypeCapability> T getCapability(@NotNull Class<T> 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));
|
||||
|
||||
@@ -37,11 +37,6 @@ interface KotlinType : Annotated {
|
||||
val isError: Boolean
|
||||
|
||||
override fun equals(other: Any?): Boolean
|
||||
|
||||
fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): 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 <T : TypeCapability> getCapability(capabilityClass: Class<T>): 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 {
|
||||
|
||||
@@ -45,11 +45,10 @@ internal constructor(
|
||||
nullable: Boolean,
|
||||
arguments: List<TypeProjection>,
|
||||
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<TypeProjection>,
|
||||
memberScope: MemberScope,
|
||||
override val capabilities: TypeCapabilities,
|
||||
override val abbreviatedType: SimpleType?
|
||||
) : KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
|
||||
|
||||
|
||||
@@ -16,39 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
interface TypeCapability
|
||||
|
||||
interface TypeCapabilities {
|
||||
object NONE : TypeCapabilities {
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? = null
|
||||
}
|
||||
|
||||
fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T?
|
||||
}
|
||||
|
||||
class CompositeTypeCapabilities(private val first: TypeCapabilities, private val second: TypeCapabilities) : TypeCapabilities {
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? =
|
||||
first.getCapability(capabilityClass) ?: second.getCapability(capabilityClass)
|
||||
}
|
||||
|
||||
class SingletonTypeCapabilities(private val clazz: Class<*>, private val typeCapability: TypeCapability) : TypeCapabilities {
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (capabilityClass == clazz) return typeCapability as T
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : TypeCapability> TypeCapabilities.addCapability(clazz: Class<T>, 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 <reified T : TypeCapability> 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
|
||||
|
||||
@@ -116,10 +116,9 @@ class IndexedParametersSubstitution(
|
||||
@JvmOverloads
|
||||
fun KotlinType.replace(
|
||||
newArguments: List<TypeProjection> = 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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -77,18 +77,6 @@ public class TypeUtils {
|
||||
throw new IllegalStateException(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends TypeCapability> T getCapability(@NotNull Class<T> capabilityClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeCapabilities getCapabilities() {
|
||||
return TypeCapabilities.NONE.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
||||
@@ -131,10 +131,6 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Delegat
|
||||
|
||||
override val delegateType: KotlinType get() = lowerBound
|
||||
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
return super.getCapability(capabilityClass)
|
||||
}
|
||||
|
||||
override val isTypeVariable: Boolean get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
|
||||
&& lowerBound.constructor == upperBound.constructor
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user