From 926da77abeab77ab3bed5c1128702a3b9b5e958c Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Mon, 25 Apr 2016 18:35:05 +0300 Subject: [PATCH] Refactoring. Remove getSubstitution from KotlinType. --- ...nExpansiveInheritanceRestrictionChecker.kt | 9 +++----- .../kotlin/load/java/lazy/types/RawType.kt | 1 - .../java/typeEnhancement/typeEnhancement.kt | 1 - .../kotlin/types/AbstractLazyType.kt | 10 ++++----- .../kotlin/types/DelegatingType.java | 8 +------ .../jetbrains/kotlin/types/ErrorUtils.java | 8 +------ .../jetbrains/kotlin/types/KotlinType.java | 5 +---- .../jetbrains/kotlin/types/KotlinTypeImpl.kt | 22 +++++-------------- .../kotlin/types/TypeSubstitution.kt | 2 -- .../org/jetbrains/kotlin/types/TypeUtils.java | 12 ---------- .../changeSignature/changeSignatureUtils.kt | 4 ++-- 11 files changed, 19 insertions(+), 63 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt index 1b887d12781..45d5ea26160 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt @@ -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() - val substitutor = constituentType.substitution.buildSubstitutor() + val substitutor = TypeConstructorSubstitution.create(constituentType).buildSubstitutor() val adaptedUpperBounds = originalTypeParameter.upperBounds.mapNotNull { substitutor.substitute(it, Variance.INVARIANT) } bounds.addAll(adaptedUpperBounds) diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt index 8db851e0a45..9f3215a7ed0 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/RawType.kt @@ -121,7 +121,6 @@ internal object RawSubstitution : TypeSubstitution() { parameter -> computeProjection(parameter, attr) }, - RawSubstitution, declaration.getMemberScope(RawSubstitution), RawTypeCapabilities ) diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt index 9ae85f65125..973b1b9797a 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt @@ -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(), diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractLazyType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractLazyType.kt index c021a9ea4f6..a0df31f7607 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractLazyType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractLazyType.kt @@ -34,10 +34,6 @@ abstract class AbstractLazyType(storageManager: StorageManager) : AbstractKotlin protected abstract fun computeArguments(): List - override fun getSubstitution() = computeCustomSubstitution() ?: TypeConstructorSubstitution.create(constructor, getArguments()) - - protected open fun computeCustomSubstitution(): TypeSubstitution? = getCapability()?.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()?.substitution + ?: TypeConstructorSubstitution.create(constructor, getArguments()) + descriptor.getMemberScope(substitution) + } else -> throw IllegalStateException("Unsupported classifier: $descriptor") } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java b/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java index 3dbdf84f413..bba8a3fcb63 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java @@ -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(); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index e7a1e6aaee8..9975166935e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -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; diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.java b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.java index 01dfa3aa06f..1b155fc0337 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.java @@ -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 getArguments(); - @NotNull - TypeSubstitution getSubstitution(); - boolean isMarkedNullable(); @NotNull diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt index b507325d929..00674b3aa28 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt @@ -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, - private val substitution: TypeSubstitution?, private val memberScope: MemberScope ) : AbstractKotlinType() { @@ -37,20 +36,19 @@ private constructor( arguments: List, 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, - 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): 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, - 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 diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt index 2d61186745e..abc5e9f5d8e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitution.kt @@ -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 ) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 716e044bc06..75826b36f2f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -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 getCapability(@NotNull Class capabilityClass) { 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 251630d51d0..c6ee7d6f7a5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt @@ -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