diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt index 691f799ea5f..23a40fca777 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt @@ -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) diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt index eabdaa7f412..01704a2e694 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt @@ -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) = G<*> // UpperBound(T) is a type G with arguments