Replace JavaTypeAttributes interface with simple data class
This commit is contained in:
+4
-10
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.lazy.childForMethod
|
||||
import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeAttributes
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaArrayType
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||
@@ -147,8 +147,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
||||
|
||||
protected fun computeMethodReturnType(method: JavaMethod, c: LazyJavaResolverContext): KotlinType {
|
||||
val annotationMethod = method.containingClass.isAnnotationType
|
||||
val returnTypeAttrs = LazyJavaTypeAttributes(
|
||||
TypeUsage.COMMON,
|
||||
val returnTypeAttrs = TypeUsage.COMMON.toAttributes(
|
||||
isForAnnotationParameter = annotationMethod
|
||||
)
|
||||
return c.typeResolver.transformJavaType(method.returnType, returnTypeAttrs)
|
||||
@@ -166,10 +165,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
||||
val (index, javaParameter) = pair
|
||||
|
||||
val annotations = c.resolveAnnotations(javaParameter)
|
||||
val typeUsage =
|
||||
LazyJavaTypeAttributes(
|
||||
TypeUsage.COMMON
|
||||
)
|
||||
val typeUsage = TypeUsage.COMMON.toAttributes()
|
||||
val (outType, varargElementType) =
|
||||
if (javaParameter.isVararg) {
|
||||
val paramType = javaParameter.type as? JavaArrayType
|
||||
@@ -287,9 +283,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
||||
val isNotNullable = !(field.isFinalStatic && field.hasConstantNotNullInitializer)
|
||||
val propertyType = c.typeResolver.transformJavaType(
|
||||
field.type,
|
||||
LazyJavaTypeAttributes(
|
||||
TypeUsage.COMMON
|
||||
)
|
||||
TypeUsage.COMMON.toAttributes()
|
||||
)
|
||||
if (!isNotNullable) {
|
||||
return TypeUtils.makeNotNullable(propertyType)
|
||||
|
||||
+13
-26
@@ -282,15 +282,14 @@ internal fun makeStarProjection(
|
||||
StarProjectionImpl(typeParameter)
|
||||
}
|
||||
|
||||
interface JavaTypeAttributes {
|
||||
val howThisTypeIsUsed: TypeUsage
|
||||
val flexibility: JavaTypeFlexibility
|
||||
get() = INFLEXIBLE
|
||||
val isForAnnotationParameter: Boolean
|
||||
get() = false
|
||||
// Current type is upper bound of this type parameter
|
||||
val upperBoundOfTypeParameter: TypeParameterDescriptor?
|
||||
get() = null
|
||||
data class JavaTypeAttributes(
|
||||
val howThisTypeIsUsed: TypeUsage,
|
||||
val flexibility: JavaTypeFlexibility = INFLEXIBLE,
|
||||
val isForAnnotationParameter: Boolean = false,
|
||||
// Current type is upper bound of this type parameter
|
||||
val upperBoundOfTypeParameter: TypeParameterDescriptor? = null
|
||||
) {
|
||||
fun withFlexibility(flexibility: JavaTypeFlexibility) = copy(flexibility = flexibility)
|
||||
}
|
||||
|
||||
enum class JavaTypeFlexibility {
|
||||
@@ -299,26 +298,14 @@ enum class JavaTypeFlexibility {
|
||||
FLEXIBLE_LOWER_BOUND
|
||||
}
|
||||
|
||||
class LazyJavaTypeAttributes(
|
||||
override val howThisTypeIsUsed: TypeUsage,
|
||||
override val isForAnnotationParameter: Boolean = false
|
||||
): JavaTypeAttributes
|
||||
|
||||
fun TypeUsage.toAttributes(
|
||||
isForAnnotationParameter: Boolean = false,
|
||||
upperBoundForTypeParameter: TypeParameterDescriptor? = null
|
||||
) = object : JavaTypeAttributes {
|
||||
override val howThisTypeIsUsed: TypeUsage = this@toAttributes
|
||||
|
||||
override val isForAnnotationParameter: Boolean = isForAnnotationParameter
|
||||
override val upperBoundOfTypeParameter: TypeParameterDescriptor? = upperBoundForTypeParameter
|
||||
}
|
||||
|
||||
fun JavaTypeAttributes.withFlexibility(flexibility: JavaTypeFlexibility) =
|
||||
object : JavaTypeAttributes by this {
|
||||
override val flexibility = flexibility
|
||||
}
|
||||
|
||||
) = JavaTypeAttributes(
|
||||
this,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
upperBoundOfTypeParameter = upperBoundForTypeParameter
|
||||
)
|
||||
|
||||
// Definition:
|
||||
// ErasedUpperBound(T : G<t>) = G<*> // UpperBound(T) is a type G<t> with arguments
|
||||
|
||||
Reference in New Issue
Block a user