Minor. Use getOrElse from stdlib

This commit is contained in:
Denis Zharkov
2015-07-06 18:59:39 +03:00
parent fd43799c6e
commit e13f34a8a0
2 changed files with 2 additions and 6 deletions
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.checker.JetTypeChecker
import org.jetbrains.kotlin.types.flexibility
import org.jetbrains.kotlin.types.isFlexible
import org.jetbrains.kotlin.utils.getOrDefault
import java.util.ArrayList
enum class NullabilityQualifier {
@@ -126,13 +125,13 @@ fun JetType.computeIndexedQualifiersForOverride(fromSupertypes: Collection<JetTy
assert(isHeadTypeConstructor || !onlyHeadTypeConstructor) { "Only head type constructors should be computed" }
val qualifiers = indexedThisType[index]
val verticalSlice = indexedFromSupertypes.map { it.getOrDefault(index, { null }) }.filterNotNull()
val verticalSlice = indexedFromSupertypes.map { it.getOrElse(index, { null }) }.filterNotNull()
// Only the head type constructor is safely co-variant
qualifiers.computeQualifiersForOverride(verticalSlice, isCovariant && isHeadTypeConstructor)
}
return { index -> computedResult.getOrDefault(index) { JavaTypeQualifiers.NONE } }
return { index -> computedResult.getOrElse(index) { JavaTypeQualifiers.NONE } }
}
private fun JetType.computeQualifiersForOverride(fromSupertypes: Collection<JetType>, isCovariant: Boolean): JavaTypeQualifiers {
@@ -105,6 +105,3 @@ public fun <T> Collection<T>.toReadOnlyList(): List<T> =
if (isEmpty()) Collections.emptyList() else ArrayList(this)
public fun <T: Any> T?.singletonOrEmptyList(): List<T> = if (this != null) Collections.singletonList(this) else Collections.emptyList()
public inline fun <T> List<T>.getOrDefault(index: Int, default: (Int) -> T): T = if (index in 0..size() - 1) this[index] else default(index)
public inline fun <T> Array<T>.getOrDefault(index: Int, default: (Int) -> T): T = if (index in 0..size() - 1) this[index] else default(index)