Support type enhancement for super classes' types
This commit is contained in:
+6
@@ -91,6 +91,12 @@ class BinaryJavaClass(
|
|||||||
val translatedPath = BinaryJavaAnnotation.translatePath(typePath)
|
val translatedPath = BinaryJavaAnnotation.translatePath(typePath)
|
||||||
|
|
||||||
when (typeReference.sort) {
|
when (typeReference.sort) {
|
||||||
|
TypeReference.CLASS_EXTENDS -> {
|
||||||
|
val baseType: JavaType = if (typeReference.superTypeIndex == -1) superclass!! else interfaces[typeReference.superTypeIndex]
|
||||||
|
val targetType = BinaryJavaAnnotation.computeTargetType(baseType, translatedPath)
|
||||||
|
|
||||||
|
return BinaryJavaAnnotation.addAnnotation(targetType as JavaPlainType, descriptor, context, signatureParser)
|
||||||
|
}
|
||||||
TypeReference.CLASS_TYPE_PARAMETER_BOUND -> {
|
TypeReference.CLASS_TYPE_PARAMETER_BOUND -> {
|
||||||
val baseType = computeTypeParameterBound(typeParameters, typeReference)
|
val baseType = computeTypeParameterBound(typeParameters, typeReference)
|
||||||
val targetType = BinaryJavaAnnotation.computeTargetType(baseType, translatedPath)
|
val targetType = BinaryJavaAnnotation.computeTargetType(baseType, translatedPath)
|
||||||
|
|||||||
+5
-4
@@ -208,16 +208,17 @@ class LazyJavaClassDescriptor(
|
|||||||
|
|
||||||
for (javaType in javaTypes) {
|
for (javaType in javaTypes) {
|
||||||
val kotlinType = c.typeResolver.transformJavaType(javaType, TypeUsage.SUPERTYPE.toAttributes())
|
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)
|
incomplete.add(javaType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kotlinType.constructor == purelyImplementedSupertype?.constructor) {
|
if (enhancedKotlinType.constructor == purelyImplementedSupertype?.constructor) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!KotlinBuiltIns.isAnyOrNullableAny(kotlinType)) {
|
if (!KotlinBuiltIns.isAnyOrNullableAny(enhancedKotlinType)) {
|
||||||
result.add(kotlinType)
|
result.add(enhancedKotlinType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
@@ -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) =
|
private fun ValueParameterDescriptor.hasDefaultValueInAnnotation(type: KotlinType) =
|
||||||
when (val defaultValue = getDefaultValueFromAnnotation()) {
|
when (val defaultValue = getDefaultValueFromAnnotation()) {
|
||||||
is StringDefaultValue -> type.lexicalCastFrom(defaultValue.value) != null
|
is StringDefaultValue -> type.lexicalCastFrom(defaultValue.value) != null
|
||||||
|
|||||||
Reference in New Issue
Block a user