Use TypeSystemCommonBackendContext in KotlinTypeMapper.writeGenericArguments

This commit is contained in:
Alexander Udalov
2019-06-21 13:41:43 +02:00
parent 2585ce0aa7
commit c27d9c4546
5 changed files with 81 additions and 35 deletions
@@ -5,9 +5,23 @@
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
import org.jetbrains.kotlin.types.model.TypeSystemContext
interface TypeSystemCommonBackendContext : TypeSystemContext {
fun TypeConstructorMarker.isFinalClassOrEnumEntryOrAnnotationClassConstructor(): Boolean
fun KotlinTypeMarker.hasAnnotation(fqName: FqName): Boolean
/**
* @return value of the first argument of the annotation with the given [fqName], if the annotation is present and
* the argument is of a primitive type or a String, or null otherwise.
*
* Note that this method returns null if no arguments are provided, even if the corresponding annotation parameter has a default value.
*
* TODO: provide a more granular & elaborate API here to reduce confusion
*/
fun KotlinTypeMarker.getAnnotationFirstArgumentValue(fqName: FqName): Any?
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.resolve.descriptorUtil.hasExactAnnotation
@@ -485,6 +486,15 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
return this is NewCapturedTypeConstructor
}
override fun KotlinTypeMarker.hasAnnotation(fqName: FqName): Boolean {
require(this is KotlinType, this::errorMessage)
return annotations.hasAnnotation(fqName)
}
override fun KotlinTypeMarker.getAnnotationFirstArgumentValue(fqName: FqName): Any? {
require(this is KotlinType, this::errorMessage)
return annotations.findAnnotation(fqName)?.allValueArguments?.values?.firstOrNull()?.value
}
}
fun TypeVariance.convertVariance(): Variance {