Refactoring: move getRepresentativeUpperBound method to core

Plus prettify it a bit
This commit is contained in:
Mikhail Zarechenskiy
2019-03-05 12:34:11 +03:00
parent 7c357c0ec0
commit 82c8289666
4 changed files with 19 additions and 21 deletions
@@ -228,3 +228,14 @@ fun UnwrappedType.canHaveUndefinedNullability(): Boolean =
constructor is NewTypeVariableConstructor ||
constructor.declarationDescriptor is TypeParameterDescriptor ||
this is NewCapturedType
val TypeParameterDescriptor.representativeUpperBound: KotlinType
get() {
assert(upperBounds.isNotEmpty()) { "Upper bounds should not be empty: $this" }
return upperBounds.firstOrNull {
val classDescriptor = it.constructor.declarationDescriptor as? ClassDescriptor ?: return@firstOrNull false
classDescriptor.kind != ClassKind.INTERFACE && classDescriptor.kind != ClassKind.ANNOTATION_CLASS
} ?: upperBounds.first()
}