Inject builtins in constants
This commit is contained in:
+1
-1
@@ -64,7 +64,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
annotationClass?.getDefaultType() ?: ErrorUtils.createErrorType(fqName.asString())
|
||||
}
|
||||
|
||||
private val factory = CompileTimeConstantFactory(CompileTimeConstant.Parameters.Impl(true, false, false))
|
||||
private val factory = CompileTimeConstantFactory(CompileTimeConstant.Parameters.Impl(true, false, false), c.module.builtIns)
|
||||
|
||||
override fun getType(): JetType = type()
|
||||
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
storageManager, kotlinClassFinder, errorReporter
|
||||
) {
|
||||
private val annotationDeserializer = AnnotationDeserializer(module)
|
||||
private val factory = CompileTimeConstantFactory(CompileTimeConstant.Parameters.ThrowException)
|
||||
private val factory = CompileTimeConstantFactory(CompileTimeConstant.Parameters.ThrowException, module.builtIns)
|
||||
|
||||
override fun loadTypeAnnotation(proto: ProtoBuf.Annotation, nameResolver: NameResolver): AnnotationDescriptor =
|
||||
annotationDeserializer.deserializeAnnotation(proto, nameResolver)
|
||||
|
||||
@@ -23,7 +23,8 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class AnnotationValue(value: AnnotationDescriptor) :
|
||||
CompileTimeConstant<AnnotationDescriptor>(value, CompileTimeConstant.Parameters.Impl(true, false, false)) {
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = value.getType()
|
||||
override val type: JetType
|
||||
get() = value.getType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitAnnotationValue(this, data)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.*
|
||||
|
||||
public class ArrayValue(
|
||||
value: List<CompileTimeConstant<*>>,
|
||||
private val type: JetType,
|
||||
override val type: JetType,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
) : CompileTimeConstant<List<CompileTimeConstant<*>>>(value, parameters) {
|
||||
|
||||
@@ -40,8 +40,6 @@ public class ArrayValue(
|
||||
assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value }
|
||||
}
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = type
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitArrayValue(this, data)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
||||
@@ -22,11 +22,12 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class BooleanValue(
|
||||
value: Boolean,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : CompileTimeConstant<Boolean>(value, parameters) {
|
||||
override fun isPure(): Boolean = false
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getBooleanType()
|
||||
override val type = builtIns.getBooleanType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitBooleanValue(this, data)
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class ByteValue(
|
||||
value: Byte,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : IntegerValueConstant<Byte>(value, parameters) {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getByteType()
|
||||
override val type = builtIns.getByteType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitByteValue(this, data)
|
||||
|
||||
|
||||
@@ -22,10 +22,11 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class CharValue(
|
||||
value: Char,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : IntegerValueConstant<Char>(value, parameters) {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getCharType()
|
||||
override val type = builtIns.getCharType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitCharValue(this, data)
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class CompileTimeConstant<T> protected constructor(
|
||||
|
||||
public open fun usesVariableAsConstant(): Boolean = parameters.usesVariableAsConstant
|
||||
|
||||
public abstract fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType
|
||||
public abstract val type: JetType
|
||||
|
||||
public abstract fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R
|
||||
|
||||
|
||||
+14
-11
@@ -22,28 +22,31 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
public class CompileTimeConstantFactory(private val parameters: CompileTimeConstant.Parameters) {
|
||||
fun createLongValue(value: Long) = LongValue(value, parameters)
|
||||
public class CompileTimeConstantFactory(
|
||||
private val parameters: CompileTimeConstant.Parameters,
|
||||
private val builtins: KotlinBuiltIns
|
||||
) {
|
||||
fun createLongValue(value: Long) = LongValue(value, parameters, builtins)
|
||||
|
||||
fun createIntValue(value: Int) = IntValue(value, parameters)
|
||||
fun createIntValue(value: Int) = IntValue(value, parameters, builtins)
|
||||
|
||||
fun createErrorValue(message: String) = ErrorValue.create(message)
|
||||
|
||||
fun createShortValue(value: Short) = ShortValue(value, parameters)
|
||||
fun createShortValue(value: Short) = ShortValue(value, parameters, builtins)
|
||||
|
||||
fun createByteValue(value: Byte) = ByteValue(value, parameters)
|
||||
fun createByteValue(value: Byte) = ByteValue(value, parameters, builtins)
|
||||
|
||||
fun createDoubleValue(value: Double) = DoubleValue(value, parameters)
|
||||
fun createDoubleValue(value: Double) = DoubleValue(value, parameters, builtins)
|
||||
|
||||
fun createFloatValue(value: Float) = FloatValue(value, parameters)
|
||||
fun createFloatValue(value: Float) = FloatValue(value, parameters, builtins)
|
||||
|
||||
fun createBooleanValue(value: Boolean) = BooleanValue(value, parameters)
|
||||
fun createBooleanValue(value: Boolean) = BooleanValue(value, parameters, builtins)
|
||||
|
||||
fun createCharValue(value: Char) = CharValue(value, parameters)
|
||||
fun createCharValue(value: Char) = CharValue(value, parameters, builtins)
|
||||
|
||||
fun createStringValue(value: String) = StringValue(value, parameters)
|
||||
fun createStringValue(value: String) = StringValue(value, parameters, builtins)
|
||||
|
||||
fun createNullValue() = NullValue
|
||||
fun createNullValue() = NullValue(builtins)
|
||||
|
||||
fun createEnumValue(enumEntryClass: ClassDescriptor): EnumValue = EnumValue(enumEntryClass)
|
||||
|
||||
|
||||
@@ -22,12 +22,13 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class DoubleValue(
|
||||
value: Double,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : CompileTimeConstant<Double>(value, parameters) {
|
||||
|
||||
override fun isPure() = false
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getDoubleType()
|
||||
override val type = builtIns.getDoubleType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitDoubleValue(this, data)
|
||||
|
||||
|
||||
@@ -27,13 +27,12 @@ public class EnumValue(
|
||||
value: ClassDescriptor
|
||||
) : CompileTimeConstant<ClassDescriptor>(value, CompileTimeConstant.Parameters.Impl(true, false, false)) {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = getType()
|
||||
|
||||
private fun getType() = value.classObjectType.sure { "Enum entry must have a class object type: " + value }
|
||||
override val type: JetType
|
||||
get() = value.classObjectType.sure { "Enum entry must have a class object type: " + value }
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitEnumValue(this, data)
|
||||
|
||||
override fun toString() = "${getType()}.${value.getName()}"
|
||||
override fun toString() = "$type.${value.getName()}"
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class ErrorValue : CompileTimeConstant<Unit>(Unit, CompileTimeCo
|
||||
|
||||
public class ErrorValueWithMessage(public val message: String) : ErrorValue() {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = ErrorUtils.createErrorType(message)
|
||||
override val type = ErrorUtils.createErrorType(message)
|
||||
|
||||
override fun toString() = message
|
||||
}
|
||||
|
||||
@@ -22,11 +22,12 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class FloatValue(
|
||||
value: Float,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : CompileTimeConstant<Float>(value, parameters) {
|
||||
override fun isPure() = false
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getFloatType()
|
||||
override val type = builtIns.getFloatType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitFloatValue(this, data)
|
||||
|
||||
|
||||
@@ -22,10 +22,11 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class IntValue(
|
||||
value: Int,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : IntegerValueConstant<Int>(value, parameters) {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getIntType()
|
||||
override val type = builtIns.getIntType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitIntValue(this, data)
|
||||
|
||||
|
||||
+4
-6
@@ -32,12 +32,10 @@ public class IntegerValueTypeConstant(
|
||||
|
||||
private val typeConstructor = IntegerValueTypeConstructor(value.toLong())
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return JetTypeImpl(
|
||||
Annotations.EMPTY, typeConstructor, false, emptyList<TypeProjection>()
|
||||
, ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)
|
||||
)
|
||||
}
|
||||
override val type = JetTypeImpl(
|
||||
Annotations.EMPTY, typeConstructor, false, emptyList<TypeProjection>()
|
||||
, ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)
|
||||
)
|
||||
|
||||
deprecated("")
|
||||
override val value: Number
|
||||
|
||||
@@ -20,9 +20,8 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class KClassValue(private val type: JetType) :
|
||||
public class KClassValue(override val type: JetType) :
|
||||
CompileTimeConstant<JetType>(type, CompileTimeConstant.Parameters.Impl(true, false, false)) {
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = type
|
||||
override val value: JetType
|
||||
get() = type.getArguments().single().getType()
|
||||
|
||||
|
||||
@@ -22,10 +22,11 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class LongValue(
|
||||
value: Long,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : IntegerValueConstant<Long>(value, parameters) {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getLongType()
|
||||
override val type = builtIns.getLongType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitLongValue(this, data)
|
||||
|
||||
|
||||
@@ -20,9 +20,11 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public object NullValue : CompileTimeConstant<Void?>(null, CompileTimeConstant.Parameters.Impl(false, false, false)) {
|
||||
public class NullValue(
|
||||
builtIns: KotlinBuiltIns
|
||||
) : CompileTimeConstant<Void?>(null, CompileTimeConstant.Parameters.Impl(false, false, false)) {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getNullableNothingType()
|
||||
override val type = builtIns.getNullableNothingType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitNullValue(this, data)
|
||||
|
||||
|
||||
@@ -22,10 +22,11 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class ShortValue(
|
||||
value: Short,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : IntegerValueConstant<Short>(value, parameters) {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getShortType()
|
||||
override val type = builtIns.getShortType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitShortValue(this, data)
|
||||
|
||||
|
||||
@@ -22,11 +22,12 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class StringValue(
|
||||
value: String,
|
||||
parameters: CompileTimeConstant.Parameters
|
||||
parameters: CompileTimeConstant.Parameters,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : CompileTimeConstant<String>(value, parameters) {
|
||||
override fun isPure() = false
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getStringType()
|
||||
override val type = builtIns.getStringType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitStringValue(this, data)
|
||||
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
|
||||
private val builtIns: KotlinBuiltIns
|
||||
get() = module.builtIns
|
||||
|
||||
private val factory = CompileTimeConstantFactory(CompileTimeConstant.Parameters.ThrowException)
|
||||
private val factory = CompileTimeConstantFactory(CompileTimeConstant.Parameters.ThrowException, builtIns)
|
||||
|
||||
public fun deserializeAnnotation(proto: Annotation, nameResolver: NameResolver): AnnotationDescriptor {
|
||||
val annotationClass = resolveClass(nameResolver.getClassId(proto.getId()))
|
||||
@@ -121,7 +121,7 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
|
||||
else -> error("Unsupported annotation argument type: ${value.getType()} (expected $expectedType)")
|
||||
}
|
||||
|
||||
if (result.getType(builtIns) isSubtypeOf expectedType) {
|
||||
if (result.type isSubtypeOf expectedType) {
|
||||
return result
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user