From f1675a9162ba3ed3c4d58149adb9895cf7c4a48f Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Sun, 12 Oct 2014 23:21:50 +0400 Subject: [PATCH] Minor. Getters replaced by properties --- .../java/lazy/types/LazyJavaTypeResolver.kt | 4 +- .../jetbrains/jet/lang/types/flexibleTypes.kt | 48 ++++++++----------- .../jetbrains/jet/plugin/util/TypeUtils.kt | 6 +-- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt index bd8a6597477..a287118d5d0 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt @@ -289,8 +289,8 @@ class LazyJavaTypeResolver( private class Impl(val flexibility: Flexibility) : CustomTypeVariable, Specificity { - private val lowerBound: JetType get() = flexibility.getLowerBound() - private val upperBound: JetType get() = flexibility.getUpperBound() + private val lowerBound: JetType get() = flexibility.lowerBound + private val upperBound: JetType get() = flexibility.upperBound override val isTypeVariable: Boolean = lowerBound.getConstructor() == upperBound.getConstructor() && lowerBound.getConstructor().getDeclarationDescriptor() is TypeParameterDescriptor diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/jet/lang/types/flexibleTypes.kt index 8c77b88ef03..df59ce58cac 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/flexibleTypes.kt @@ -32,11 +32,10 @@ public trait FlexibleTypeCapabilities { public trait Flexibility : TypeCapability { // lowerBound is a subtype of upperBound - public fun getUpperBound(): JetType + public val lowerBound: JetType + public val upperBound: JetType - public fun getLowerBound(): JetType - - public fun getExtraCapabilities(): FlexibleTypeCapabilities + public val extraCapabilities: FlexibleTypeCapabilities } public fun JetType.isFlexible(): Boolean = this.getCapability(javaClass()) != null @@ -74,8 +73,8 @@ fun Collection.singleBestRepresentative(): TypeProjection? { return TypeProjectionImpl(projectionKinds.single(), bestType) } -public fun JetType.lowerIfFlexible(): JetType = if (this.isFlexible()) this.flexibility().getLowerBound() else this -public fun JetType.upperIfFlexible(): JetType = if (this.isFlexible()) this.flexibility().getUpperBound() else this +public fun JetType.lowerIfFlexible(): JetType = if (this.isFlexible()) this.flexibility().lowerBound else this +public fun JetType.upperIfFlexible(): JetType = if (this.isFlexible()) this.flexibility().upperBound else this public trait NullAwareness : TypeCapability { public fun makeNullableAsSpecified(nullable: Boolean): JetType @@ -115,9 +114,9 @@ public fun JetType.getApproximationTo( public open class DelegatingFlexibleType protected ( - private val _lowerBound: JetType, - private val _upperBound: JetType, - private val _extraCapabilities: FlexibleTypeCapabilities + override val lowerBound: JetType, + override val upperBound: JetType, + override val extraCapabilities: FlexibleTypeCapabilities ) : DelegatingType(), NullAwareness, Flexibility, Approximation { class object { fun create(lowerBound: JetType, upperBound: JetType, extraCapabilities: FlexibleTypeCapabilities): JetType { @@ -127,45 +126,40 @@ public open class DelegatingFlexibleType protected ( } { - assert (!_lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $_lowerBound" } - assert (!_upperBound.isFlexible()) { "Upper bound of a flexible type can not be flexible: $_upperBound" } - assert (_lowerBound != _upperBound) { "Lower and upper bounds are equal: $_lowerBound == $_upperBound" } - assert (JetTypeChecker.DEFAULT.isSubtypeOf(_lowerBound, _upperBound)) { - "Lower bound $_lowerBound of a flexible type must be a subtype of the upper bound $_upperBound" + assert (!lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $lowerBound" } + assert (!upperBound.isFlexible()) { "Upper bound of a flexible type can not be flexible: $upperBound" } + assert (lowerBound != upperBound) { "Lower and upper bounds are equal: $lowerBound == $upperBound" } + assert (JetTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) { + "Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound" } } - override fun getUpperBound(): JetType = _upperBound - override fun getLowerBound(): JetType = _lowerBound - - override fun getExtraCapabilities() = _extraCapabilities - override fun getCapability(capabilityClass: Class): T? { - return getExtraCapabilities().getCapability(capabilityClass, this, this) ?: super.getCapability(capabilityClass) + return extraCapabilities.getCapability(capabilityClass, this, this) ?: super.getCapability(capabilityClass) } override fun makeNullableAsSpecified(nullable: Boolean): JetType { return create( - TypeUtils.makeNullableAsSpecified(_lowerBound, nullable), - TypeUtils.makeNullableAsSpecified(_upperBound, nullable), - getExtraCapabilities()) + TypeUtils.makeNullableAsSpecified(lowerBound, nullable), + TypeUtils.makeNullableAsSpecified(upperBound, nullable), + extraCapabilities) } override fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: Approximation.DataFlowExtras): Approximation.Info? { // val foo: Any? = foo() : Foo! - if (JetTypeChecker.DEFAULT.isSubtypeOf(getUpperBound(), expectedType)) return null + if (JetTypeChecker.DEFAULT.isSubtypeOf(upperBound, expectedType)) return null // if (foo : Foo! != null) { // val bar: Any = foo // } - if (!dataFlowExtras.canBeNull && JetTypeChecker.DEFAULT.isSubtypeOf(TypeUtils.makeNotNullable(getUpperBound()), expectedType)) return null + if (!dataFlowExtras.canBeNull && JetTypeChecker.DEFAULT.isSubtypeOf(TypeUtils.makeNotNullable(upperBound), expectedType)) return null // TODO: maybe check possibleTypes to avoid extra approximations return Approximation.Info(this, expectedType, dataFlowExtras.presentableText) } - override fun getDelegate() = _lowerBound + override fun getDelegate() = lowerBound - override fun toString() = "('$_lowerBound'..'$_upperBound')" + override fun toString() = "('$lowerBound'..'$upperBound')" } diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/TypeUtils.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/TypeUtils.kt index 1d9a07567fc..756e88c1082 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/TypeUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/TypeUtils.kt @@ -38,7 +38,7 @@ fun JetType.isUnit(): Boolean = KotlinBuiltIns.getInstance().isUnit(this) public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true): JetType { if (jetType.isFlexible()) { val flexible = jetType.flexibility() - val lowerClass = flexible.getLowerBound().getConstructor().getDeclarationDescriptor() as? ClassDescriptor? + val lowerClass = flexible.lowerBound.getConstructor().getDeclarationDescriptor() as? ClassDescriptor? val isCollection = lowerClass != null && CollectionClassMapping.getInstance().isMutableCollection(lowerClass) // (Mutable)Collection! -> MutableCollection? // Foo<(Mutable)Collection!>! -> Foo>? @@ -46,9 +46,9 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true) // Foo! -> Foo? val approximation = if (isCollection) - TypeUtils.makeNullableAsSpecified(if (jetType.isMarkedReadOnly()) flexible.getUpperBound() else flexible.getLowerBound(), outermost) + TypeUtils.makeNullableAsSpecified(if (jetType.isMarkedReadOnly()) flexible.upperBound else flexible.lowerBound, outermost) else - if (outermost) flexible.getUpperBound() else flexible.getLowerBound() + if (outermost) flexible.upperBound else flexible.lowerBound val approximated = approximateFlexibleTypes(approximation) return if (jetType.isMarkedNotNull()) approximated.makeNotNullable() else approximated }