Extract computing raw type arguments into separate method
This commit is contained in:
committed by
TeamCityServer
parent
a3bb9dde45
commit
63cefe228d
+26
-19
@@ -193,22 +193,12 @@ class JavaTypeResolver(
|
|||||||
return mutableLastParameterVariance != OUT_VARIANCE
|
return mutableLastParameterVariance != OUT_VARIANCE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeArguments(
|
private fun computeRawTypeArguments(
|
||||||
javaType: JavaClassifierType,
|
javaType: JavaClassifierType,
|
||||||
attr: JavaTypeAttributes,
|
typeParameters: List<TypeParameterDescriptor>,
|
||||||
constructor: TypeConstructor
|
constructor: TypeConstructor,
|
||||||
): List<TypeProjection> {
|
attr: JavaTypeAttributes
|
||||||
val isRaw = javaType.isRaw
|
) = typeParameters.map { parameter ->
|
||||||
val eraseTypeParameters =
|
|
||||||
isRaw ||
|
|
||||||
// This option is needed because sometimes we get weird versions of JDK classes in the class path,
|
|
||||||
// such as collections with no generics, so the Java types are not raw, formally, but they don't match with
|
|
||||||
// their Kotlin analogs, so we treat them as raw to avoid exceptions
|
|
||||||
(javaType.typeArguments.isEmpty() && constructor.parameters.isNotEmpty())
|
|
||||||
|
|
||||||
val typeParameters = constructor.parameters
|
|
||||||
if (eraseTypeParameters) {
|
|
||||||
return typeParameters.map { parameter ->
|
|
||||||
/*
|
/*
|
||||||
* We shouldn't erase recursive type parameters to avoid creating types unsatisfying upper bounds.
|
* We shouldn't erase recursive type parameters to avoid creating types unsatisfying upper bounds.
|
||||||
* E.g. if we got erased raw type of `class Foo<T: Foo<T>> {}` we'd create Foo<(raw) Foo<*>!>!,
|
* E.g. if we got erased raw type of `class Foo<T: Foo<T>> {}` we'd create Foo<(raw) Foo<*>!>!,
|
||||||
@@ -216,7 +206,7 @@ class JavaTypeResolver(
|
|||||||
* So we should create Foo<*> in this case (CapturedType(*) is really subtype of Foo<CapturedType(*)>).
|
* So we should create Foo<*> in this case (CapturedType(*) is really subtype of Foo<CapturedType(*)>).
|
||||||
*/
|
*/
|
||||||
if (hasTypeParameterRecursiveBounds(parameter, selfConstructor = null, attr.visitedTypeParameters))
|
if (hasTypeParameterRecursiveBounds(parameter, selfConstructor = null, attr.visitedTypeParameters))
|
||||||
return@map StarProjectionImpl(parameter)
|
return@map makeStarProjection(parameter, attr)
|
||||||
|
|
||||||
// Some activity for preventing recursion in cases like `class A<T extends A, F extends T>`
|
// Some activity for preventing recursion in cases like `class A<T extends A, F extends T>`
|
||||||
//
|
//
|
||||||
@@ -233,7 +223,7 @@ class JavaTypeResolver(
|
|||||||
val erasedUpperBound = LazyWrappedType(c.storageManager) {
|
val erasedUpperBound = LazyWrappedType(c.storageManager) {
|
||||||
typeParameterUpperBoundEraser.getErasedUpperBound(
|
typeParameterUpperBoundEraser.getErasedUpperBound(
|
||||||
parameter,
|
parameter,
|
||||||
isRaw,
|
javaType.isRaw,
|
||||||
attr.withDefaultType(constructor.declarationDescriptor?.defaultType)
|
attr.withDefaultType(constructor.declarationDescriptor?.defaultType)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -241,10 +231,27 @@ class JavaTypeResolver(
|
|||||||
rawSubstitution.computeProjection(
|
rawSubstitution.computeProjection(
|
||||||
parameter,
|
parameter,
|
||||||
// if erasure happens due to invalid arguments number, use star projections instead
|
// if erasure happens due to invalid arguments number, use star projections instead
|
||||||
if (isRaw) attr else attr.withFlexibility(INFLEXIBLE),
|
if (javaType.isRaw) attr else attr.withFlexibility(INFLEXIBLE),
|
||||||
erasedUpperBound
|
erasedUpperBound
|
||||||
)
|
)
|
||||||
}.toList()
|
}
|
||||||
|
|
||||||
|
private fun computeArguments(
|
||||||
|
javaType: JavaClassifierType,
|
||||||
|
attr: JavaTypeAttributes,
|
||||||
|
constructor: TypeConstructor
|
||||||
|
): List<TypeProjection> {
|
||||||
|
val isRaw = javaType.isRaw
|
||||||
|
val eraseTypeParameters =
|
||||||
|
isRaw ||
|
||||||
|
// This option is needed because sometimes we get weird versions of JDK classes in the class path,
|
||||||
|
// such as collections with no generics, so the Java types are not raw, formally, but they don't match with
|
||||||
|
// their Kotlin analogs, so we treat them as raw to avoid exceptions
|
||||||
|
(javaType.typeArguments.isEmpty() && constructor.parameters.isNotEmpty())
|
||||||
|
|
||||||
|
val typeParameters = constructor.parameters
|
||||||
|
if (eraseTypeParameters) {
|
||||||
|
return computeRawTypeArguments(javaType, typeParameters, constructor, attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeParameters.size != javaType.typeArguments.size) {
|
if (typeParameters.size != javaType.typeArguments.size) {
|
||||||
|
|||||||
Reference in New Issue
Block a user