Don't create platform types for annotation members

This commit is contained in:
Andrey Breslav
2014-08-08 19:48:50 +04:00
parent bdf7e924b5
commit 867956729b
4 changed files with 20 additions and 10 deletions
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.JavaConstructorDescriptor
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
import org.jetbrains.jet.lang.types.JetType
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyJavaMemberScope.MethodSignatureData
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver.PLATFORM_TYPES
public class LazyJavaClassMemberScope(
c: LazyJavaResolverContextWithTypes,
@@ -180,16 +181,17 @@ public class LazyJavaClassMemberScope(
val jReturnType = method.getReturnType() ?: throw AssertionError("Annotation method has no return type: " + method)
val attr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes(allowFlexible = false)
val varargElementType =
if (index == methods.size() - 1 && jReturnType is JavaArrayType) {
c.typeResolver.transformJavaType(
jReturnType.getComponentType(),
TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes()
attr
)
}
else null
val returnType = c.typeResolver.transformJavaType(jReturnType, TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes())
val returnType = c.typeResolver.transformJavaType(jReturnType, attr)
result.add(ValueParameterDescriptorImpl(
constructor,
@@ -46,6 +46,7 @@ import org.jetbrains.jet.lang.resolve.java.resolver.ExternalSignatureResolver
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils
import org.jetbrains.jet.utils.*
import org.jetbrains.jet.lang.resolve.java.PLATFORM_TYPES
import org.jetbrains.jet.lang.types.lowerIfFlexible
public abstract class LazyJavaMemberScope(
protected val c: LazyJavaResolverContextWithTypes,
@@ -124,7 +125,8 @@ public abstract class LazyJavaMemberScope(
val methodTypeParameters = method.getTypeParameters().map { p -> c.typeParameterResolver.resolveTypeParameter(p)!! }
val valueParameters = resolveValueParameters(c, functionDescriptorImpl, method.getValueParameters())
val returnTypeAttrs = LazyJavaTypeAttributes(c, method, TypeUsage.MEMBER_SIGNATURE_COVARIANT) {
val annotationMethod = method.getContainingClass().isAnnotationType()
val returnTypeAttrs = LazyJavaTypeAttributes(c, method, TypeUsage.MEMBER_SIGNATURE_COVARIANT, allowFlexible = !annotationMethod) {
if (c.hasReadOnlyAnnotation(method) && !c.hasMutableAnnotation(method))
TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT
else
@@ -132,9 +134,9 @@ public abstract class LazyJavaMemberScope(
}
val returnJavaType = method.getReturnType() ?: throw IllegalStateException("Constructor passed as method: $method")
// Annotation arguments are never null in Java
val returnType = c.typeResolver.transformJavaType(returnJavaType, returnTypeAttrs).let {
// Annotation arguments are never null in Java
if (method.getContainingClass().isAnnotationType()) TypeUtils.makeNotNullable(it) else it
if (annotationMethod) TypeUtils.makeNotNullable(it) else it
}
val (effectiveSignature, superFunctions, signatureErrors) = resolveMethodSignature(method, methodTypeParameters, returnType, valueParameters)
@@ -47,7 +47,7 @@ class LazyJavaTypeResolver(
assert(jetType != null, "Primitive type is not found: " + canonicalText)
return jetType!!
}
is JavaClassifierType -> if (PLATFORM_TYPES && attr.howThisTypeIsUsed != SUPERTYPE)
is JavaClassifierType -> if (PLATFORM_TYPES && attr.allowFlexible && attr.howThisTypeIsUsed != SUPERTYPE)
LazyFlexibleJavaClassifierType(javaType, attr)
else LazyJavaClassifierType(javaType, attr)
is JavaArrayType -> transformArrayType(javaType, attr)
@@ -65,9 +65,9 @@ class LazyJavaTypeResolver(
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT && !isVararg) OUT_VARIANCE else INVARIANT
val howArgumentTypeIsUsed = if (isVararg) MEMBER_SIGNATURE_CONTRAVARIANT else TYPE_ARGUMENT
val componentType = transformJavaType(javaComponentType, howArgumentTypeIsUsed.toAttributes())
val componentType = transformJavaType(javaComponentType, howArgumentTypeIsUsed.toAttributes(attr.allowFlexible))
val result = KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType)
return if (PLATFORM_TYPES)
return if (PLATFORM_TYPES && attr.allowFlexible)
DelegatingFlexibleType(
KotlinBuiltIns.getInstance().getArrayType(INVARIANT, componentType),
TypeUtils.makeNullable(
@@ -278,8 +278,10 @@ trait JavaTypeAttributes {
val howThisTypeIsUsed: TypeUsage
val howThisTypeIsUsedAccordingToAnnotations: TypeUsage
val isMarkedNotNull: Boolean
open val flexibility: Flexibility
val flexibility: Flexibility
get() = INFLEXIBLE
val allowFlexible: Boolean
get() = true
}
fun JavaTypeAttributes.isFlexible() = flexibility != INFLEXIBLE
@@ -294,6 +296,7 @@ class LazyJavaTypeAttributes(
c: LazyJavaResolverContext,
val annotationOwner: JavaAnnotationOwner,
override val howThisTypeIsUsed: TypeUsage,
override val allowFlexible: Boolean = true,
computeHowThisTypeIsUsedAccordingToAnnotations: () -> TypeUsage = {howThisTypeIsUsed}
): JavaTypeAttributes {
@@ -304,11 +307,12 @@ class LazyJavaTypeAttributes(
override val isMarkedNotNull: Boolean by c.storageManager.createLazyValue { c.hasNotNullAnnotation(annotationOwner) }
}
fun TypeUsage.toAttributes() = object : JavaTypeAttributes {
fun TypeUsage.toAttributes(allowFlexible: Boolean = true) = object : JavaTypeAttributes {
override val howThisTypeIsUsed: TypeUsage = this@toAttributes
override val howThisTypeIsUsedAccordingToAnnotations: TypeUsage
get() = howThisTypeIsUsed
override val isMarkedNotNull: Boolean = false
override val allowFlexible: Boolean = allowFlexible
}
fun JavaTypeAttributes.toFlexible(flexibility: Flexibility) =