Refactoring. Remove getSubstitution from KotlinType.
This commit is contained in:
+3
-6
@@ -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.
|
||||
@@ -23,10 +23,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.boundClosure
|
||||
import org.jetbrains.kotlin.types.typeUtil.constituentTypes
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
@@ -118,7 +115,7 @@ object NonExpansiveInheritanceRestrictionChecker {
|
||||
val originalTypeParameter = constituentTypeConstructor.parameters[i]
|
||||
val bounds = hashSetOf<KotlinType>()
|
||||
|
||||
val substitutor = constituentType.substitution.buildSubstitutor()
|
||||
val substitutor = TypeConstructorSubstitution.create(constituentType).buildSubstitutor()
|
||||
val adaptedUpperBounds = originalTypeParameter.upperBounds.mapNotNull { substitutor.substitute(it, Variance.INVARIANT) }
|
||||
bounds.addAll(adaptedUpperBounds)
|
||||
|
||||
|
||||
@@ -121,7 +121,6 @@ internal object RawSubstitution : TypeSubstitution() {
|
||||
parameter ->
|
||||
computeProjection(parameter, attr)
|
||||
},
|
||||
RawSubstitution,
|
||||
declaration.getMemberScope(RawSubstitution),
|
||||
RawTypeCapabilities
|
||||
)
|
||||
|
||||
-1
@@ -136,7 +136,6 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
||||
typeConstructor,
|
||||
enhancedNullability,
|
||||
enhancedArguments,
|
||||
newSubstitution,
|
||||
if (enhancedClassifier is ClassDescriptor)
|
||||
enhancedClassifier.getMemberScope(newSubstitution)
|
||||
else enhancedClassifier.getDefaultType().getMemberScope(),
|
||||
|
||||
@@ -34,10 +34,6 @@ abstract class AbstractLazyType(storageManager: StorageManager) : AbstractKotlin
|
||||
|
||||
protected abstract fun computeArguments(): List<TypeProjection>
|
||||
|
||||
override fun getSubstitution() = computeCustomSubstitution() ?: TypeConstructorSubstitution.create(constructor, getArguments())
|
||||
|
||||
protected open fun computeCustomSubstitution(): TypeSubstitution? = getCapability<RawTypeCapability>()?.substitution
|
||||
|
||||
private val memberScope = storageManager.createLazyValue { computeMemberScope() }
|
||||
override fun getMemberScope() = memberScope()
|
||||
|
||||
@@ -45,7 +41,11 @@ abstract class AbstractLazyType(storageManager: StorageManager) : AbstractKotlin
|
||||
val descriptor = constructor.declarationDescriptor
|
||||
return when (descriptor) {
|
||||
is TypeParameterDescriptor -> descriptor.getDefaultType().memberScope
|
||||
is ClassDescriptor -> descriptor.getMemberScope(substitution)
|
||||
is ClassDescriptor -> {
|
||||
val substitution = getCapability<RawTypeCapability>()?.substitution
|
||||
?: TypeConstructorSubstitution.create(constructor, getArguments())
|
||||
descriptor.getMemberScope(substitution)
|
||||
}
|
||||
else -> throw IllegalStateException("Unsupported classifier: $descriptor")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -39,12 +39,6 @@ public abstract class DelegatingType implements KotlinType {
|
||||
return getDelegate().getArguments();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeSubstitution getSubstitution() {
|
||||
return getDelegate().getSubstitution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarkedNullable() {
|
||||
return getDelegate().isMarkedNullable();
|
||||
|
||||
@@ -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.
|
||||
@@ -515,12 +515,6 @@ public class ErrorUtils {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeSubstitution getSubstitution() {
|
||||
return TypeConstructorSubstitution.create(constructor, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarkedNullable() {
|
||||
return false;
|
||||
|
||||
@@ -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.
|
||||
@@ -36,9 +36,6 @@ public interface KotlinType extends Annotated {
|
||||
@ReadOnly
|
||||
List<TypeProjection> getArguments();
|
||||
|
||||
@NotNull
|
||||
TypeSubstitution getSubstitution();
|
||||
|
||||
boolean isMarkedNullable();
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -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.
|
||||
@@ -26,7 +26,6 @@ private constructor(
|
||||
private val constructor: TypeConstructor,
|
||||
private val nullable: Boolean,
|
||||
private val arguments: List<TypeProjection>,
|
||||
private val substitution: TypeSubstitution?,
|
||||
private val memberScope: MemberScope
|
||||
) : AbstractKotlinType() {
|
||||
|
||||
@@ -37,20 +36,19 @@ private constructor(
|
||||
arguments: List<TypeProjection>,
|
||||
memberScope: MemberScope): KotlinTypeImpl
|
||||
|
||||
= KotlinTypeImpl(annotations, constructor, nullable, arguments, null, memberScope)
|
||||
= KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
|
||||
|
||||
@JvmStatic fun create(annotations: Annotations,
|
||||
constructor: TypeConstructor,
|
||||
nullable: Boolean,
|
||||
arguments: List<TypeProjection>,
|
||||
substitution: TypeSubstitution,
|
||||
memberScope: MemberScope,
|
||||
capabilities: TypeCapabilities
|
||||
): KotlinTypeImpl {
|
||||
if (capabilities !== TypeCapabilities.NONE) {
|
||||
return WithCapabilities(annotations, constructor, nullable, arguments, substitution, memberScope, capabilities)
|
||||
return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, capabilities)
|
||||
}
|
||||
return KotlinTypeImpl(annotations, constructor, nullable, arguments, substitution, memberScope)
|
||||
return KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
|
||||
}
|
||||
|
||||
@JvmStatic fun create(annotations: Annotations,
|
||||
@@ -59,7 +57,7 @@ private constructor(
|
||||
arguments: List<TypeProjection>): KotlinTypeImpl
|
||||
|
||||
= KotlinTypeImpl(
|
||||
annotations, descriptor.typeConstructor, nullable, arguments, null, descriptor.getMemberScope(arguments)
|
||||
annotations, descriptor.typeConstructor, nullable, arguments, descriptor.getMemberScope(arguments)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -68,10 +66,9 @@ private constructor(
|
||||
constructor: TypeConstructor,
|
||||
nullable: Boolean,
|
||||
arguments: List<TypeProjection>,
|
||||
substitution: TypeSubstitution?,
|
||||
memberScope: MemberScope,
|
||||
private val typeCapabilities: TypeCapabilities
|
||||
) : KotlinTypeImpl(annotations, constructor, nullable, arguments, substitution, memberScope) {
|
||||
) : KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope) {
|
||||
override fun getCapabilities(): TypeCapabilities = typeCapabilities
|
||||
}
|
||||
|
||||
@@ -83,13 +80,6 @@ private constructor(
|
||||
|
||||
override fun getAnnotations() = annotations
|
||||
|
||||
override fun getSubstitution(): TypeSubstitution {
|
||||
if (substitution == null) {
|
||||
return TypeConstructorSubstitution.create(getConstructor(), getArguments())
|
||||
}
|
||||
return substitution
|
||||
}
|
||||
|
||||
override fun getConstructor() = constructor
|
||||
|
||||
override fun getArguments() = arguments
|
||||
|
||||
@@ -137,7 +137,6 @@ fun KotlinType.replace(
|
||||
constructor,
|
||||
isMarkedNullable,
|
||||
arguments,
|
||||
substitution,
|
||||
memberScope,
|
||||
newCapabilities
|
||||
)
|
||||
@@ -156,7 +155,6 @@ fun KotlinType.replace(
|
||||
constructor,
|
||||
isMarkedNullable,
|
||||
newArguments,
|
||||
newSubstitution,
|
||||
newScope,
|
||||
newCapabilities
|
||||
)
|
||||
|
||||
@@ -54,12 +54,6 @@ public class TypeUtils {
|
||||
throw new IllegalStateException(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeSubstitution getSubstitution() {
|
||||
throw new IllegalStateException(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarkedNullable() {
|
||||
throw new IllegalStateException(name);
|
||||
@@ -553,12 +547,6 @@ public class TypeUtils {
|
||||
return delegate.getAnnotations();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeSubstitution getSubstitution() {
|
||||
return delegate.getSubstitution();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends TypeCapability> T getCapability(@NotNull Class<T> capabilityClass) {
|
||||
|
||||
+2
-2
@@ -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.
|
||||
@@ -89,7 +89,7 @@ private object ForceTypeCopySubstitution : TypeSubstitution() {
|
||||
override fun get(key: KotlinType) =
|
||||
with(key) {
|
||||
KotlinTypeImpl.create(
|
||||
annotations, constructor, isMarkedNullable, arguments, substitution, memberScope, capabilities).asTypeProjection()
|
||||
annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities).asTypeProjection()
|
||||
}
|
||||
|
||||
override fun isEmpty() = false
|
||||
|
||||
Reference in New Issue
Block a user