Drop some of the TypeUsage enum entries
The only sensible usage of them was in the `isNullable` method But you can check that UPPER_BOUND/SUPERTYPE_ARGUMENT are always flexible and TYPE_ARGUMENT is not only in case of annotation methods/parameters
This commit is contained in:
+1
-4
@@ -21,12 +21,9 @@ package org.jetbrains.kotlin.load.java.components;
|
|||||||
* This enum encodes the kinds of occurrences
|
* This enum encodes the kinds of occurrences
|
||||||
*/
|
*/
|
||||||
public enum TypeUsage {
|
public enum TypeUsage {
|
||||||
// Type T occurs somewhere as a generic argument, e.g.: List<T> or List<? extends T>
|
|
||||||
TYPE_ARGUMENT,
|
|
||||||
UPPER_BOUND,
|
|
||||||
MEMBER_SIGNATURE_COVARIANT,
|
MEMBER_SIGNATURE_COVARIANT,
|
||||||
MEMBER_SIGNATURE_CONTRAVARIANT,
|
MEMBER_SIGNATURE_CONTRAVARIANT,
|
||||||
MEMBER_SIGNATURE_INVARIANT,
|
MEMBER_SIGNATURE_INVARIANT,
|
||||||
SUPERTYPE,
|
SUPERTYPE,
|
||||||
SUPERTYPE_ARGUMENT
|
COMMON
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ class LazyJavaTypeParameterDescriptor(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
return bounds.map {
|
return bounds.map {
|
||||||
c.typeResolver.transformJavaType(it, TypeUsage.UPPER_BOUND.toAttributes(upperBoundForTypeParameter = this))
|
c.typeResolver.transformJavaType(it, TypeUsage.COMMON.toAttributes(upperBoundForTypeParameter = this))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-19
@@ -73,7 +73,7 @@ class JavaTypeResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val componentType = transformJavaType(javaComponentType,
|
val componentType = transformJavaType(javaComponentType,
|
||||||
TYPE_ARGUMENT.toAttributes(attr.allowFlexible, attr.isForAnnotationParameter))
|
COMMON.toAttributes(attr.allowFlexible, attr.isForAnnotationParameter))
|
||||||
|
|
||||||
if (attr.allowFlexible) {
|
if (attr.allowFlexible) {
|
||||||
return@run KotlinTypeFactory.flexibleType(
|
return@run KotlinTypeFactory.flexibleType(
|
||||||
@@ -113,7 +113,7 @@ class JavaTypeResolver(
|
|||||||
val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
|
val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
|
||||||
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
||||||
val arguments = computeArguments(javaType, attr, constructor)
|
val arguments = computeArguments(javaType, attr, constructor)
|
||||||
val isNullable = isNullable(javaType, attr)
|
val isNullable = attr.isNullable()
|
||||||
|
|
||||||
return KotlinTypeFactory.simpleType(annotations, constructor, arguments, isNullable)
|
return KotlinTypeFactory.simpleType(annotations, constructor, arguments, isNullable)
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,6 @@ class JavaTypeResolver(
|
|||||||
// Most of the time this means there is an error in the Java code
|
// Most of the time this means there is an error in the Java code
|
||||||
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }.toList()
|
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }.toList()
|
||||||
}
|
}
|
||||||
val howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
|
|
||||||
return javaType.typeArguments.withIndex().map {
|
return javaType.typeArguments.withIndex().map {
|
||||||
indexedArgument ->
|
indexedArgument ->
|
||||||
val (i, javaTypeArgument) = indexedArgument
|
val (i, javaTypeArgument) = indexedArgument
|
||||||
@@ -242,7 +241,7 @@ class JavaTypeResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val parameter = typeParameters[i]
|
val parameter = typeParameters[i]
|
||||||
transformToTypeProjection(javaTypeArgument, howTheProjectionIsUsed.toAttributes(), parameter)
|
transformToTypeProjection(javaTypeArgument, COMMON.toAttributes(), parameter)
|
||||||
}.toList()
|
}.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +258,7 @@ class JavaTypeResolver(
|
|||||||
makeStarProjection(typeParameter, attr)
|
makeStarProjection(typeParameter, attr)
|
||||||
else {
|
else {
|
||||||
createProjection(
|
createProjection(
|
||||||
type = transformJavaType(bound, UPPER_BOUND.toAttributes()),
|
type = transformJavaType(bound, COMMON.toAttributes()),
|
||||||
projectionKind = projectionKind,
|
projectionKind = projectionKind,
|
||||||
typeParameterDescriptor = typeParameter
|
typeParameterDescriptor = typeParameter
|
||||||
)
|
)
|
||||||
@@ -274,21 +273,11 @@ class JavaTypeResolver(
|
|||||||
return this != typeParameter.variance
|
return this != typeParameter.variance
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isNullable(javaType: JavaClassifierType, attr: JavaTypeAttributes): Boolean {
|
private fun JavaTypeAttributes.isNullable(): Boolean {
|
||||||
if (attr.flexibility == FLEXIBLE_LOWER_BOUND) return false
|
if (flexibility == FLEXIBLE_LOWER_BOUND) return false
|
||||||
if (attr.flexibility == FLEXIBLE_UPPER_BOUND) return true
|
if (flexibility == FLEXIBLE_UPPER_BOUND) return true
|
||||||
|
|
||||||
return !attr.isMarkedNotNull &&
|
return !isMarkedNotNull && !isForAnnotationParameter && howThisTypeIsUsed != SUPERTYPE
|
||||||
// 'L extends List<T>' in Java is a List<T> in Kotlin, not a List<T?>
|
|
||||||
// nullability will be taken care of in individual member signatures
|
|
||||||
when (javaType.classifier) {
|
|
||||||
is JavaTypeParameter -> {
|
|
||||||
attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, UPPER_BOUND, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
|
||||||
}
|
|
||||||
is JavaClass,
|
|
||||||
null -> attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
|
||||||
else -> error("Unknown classifier: ${javaType.classifier}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user