Minor. Getters replaced by properties
This commit is contained in:
+2
-2
@@ -289,8 +289,8 @@ class LazyJavaTypeResolver(
|
|||||||
|
|
||||||
private class Impl(val flexibility: Flexibility) : CustomTypeVariable, Specificity {
|
private class Impl(val flexibility: Flexibility) : CustomTypeVariable, Specificity {
|
||||||
|
|
||||||
private val lowerBound: JetType get() = flexibility.getLowerBound()
|
private val lowerBound: JetType get() = flexibility.lowerBound
|
||||||
private val upperBound: JetType get() = flexibility.getUpperBound()
|
private val upperBound: JetType get() = flexibility.upperBound
|
||||||
|
|
||||||
override val isTypeVariable: Boolean = lowerBound.getConstructor() == upperBound.getConstructor()
|
override val isTypeVariable: Boolean = lowerBound.getConstructor() == upperBound.getConstructor()
|
||||||
&& lowerBound.getConstructor().getDeclarationDescriptor() is TypeParameterDescriptor
|
&& lowerBound.getConstructor().getDeclarationDescriptor() is TypeParameterDescriptor
|
||||||
|
|||||||
@@ -32,11 +32,10 @@ public trait FlexibleTypeCapabilities {
|
|||||||
|
|
||||||
public trait Flexibility : TypeCapability {
|
public trait Flexibility : TypeCapability {
|
||||||
// lowerBound is a subtype of upperBound
|
// lowerBound is a subtype of upperBound
|
||||||
public fun getUpperBound(): JetType
|
public val lowerBound: JetType
|
||||||
|
public val upperBound: JetType
|
||||||
|
|
||||||
public fun getLowerBound(): JetType
|
public val extraCapabilities: FlexibleTypeCapabilities
|
||||||
|
|
||||||
public fun getExtraCapabilities(): FlexibleTypeCapabilities
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun JetType.isFlexible(): Boolean = this.getCapability(javaClass<Flexibility>()) != null
|
public fun JetType.isFlexible(): Boolean = this.getCapability(javaClass<Flexibility>()) != null
|
||||||
@@ -74,8 +73,8 @@ fun Collection<TypeProjection>.singleBestRepresentative(): TypeProjection? {
|
|||||||
return TypeProjectionImpl(projectionKinds.single(), bestType)
|
return TypeProjectionImpl(projectionKinds.single(), bestType)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun JetType.lowerIfFlexible(): JetType = if (this.isFlexible()) this.flexibility().getLowerBound() 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().getUpperBound() else this
|
public fun JetType.upperIfFlexible(): JetType = if (this.isFlexible()) this.flexibility().upperBound else this
|
||||||
|
|
||||||
public trait NullAwareness : TypeCapability {
|
public trait NullAwareness : TypeCapability {
|
||||||
public fun makeNullableAsSpecified(nullable: Boolean): JetType
|
public fun makeNullableAsSpecified(nullable: Boolean): JetType
|
||||||
@@ -115,9 +114,9 @@ public fun JetType.getApproximationTo(
|
|||||||
|
|
||||||
|
|
||||||
public open class DelegatingFlexibleType protected (
|
public open class DelegatingFlexibleType protected (
|
||||||
private val _lowerBound: JetType,
|
override val lowerBound: JetType,
|
||||||
private val _upperBound: JetType,
|
override val upperBound: JetType,
|
||||||
private val _extraCapabilities: FlexibleTypeCapabilities
|
override val extraCapabilities: FlexibleTypeCapabilities
|
||||||
) : DelegatingType(), NullAwareness, Flexibility, Approximation {
|
) : DelegatingType(), NullAwareness, Flexibility, Approximation {
|
||||||
class object {
|
class object {
|
||||||
fun create(lowerBound: JetType, upperBound: JetType, extraCapabilities: FlexibleTypeCapabilities): JetType {
|
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 (!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 (!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 (lowerBound != upperBound) { "Lower and upper bounds are equal: $lowerBound == $upperBound" }
|
||||||
assert (JetTypeChecker.DEFAULT.isSubtypeOf(_lowerBound, _upperBound)) {
|
assert (JetTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) {
|
||||||
"Lower bound $_lowerBound of a flexible type must be a subtype of the upper bound $_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 <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||||
return getExtraCapabilities().getCapability(capabilityClass, this, this) ?: super<DelegatingType>.getCapability(capabilityClass)
|
return extraCapabilities.getCapability(capabilityClass, this, this) ?: super<DelegatingType>.getCapability(capabilityClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(nullable: Boolean): JetType {
|
override fun makeNullableAsSpecified(nullable: Boolean): JetType {
|
||||||
return create(
|
return create(
|
||||||
TypeUtils.makeNullableAsSpecified(_lowerBound, nullable),
|
TypeUtils.makeNullableAsSpecified(lowerBound, nullable),
|
||||||
TypeUtils.makeNullableAsSpecified(_upperBound, nullable),
|
TypeUtils.makeNullableAsSpecified(upperBound, nullable),
|
||||||
getExtraCapabilities())
|
extraCapabilities)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: Approximation.DataFlowExtras): Approximation.Info? {
|
override fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: Approximation.DataFlowExtras): Approximation.Info? {
|
||||||
// val foo: Any? = foo() : Foo!
|
// 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) {
|
// if (foo : Foo! != null) {
|
||||||
// val bar: Any = foo
|
// 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
|
// TODO: maybe check possibleTypes to avoid extra approximations
|
||||||
|
|
||||||
return Approximation.Info(this, expectedType, dataFlowExtras.presentableText)
|
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')"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ fun JetType.isUnit(): Boolean = KotlinBuiltIns.getInstance().isUnit(this)
|
|||||||
public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true): JetType {
|
public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true): JetType {
|
||||||
if (jetType.isFlexible()) {
|
if (jetType.isFlexible()) {
|
||||||
val flexible = jetType.flexibility()
|
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)
|
val isCollection = lowerClass != null && CollectionClassMapping.getInstance().isMutableCollection(lowerClass)
|
||||||
// (Mutable)Collection<T>! -> MutableCollection<T>?
|
// (Mutable)Collection<T>! -> MutableCollection<T>?
|
||||||
// Foo<(Mutable)Collection<T>!>! -> Foo<Collection<T>>?
|
// Foo<(Mutable)Collection<T>!>! -> Foo<Collection<T>>?
|
||||||
@@ -46,9 +46,9 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true)
|
|||||||
// Foo<Bar!>! -> Foo<Bar>?
|
// Foo<Bar!>! -> Foo<Bar>?
|
||||||
val approximation =
|
val approximation =
|
||||||
if (isCollection)
|
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
|
else
|
||||||
if (outermost) flexible.getUpperBound() else flexible.getLowerBound()
|
if (outermost) flexible.upperBound else flexible.lowerBound
|
||||||
val approximated = approximateFlexibleTypes(approximation)
|
val approximated = approximateFlexibleTypes(approximation)
|
||||||
return if (jetType.isMarkedNotNull()) approximated.makeNotNullable() else approximated
|
return if (jetType.isMarkedNotNull()) approximated.makeNotNullable() else approximated
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user