FIR Java: simplify flexible nullability manipulations
This commit is contained in:
committed by
teamcityserver
parent
fc7f589caa
commit
b658e99f91
@@ -34,7 +34,7 @@ class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : A
|
||||
}
|
||||
|
||||
val Empty: ConeAttributes = ConeAttributes(emptyList())
|
||||
val WithFlexibleNullability: ConeAttributes = ConeAttributes(listOf(CompilerConeAttributes.FlexibleNullability))
|
||||
internal val WithFlexibleNullability: ConeAttributes = ConeAttributes(listOf(CompilerConeAttributes.FlexibleNullability))
|
||||
|
||||
fun create(attributes: List<ConeAttribute<*>>): ConeAttributes {
|
||||
return if (attributes.isEmpty()) {
|
||||
@@ -68,13 +68,6 @@ class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : A
|
||||
return perform(other) { this.intersect(it) }
|
||||
}
|
||||
|
||||
fun intersectUnless(other: ConeAttributes, predicate: (ConeAttributes) -> Boolean): ConeAttributes {
|
||||
return if (predicate.invoke(this))
|
||||
this
|
||||
else
|
||||
perform(other) { this.intersect(it) }
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<ConeAttribute<*>> {
|
||||
return arrayMap.iterator()
|
||||
}
|
||||
@@ -101,3 +94,12 @@ class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : A
|
||||
return arrayMap.isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
private fun ConeAttributes.intersectUnless(other: ConeAttributes, predicate: (ConeAttributes) -> Boolean): ConeAttributes =
|
||||
if (predicate.invoke(this)) this else intersect(other)
|
||||
|
||||
fun ConeAttributes.withFlexible(): ConeAttributes =
|
||||
intersect(ConeAttributes.WithFlexibleNullability)
|
||||
|
||||
fun ConeAttributes.withFlexibleUnless(predicate: (ConeAttributes) -> Boolean): ConeAttributes =
|
||||
intersectUnless(ConeAttributes.WithFlexibleNullability, predicate)
|
||||
|
||||
@@ -200,7 +200,7 @@ private fun ClassId.toConeFlexibleType(
|
||||
toConeKotlinType(
|
||||
typeArguments,
|
||||
isNullable = false,
|
||||
attributes.intersectUnless(ConeAttributes.WithFlexibleNullability) { it.hasEnhancedNullability }
|
||||
attributes.withFlexibleUnless { it.hasEnhancedNullability }
|
||||
),
|
||||
toConeKotlinType(typeArgumentsForUpper, isNullable = true, attributes)
|
||||
)
|
||||
@@ -242,7 +242,7 @@ private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
||||
else
|
||||
ConeFlexibleType(
|
||||
lowerBound.withAttributes(
|
||||
lowerBound.attributes.intersectUnless(ConeAttributes.WithFlexibleNullability) { it.hasEnhancedNullability }
|
||||
lowerBound.attributes.withFlexibleUnless { it.hasEnhancedNullability }
|
||||
),
|
||||
upperBound
|
||||
)
|
||||
@@ -316,7 +316,7 @@ private fun getErasedVersionOfFirstUpperBound(
|
||||
// Avoid exponential complexity
|
||||
ConeFlexibleType(
|
||||
lowerBound.withAttributes(
|
||||
lowerBound.attributes.intersectUnless(ConeAttributes.WithFlexibleNullability) { it.hasEnhancedNullability }
|
||||
lowerBound.attributes.withFlexibleUnless { it.hasEnhancedNullability }
|
||||
),
|
||||
lowerBound.withNullability(ConeNullability.NULLABLE)
|
||||
)
|
||||
|
||||
@@ -92,7 +92,7 @@ private fun ConeKotlinType.enhanceConeKotlinType(
|
||||
val lowerResult = lowerBound.enhanceInflexibleType(
|
||||
session, TypeComponentPosition.FLEXIBLE_LOWER, qualifiers, index,
|
||||
attributes = if (needsFlexibleNullabilityAttribute)
|
||||
lowerBound.attributes.intersect(ConeAttributes.WithFlexibleNullability)
|
||||
lowerBound.attributes.withFlexible()
|
||||
else
|
||||
lowerBound.attributes
|
||||
)
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ class JavaClassMembersEnhancementScope(
|
||||
if (valueParameter.returnTypeRef.coneType is ConeFlexibleType) {
|
||||
ConeFlexibleType(
|
||||
type.withAttributes(
|
||||
type.attributes.intersectUnless(ConeAttributes.WithFlexibleNullability) {
|
||||
type.attributes.withFlexibleUnless {
|
||||
it.hasEnhancedNullability
|
||||
}
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user