KT-6815 Representing raw types when used as supertypes for Java classes

#KT-6815 Fixed
This commit is contained in:
Andrey Breslav
2015-03-02 19:31:02 +03:00
parent 7c62d8ed83
commit 61989ba245
14 changed files with 196 additions and 33 deletions
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import kotlin.platform.platformStatic
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
import kotlin.properties.*
class LazyJavaTypeResolver(
private val c: LazyJavaResolverContext,
@@ -89,17 +90,14 @@ class LazyJavaTypeResolver(
}.replaceAnnotations(attr.annotations)
}
private class LazyStarProjection(
val typeParameter: TypeParameterDescriptor,
val attr: JavaTypeAttributes
) : TypeProjectionBase() {
override fun isStarProjection() = true
override fun getProjectionKind() =
// projections are not allowed in immediate arguments of supertypes
if (typeParameter.getVariance() == OUT_VARIANCE || attr.howThisTypeIsUsed == SUPERTYPE) INVARIANT else OUT_VARIANCE
override fun getType() = typeParameter.getUpperBoundsAsType()
fun makeStarProjection(
typeParameter: TypeParameterDescriptor,
attr: JavaTypeAttributes
): TypeProjection {
return if (attr.howThisTypeIsUsed == SUPERTYPE)
TypeProjectionImpl(typeParameter.starProjectionType())
else
StarProjectionImpl(typeParameter)
}
private inner class LazyJavaClassifierType(
@@ -197,7 +195,7 @@ class LazyJavaTypeResolver(
TypeProjectionImpl(projectionKind, KotlinBuiltIns.getInstance().getNullableAnyType())
}
else
LazyStarProjection(parameter, attr)
makeStarProjection(parameter, attr)
}
}
if (isConstructorTypeParameter()) {
@@ -228,7 +226,7 @@ class LazyJavaTypeResolver(
is JavaWildcardType -> {
val bound = javaType.getBound()
if (bound == null)
LazyStarProjection(typeParameter, attr)
makeStarProjection(typeParameter, attr)
else {
var projectionKind = if (javaType.isExtends()) OUT_VARIANCE else IN_VARIANCE
if (projectionKind == typeParameter.getVariance()) {