Support type enhancement for super classes' types

This commit is contained in:
Victor Petukhov
2020-12-08 16:09:18 +03:00
parent 276498793f
commit f389654fea
3 changed files with 22 additions and 4 deletions
@@ -208,16 +208,17 @@ class LazyJavaClassDescriptor(
for (javaType in javaTypes) {
val kotlinType = c.typeResolver.transformJavaType(javaType, TypeUsage.SUPERTYPE.toAttributes())
if (kotlinType.constructor.declarationDescriptor is NotFoundClasses.MockClassDescriptor) {
val enhancedKotlinType = c.components.signatureEnhancement.enhanceSuperType(kotlinType, c)
if (enhancedKotlinType.constructor.declarationDescriptor is NotFoundClasses.MockClassDescriptor) {
incomplete.add(javaType)
}
if (kotlinType.constructor == purelyImplementedSupertype?.constructor) {
if (enhancedKotlinType.constructor == purelyImplementedSupertype?.constructor) {
continue
}
if (!KotlinBuiltIns.isAnyOrNullableAny(kotlinType)) {
result.add(kotlinType)
if (!KotlinBuiltIns.isAnyOrNullableAny(enhancedKotlinType)) {
result.add(enhancedKotlinType)
}
}
@@ -245,6 +245,17 @@ class SignatureEnhancement(
}
}
/*
* This method should be only used for type enhancement of base classes' type arguments:
* class A extends B<@NotNull Integer> {}
*/
fun enhanceSuperType(type: KotlinType, context: LazyJavaResolverContext) =
SignatureParts(
null, type, emptyList(), false, context,
AnnotationQualifierApplicabilityType.TYPE_USE,
typeParameterBounds = true
).enhance().type
private fun ValueParameterDescriptor.hasDefaultValueInAnnotation(type: KotlinType) =
when (val defaultValue = getDefaultValueFromAnnotation()) {
is StringDefaultValue -> type.lexicalCastFrom(defaultValue.value) != null