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