diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java index 0a9efcae3bf..45bdebfb4aa 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.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. @@ -180,9 +180,9 @@ public abstract class AnnotationCodegen { if (FlexibleTypesKt.isFlexible(type)) { // A flexible type whose lower bound in not-null and upper bound is nullable, should not be annotated - Flexibility flexibility = FlexibleTypesKt.flexibility(type); + FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type); - if (!TypeUtils.isNullableType(flexibility.getLowerBound()) && TypeUtils.isNullableType(flexibility.getUpperBound())) { + if (!TypeUtils.isNullableType(flexibleType.getLowerBound()) && TypeUtils.isNullableType(flexibleType.getUpperBound())) { AnnotationDescriptor notNull = type.getAnnotations().findAnnotation(JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION); if (notNull != null) { generateAnnotationIfNotPresent(annotationDescriptorsAlreadyPresent, NotNull.class); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmTypeSpecificityComparator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmTypeSpecificityComparator.kt index ea684e6f7c3..3b7c93c74e3 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmTypeSpecificityComparator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmTypeSpecificityComparator.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.flexibility +import org.jetbrains.kotlin.types.asFlexibleType import org.jetbrains.kotlin.types.isFlexible object JvmTypeSpecificityComparator : TypeSpecificityComparator { @@ -28,7 +28,7 @@ object JvmTypeSpecificityComparator : TypeSpecificityComparator { if (!specific.isFlexible() || general.isFlexible()) return false // general is inflexible - val flexibility = specific.flexibility() + val flexibility = specific.asFlexibleType() // For primitive types we have to take care of the case when there are two overloaded methods like // foo(int) and foo(Integer) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/WhenByPlatformEnumChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/WhenByPlatformEnumChecker.kt index ddc504bec1c..94c16ae1a7d 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/WhenByPlatformEnumChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/WhenByPlatformEnumChecker.kt @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils -import org.jetbrains.kotlin.types.flexibility +import org.jetbrains.kotlin.types.asFlexibleType import org.jetbrains.kotlin.types.isFlexible class WhenByPlatformEnumChecker : AdditionalTypeChecker { @@ -34,7 +34,7 @@ class WhenByPlatformEnumChecker : AdditionalTypeChecker { if (expression is KtWhenExpression && expression.elseExpression == null) { // Check for conditionally-exhaustive when on platform enums, see KT-6399 val type = expression.subjectExpression?.let { c.trace.getType(it) } ?: return - if (type.isFlexible() && TypeUtils.isNullableType(type.flexibility().upperBound) && !type.annotations.isMarkedNotNull()) { + if (type.isFlexible() && TypeUtils.isNullableType(type.asFlexibleType().upperBound) && !type.annotations.isMarkedNotNull()) { val enumClassDescriptor = WhenChecker.getClassDescriptorOfTypeIfEnum(type) ?: return val context = c.trace.bindingContext if (WhenChecker.getEnumMissingCases(expression, context, enumClassDescriptor).isEmpty() diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt index 77bd262ddd2..4c8841f4e5f 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JavaGenericVarianceViolationTypeChecker.kt @@ -45,8 +45,8 @@ object JavaGenericVarianceViolationTypeChecker : AdditionalTypeChecker { // optimization: if no arguments or flexibility, everything is OK if (expectedType.arguments.isEmpty() || !expectedType.isFlexible()) return - val lowerBound = expectedType.flexibility().lowerBound - val upperBound = expectedType.flexibility().upperBound + val lowerBound = expectedType.asFlexibleType().lowerBound + val upperBound = expectedType.asFlexibleType().upperBound // Use site variance projection is always the same for flexible types if (lowerBound.constructor == upperBound.constructor) return diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index d6550da949a..372fab94088 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -1151,9 +1151,9 @@ public class DescriptorResolver { : "Flexible type cannot be denoted in Kotlin otherwise than as ft, but was: " + PsiUtilsKt.getElementTextWithContext(typeReference); // it's really ft - Flexibility flexibility = FlexibleTypesKt.flexibility(type); - checkBounds(jetTypeArguments.get(0), flexibility.getLowerBound(), trace); - checkBounds(jetTypeArguments.get(1), flexibility.getUpperBound(), trace); + FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type); + checkBounds(jetTypeArguments.get(0), flexibleType.getLowerBound(), trace); + checkBounds(jetTypeArguments.get(1), flexibleType.getUpperBound(), trace); return; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index c0422096efc..778310355b6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -156,8 +156,8 @@ class TypeResolver( private fun forceResolveTypeContents(type: KotlinType) { type.annotations // force read type annotations if (type.isFlexible()) { - forceResolveTypeContents(type.flexibility().lowerBound) - forceResolveTypeContents(type.flexibility().upperBound) + forceResolveTypeContents(type.asFlexibleType().lowerBound) + forceResolveTypeContents(type.asFlexibleType().upperBound) } else { type.constructor // force read type constructor diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/ForceResolveUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/ForceResolveUtil.java index 0dec14446cc..862e22d8421 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/ForceResolveUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/ForceResolveUtil.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. @@ -98,8 +98,8 @@ public class ForceResolveUtil { forceResolveAllContents(type.getAnnotations()); if (FlexibleTypesKt.isFlexible(type)) { - forceResolveAllContents(FlexibleTypesKt.flexibility(type).getLowerBound()); - forceResolveAllContents(FlexibleTypesKt.flexibility(type).getUpperBound()); + forceResolveAllContents(FlexibleTypesKt.asFlexibleType(type).getLowerBound()); + forceResolveAllContents(FlexibleTypesKt.asFlexibleType(type).getUpperBound()); } else { forceResolveAllContents(type.getConstructor()); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java b/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java index c3a95829002..c7c21ebd6d6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java @@ -91,9 +91,9 @@ public class CommonSupertypes { return type; } hasFlexible = true; - Flexibility flexibility = FlexibleTypesKt.flexibility(type); - upper.add(flexibility.getUpperBound()); - lower.add(flexibility.getLowerBound()); + FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type); + upper.add(flexibleType.getUpperBound()); + lower.add(flexibleType.getLowerBound()); } else { upper.add(KotlinTypeKt.asSimpleType(type)); diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java index 58e89d3e289..5518a2ac204 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java @@ -506,7 +506,7 @@ public class DescriptorSerializer { } if (FlexibleTypesKt.isFlexible(type)) { - DelegatingFlexibleType flexibleType = (DelegatingFlexibleType) FlexibleTypesKt.flexibility(type); + DelegatingFlexibleType flexibleType = (DelegatingFlexibleType) FlexibleTypesKt.asFlexibleType(type); ProtoBuf.Type.Builder lowerBound = type(flexibleType.getLowerBound()); ProtoBuf.Type.Builder upperBound = type(flexibleType.getUpperBound()); diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java b/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java index 04e56be4c97..efadb0b1d0a 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.serialization; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.types.DelegatingFlexibleType; -import org.jetbrains.kotlin.types.Flexibility; import org.jetbrains.kotlin.types.KotlinType; public abstract class SerializerExtension { 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 0bfa3dfc4f3..95e441e1436 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 @@ -49,12 +49,12 @@ object RawTypeCapabilities : TypeCapabilities { } } - override fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair? { - val lowerArgs = renderer.renderArguments(flexibility.lowerBound) - val upperArgs = renderer.renderArguments(flexibility.upperBound) + override fun renderBounds(flexibleType: FlexibleType, renderer: DescriptorRenderer): Pair? { + val lowerArgs = renderer.renderArguments(flexibleType.lowerBound) + val upperArgs = renderer.renderArguments(flexibleType.upperBound) - val lowerRendered = renderer.renderType(flexibility.lowerBound) - val upperRendered = renderer.renderType(flexibility.upperBound) + val lowerRendered = renderer.renderType(flexibleType.lowerBound) + val upperRendered = renderer.renderType(flexibleType.upperBound) if (!upperArgs.isNotEmpty()) return null 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 11f7d60a8b3..684ac966c63 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 @@ -58,7 +58,7 @@ private data class Result(val type: KotlinType, val subtreeSize: Int, val wereCh private fun KotlinType.enhancePossiblyFlexible(qualifiers: (Int) -> JavaTypeQualifiers, index: Int): Result { if (this.isError) return Result(this, 1, false) return if (this.isFlexible()) { - with(this.flexibility()) { + with(this.asFlexibleType()) { val lowerResult = lowerBound.enhanceInflexible(qualifiers, index, TypeComponentPosition.FLEXIBLE_LOWER) val upperResult = upperBound.enhanceInflexible(qualifiers, index, TypeComponentPosition.FLEXIBLE_UPPER) assert(lowerResult.subtreeSize == upperResult.subtreeSize) { @@ -227,7 +227,7 @@ internal object NotNullTypeParameterTypeCapability : CustomTypeVariable { if (!TypeUtils.isNullableType(replacement) && !replacement.isTypeParameter()) return replacement if (replacement.isFlexible()) { - with(replacement.flexibility()) { + with(replacement.asFlexibleType()) { return KotlinTypeFactory.flexibleType(lowerBound.prepareReplacement().asSimpleType(), upperBound.prepareReplacement().asSimpleType()) } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt index 8b13813100c..f778e961781 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt @@ -52,7 +52,7 @@ class JavaTypeQualifiers internal constructor( private fun KotlinType.extractQualifiers(): JavaTypeQualifiers { val (lower, upper) = if (this.isFlexible()) - flexibility().let { Pair(it.lowerBound, it.upperBound) } + asFlexibleType().let { Pair(it.lowerBound, it.upperBound) } else Pair(this, this) val mapping = JavaToKotlinClassMap.INSTANCE diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index ffbbcdb0824..c7c9e039083 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -150,7 +150,7 @@ internal class DescriptorRendererImpl( } if (type.isFlexible()) { if (debugMode) { - return renderFlexibleTypeWithBothBounds(type.flexibility().lowerBound, type.flexibility().upperBound) + return renderFlexibleTypeWithBothBounds(type.asFlexibleType().lowerBound, type.asFlexibleType().upperBound) } else { return renderFlexibleType(type) @@ -194,10 +194,10 @@ internal class DescriptorRendererImpl( } private fun renderFlexibleType(type: KotlinType): String { - val lower = type.flexibility().lowerBound - val upper = type.flexibility().upperBound + val lower = type.asFlexibleType().lowerBound + val upper = type.asFlexibleType().upperBound - val (lowerRendered, upperRendered) = type.getCapability()?.renderBounds(type.flexibility(), this) + val (lowerRendered, upperRendered) = type.getCapability()?.renderBounds(type.asFlexibleType(), this) ?: Pair(renderInflexibleType(lower), renderInflexibleType(upper)) if (differsOnlyInNullability(lowerRendered, upperRendered)) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/RawTypeCapability.kt b/core/descriptors/src/org/jetbrains/kotlin/types/RawTypeCapability.kt index d783002b06b..ca1605b8301 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/RawTypeCapability.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/RawTypeCapability.kt @@ -24,6 +24,6 @@ interface RawTypeCapability : TypeCapability { val substitutionToComposeWith: TypeSubstitution? fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String? - fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair? + fun renderBounds(flexibleType: FlexibleType, renderer: DescriptorRenderer): Pair? } \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java index 25c07157c8f..00fe26b2e2f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java @@ -140,11 +140,11 @@ public class TypeSubstitutor { TypeProjection replacement = substitution.get(type); Variance originalProjectionKind = originalProjection.getProjectionKind(); if (replacement == null && FlexibleTypesKt.isFlexible(type) && !TypeCapabilitiesKt.isCustomTypeVariable(type)) { - Flexibility flexibility = FlexibleTypesKt.flexibility(type); + FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type); TypeProjection substitutedLower = - unsafeSubstitute(new TypeProjectionImpl(originalProjectionKind, flexibility.getLowerBound()), recursionDepth + 1); + unsafeSubstitute(new TypeProjectionImpl(originalProjectionKind, flexibleType.getLowerBound()), recursionDepth + 1); TypeProjection substitutedUpper = - unsafeSubstitute(new TypeProjectionImpl(originalProjectionKind, flexibility.getUpperBound()), recursionDepth + 1); + unsafeSubstitute(new TypeProjectionImpl(originalProjectionKind, flexibleType.getUpperBound()), recursionDepth + 1); Variance substitutedProjectionKind = substitutedLower.getProjectionKind(); assert (substitutedProjectionKind == substitutedUpper.getProjectionKind()) && diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 8b3ad5941d5..359c622cffe 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -135,12 +135,12 @@ public class TypeUtils { @NotNull public static KotlinType makeNullableAsSpecified(@NotNull KotlinType type, boolean nullable) { - Flexibility flexibility = type.getCapability(Flexibility.class); - if (flexibility != null) { - return flexibility.makeNullableAsSpecified(nullable); + KotlinType unwrappedType = KotlinTypeKt.unwrap(type); + if (unwrappedType instanceof FlexibleType) { + return ((FlexibleType) unwrappedType).makeNullableAsSpecified(nullable); } else { - SimpleType simpleType = KotlinTypeKt.asSimpleType(type); + SimpleType simpleType = (SimpleType) unwrappedType; if (!(simpleType instanceof LazyType) && simpleType.isMarkedNullable() == nullable) return simpleType; @@ -318,7 +318,7 @@ public class TypeUtils { if (type.isMarkedNullable()) { return true; } - if (FlexibleTypesKt.isFlexible(type) && isNullableType(FlexibleTypesKt.flexibility(type).getUpperBound())) { + if (FlexibleTypesKt.isFlexible(type) && isNullableType(FlexibleTypesKt.asFlexibleType(type).getUpperBound())) { return true; } if (isTypeParameter(type)) { @@ -336,7 +336,7 @@ public class TypeUtils { if (type.isMarkedNullable()) { return true; } - if (FlexibleTypesKt.isFlexible(type) && acceptsNullable(FlexibleTypesKt.flexibility(type).getUpperBound())) { + if (FlexibleTypesKt.isFlexible(type) && acceptsNullable(FlexibleTypesKt.asFlexibleType(type).getUpperBound())) { return true; } return false; @@ -436,9 +436,11 @@ public class TypeUtils { ) { if (type == null) return false; if (isSpecialType.invoke(type)) return true; - Flexibility flexibility = type.getCapability(Flexibility.class); - if (flexibility != null - && (contains(flexibility.getLowerBound(), isSpecialType) || contains(flexibility.getUpperBound(), isSpecialType))) { + + KotlinType unwrappedType = KotlinTypeKt.unwrap(type); + FlexibleType flexibleType = unwrappedType instanceof FlexibleType ? (FlexibleType) unwrappedType : null; + if (flexibleType != null + && (contains(flexibleType.getLowerBound(), isSpecialType) || contains(flexibleType.getUpperBound(), isSpecialType))) { return true; } for (TypeProjection projection : type.getArguments()) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index a82d5217c6b..b3a61db0122 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -85,7 +85,7 @@ fun TypeProjection.substitute(doSubstitute: (KotlinType) -> KotlinType): TypePro fun KotlinType.replaceAnnotations(newAnnotations: Annotations): KotlinType { if (annotations.isEmpty() && newAnnotations.isEmpty()) return this - if (isFlexible()) return flexibility().replaceAnnotations(newAnnotations) + if (isFlexible()) return asFlexibleType().replaceAnnotations(newAnnotations) return asSimpleType().lazyReplaceAnnotations(newAnnotations) } @@ -135,7 +135,7 @@ private fun constituentTypes(result: MutableSet, types: Collection vs (Mutable)Collection! or K(java.util.Collection) assert !FlexibleTypesKt.isFlexible(inflexibleType) : "Only inflexible types are allowed here: " + inflexibleType; - return isSubtypeOf(FlexibleTypesKt.flexibility(flexibleType).getLowerBound(), inflexibleType) - && isSubtypeOf(inflexibleType, FlexibleTypesKt.flexibility(flexibleType).getUpperBound()); + return isSubtypeOf(FlexibleTypesKt.asFlexibleType(flexibleType).getLowerBound(), inflexibleType) + && isSubtypeOf(inflexibleType, FlexibleTypesKt.asFlexibleType(flexibleType).getUpperBound()); } public enum EnrichedProjectionKind { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index 9199164db26..fa45558748b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations -interface Flexibility : TypeCapability, SubtypingRepresentatives { +interface FlexibleType : SubtypingRepresentatives { // lowerBound is a subtype of upperBound val lowerBound: SimpleType val upperBound: SimpleType @@ -39,11 +39,11 @@ interface Flexibility : TypeCapability, SubtypingRepresentatives { fun replaceAnnotations(newAnnotations: Annotations): KotlinType } -fun KotlinType.isFlexible(): Boolean = this.getCapability(Flexibility::class.java) != null -fun KotlinType.flexibility(): Flexibility = this.getCapability(Flexibility::class.java)!! +fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType +fun KotlinType.asFlexibleType(): FlexibleType = unwrap() as FlexibleType fun KotlinType.isNullabilityFlexible(): Boolean { - val flexibility = this.getCapability(Flexibility::class.java) ?: return false + val flexibility = unwrap() as? FlexibleType ?: return false return TypeUtils.isNullableType(flexibility.lowerBound) != TypeUtils.isNullableType(flexibility.upperBound) } @@ -81,13 +81,13 @@ fun Collection.singleBestRepresentative(): TypeProjection? { return TypeProjectionImpl(projectionKinds.single(), bestType) } -fun KotlinType.lowerIfFlexible(): SimpleType = (if (this.isFlexible()) this.flexibility().lowerBound else this).asSimpleType() -fun KotlinType.upperIfFlexible(): SimpleType = (if (this.isFlexible()) this.flexibility().upperBound else this).asSimpleType() +fun KotlinType.lowerIfFlexible(): SimpleType = (if (this.isFlexible()) this.asFlexibleType().lowerBound else this).asSimpleType() +fun KotlinType.upperIfFlexible(): SimpleType = (if (this.isFlexible()) this.asFlexibleType().upperBound else this).asSimpleType() abstract class DelegatingFlexibleType protected constructor( override val lowerBound: SimpleType, override val upperBound: SimpleType -) : DelegatingType(), Flexibility { +) : DelegatingType(), FlexibleType { companion object { @JvmField var RUN_SLOW_ASSERTIONS = false @@ -118,7 +118,7 @@ abstract class DelegatingFlexibleType protected constructor( override fun getCapability(capabilityClass: Class): T? { @Suppress("UNCHECKED_CAST") return when(capabilityClass) { - Flexibility::class.java, SubtypingRepresentatives::class.java -> this as T + SubtypingRepresentatives::class.java -> this as T else -> super.getCapability(capabilityClass) } } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt index 81e5a5760b7..e44ef08a734 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt @@ -39,7 +39,7 @@ fun KotlinType.approximateFlexibleTypes(preferNotNull: Boolean = false): KotlinT private fun KotlinType.approximateNonDynamicFlexibleTypes(preferNotNull: Boolean = false): SimpleType { if (isFlexible()) { - val flexible = flexibility() + val flexible = asFlexibleType() val lowerClass = flexible.lowerBound.constructor.declarationDescriptor as? ClassDescriptor? val isCollection = lowerClass != null && JavaToKotlinClassMap.INSTANCE.isMutable(lowerClass) // (Mutable)Collection! -> MutableCollection? diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.kt index 2e37c053ef9..80572e98ae0 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.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,9 +23,10 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.types.Flexibility +import org.jetbrains.kotlin.types.FlexibleType import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.unwrap fun KtFunctionLiteral.findLabelAndCall(): Pair { val literalParent = (this.parent as KtLambdaExpression).parent @@ -77,11 +78,11 @@ private fun chooseMoreSpecific(type1: KotlinType, type2: KotlinType): KotlinType !type1IsSubtype && !type2IsSubtype -> return null else -> { // type1IsSubtype && type2IsSubtype - val flexibility1 = type1.getCapability(Flexibility::class.java) - val flexibility2 = type2.getCapability(Flexibility::class.java) + val flexible1 = type1.unwrap() as? FlexibleType + val flexible2 = type2.unwrap() as? FlexibleType when { - flexibility1 != null && flexibility2 == null -> return type2 - flexibility2 != null && flexibility1 == null -> return type1 + flexible1 != null && flexible2 == null -> return type2 + flexible2 != null && flexible1 == null -> return type1 else -> return null //TODO? } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt index 195304f6d1e..ca9df8f7510 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt @@ -35,7 +35,7 @@ import org.jetbrains.kotlin.idea.decompiler.textBuilder.defaultDecompilerRendere import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.jetbrains.kotlin.renderer.DescriptorRenderer -import org.jetbrains.kotlin.types.flexibility +import org.jetbrains.kotlin.types.asFlexibleType import org.jetbrains.kotlin.types.isFlexible class KotlinClassFileDecompiler : ClassFileDecompilers.Full() { @@ -63,7 +63,7 @@ class KtClsFile(provider: KotlinDecompiledFileViewProvider) : KtDecompiledFile(p private val decompilerRendererForClassFiles = DescriptorRenderer.withOptions { defaultDecompilerRendererOptions() - typeNormalizer = { type -> if (type.isFlexible()) type.flexibility().lowerBound else type } + typeNormalizer = { type -> if (type.isFlexible()) type.asFlexibleType().lowerBound else type } } fun buildDecompiledTextForClassFile( diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.kt index 7d8522d0793..9ebcbfa2b25 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.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. @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.flexibility +import org.jetbrains.kotlin.types.asFlexibleType import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf class CastExpressionFix(element: KtExpression, type: KotlinType) : KotlinQuickFixAction(element) { @@ -65,7 +65,7 @@ class CastExpressionFix(element: KtExpression, type: KotlinType) : KotlinQuickFi object GenericVarianceConversion : Factory() { override fun extractFixData(element: KtExpression, diagnostic: Diagnostic): KotlinType? { - return ErrorsJvm.JAVA_TYPE_MISMATCH.cast(diagnostic).b.flexibility().upperBound + return ErrorsJvm.JAVA_TYPE_MISMATCH.cast(diagnostic).b.asFlexibleType().upperBound } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt index 5d931c55bc0..a059209ff2b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.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. @@ -334,7 +334,7 @@ val ControlFlow.possibleReturnTypes: List returnType.isAnnotatedNotNull() || returnType.isAnnotatedNullable() -> listOf(returnType.approximateFlexibleTypes()) else -> - returnType.getCapability(Flexibility::class.java).let { listOf(it!!.upperBound, it.lowerBound) } + (returnType.unwrap() as FlexibleType).let { listOf(it.upperBound, it.lowerBound) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt index 74a79c50612..898ad634b9f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.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. @@ -518,7 +518,7 @@ internal class MutableParameter( val typePredicate = and(typePredicates) val typeSet = if (defaultType.isFlexible()) { - val bounds = defaultType.getCapability(Flexibility::class.java)!! + val bounds = defaultType.asFlexibleType() LinkedHashSet().apply { if (typePredicate(bounds.upperBound)) add(bounds.upperBound) if (typePredicate(bounds.lowerBound)) add(bounds.lowerBound)