[FIR] Make constant values in fir serialization internal

This is needed to avoid possible name clash with ConstantValue from FE 1.0
This commit is contained in:
Dmitriy Novozhilov
2020-09-03 15:30:32 +03:00
parent 9e1e525343
commit 2f4bd626fc
5 changed files with 27 additions and 27 deletions
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.fir.types.arrayElementType
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.Flags
object FirAnnotationArgumentVisitor : AnnotationArgumentVisitor<Unit, FirAnnotationArgumentVisitorData>() {
internal object FirAnnotationArgumentVisitor : AnnotationArgumentVisitor<Unit, FirAnnotationArgumentVisitorData>() {
override fun visitAnnotationValue(value: AnnotationValue, data: FirAnnotationArgumentVisitorData) {
data.builder.type = ProtoBuf.Annotation.Argument.Value.Type.ANNOTATION
// TODO: annotation = serializeAnnotation(value.value)
@@ -29,7 +29,7 @@ class FirAnnotationSerializer(private val session: FirSession, internal val stri
}
}.build()
fun valueProto(constant: ConstantValue<*>): ProtoBuf.Annotation.Argument.Value.Builder =
internal fun valueProto(constant: ConstantValue<*>): ProtoBuf.Annotation.Argument.Value.Builder =
ProtoBuf.Annotation.Argument.Value.newBuilder().apply {
constant.accept(
FirAnnotationArgumentVisitor,
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.fir.serialization.constant
abstract class AnnotationArgumentVisitor<R, D> {
internal abstract class AnnotationArgumentVisitor<R, D> {
abstract fun visitLongValue(value: LongValue, data: D): R
abstract fun visitIntValue(value: IntValue, data: D): R
abstract fun visitErrorValue(value: ErrorValue, data: D): R
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue
sealed class ConstantValue<out T>(open val value: T) {
internal sealed class ConstantValue<out T>(open val value: T) {
abstract fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R
override fun equals(other: Any?): Boolean = this === other || value == (other as? ConstantValue<*>)?.value
@@ -27,30 +27,30 @@ sealed class ConstantValue<out T>(open val value: T) {
open fun stringTemplateValue(): String = value.toString()
}
abstract class IntegerValueConstant<out T> protected constructor(value: T) : ConstantValue<T>(value)
abstract class UnsignedValueConstant<out T> protected constructor(value: T) : ConstantValue<T>(value)
internal abstract class IntegerValueConstant<out T> protected constructor(value: T) : ConstantValue<T>(value)
internal abstract class UnsignedValueConstant<out T> protected constructor(value: T) : ConstantValue<T>(value)
class AnnotationValue(value: FirAnnotationCall) : ConstantValue<FirAnnotationCall>(value) {
internal class AnnotationValue(value: FirAnnotationCall) : ConstantValue<FirAnnotationCall>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitAnnotationValue(this, data)
}
class ArrayValue(
internal class ArrayValue(
value: List<ConstantValue<*>>,
) : ConstantValue<List<ConstantValue<*>>>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitArrayValue(this, data)
}
class BooleanValue(value: Boolean) : ConstantValue<Boolean>(value) {
internal class BooleanValue(value: Boolean) : ConstantValue<Boolean>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitBooleanValue(this, data)
}
class ByteValue(value: Byte) : IntegerValueConstant<Byte>(value) {
internal class ByteValue(value: Byte) : IntegerValueConstant<Byte>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitByteValue(this, data)
override fun toString(): String = "$value.toByte()"
}
class CharValue(value: Char) : IntegerValueConstant<Char>(value) {
internal class CharValue(value: Char) : IntegerValueConstant<Char>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitCharValue(this, data)
override fun toString(): String = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value))
@@ -77,19 +77,19 @@ class CharValue(value: Char) : IntegerValueConstant<Char>(value) {
}
}
class DoubleValue(value: Double) : ConstantValue<Double>(value) {
internal class DoubleValue(value: Double) : ConstantValue<Double>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitDoubleValue(this, data)
override fun toString(): String = "$value.toDouble()"
}
class EnumValue(val enumClassId: ClassId, val enumEntryName: Name) : ConstantValue<Pair<ClassId, Name>>(enumClassId to enumEntryName) {
internal class EnumValue(val enumClassId: ClassId, val enumEntryName: Name) : ConstantValue<Pair<ClassId, Name>>(enumClassId to enumEntryName) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitEnumValue(this, data)
override fun toString(): String = "${enumClassId.shortClassName}.$enumEntryName"
}
abstract class ErrorValue : ConstantValue<Unit>(Unit) {
internal abstract class ErrorValue : ConstantValue<Unit>(Unit) {
@Deprecated("Should not be called, for this is not a real value, but a indication of an error", level = DeprecationLevel.HIDDEN)
override val value: Unit
get() = throw UnsupportedOperationException()
@@ -107,17 +107,17 @@ abstract class ErrorValue : ConstantValue<Unit>(Unit) {
}
}
class FloatValue(value: Float) : ConstantValue<Float>(value) {
internal class FloatValue(value: Float) : ConstantValue<Float>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitFloatValue(this, data)
override fun toString(): String = "$value.toFloat()"
}
class IntValue(value: Int) : IntegerValueConstant<Int>(value) {
internal class IntValue(value: Int) : IntegerValueConstant<Int>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitIntValue(this, data)
}
class KClassValue(value: Value) : ConstantValue<KClassValue.Value>(value) {
internal class KClassValue(value: Value) : ConstantValue<KClassValue.Value>(value) {
sealed class Value {
data class NormalClass(val value: ClassLiteralValue) : Value() {
val classId: ClassId get() = value.classId
@@ -164,29 +164,29 @@ class KClassValue(value: Value) : ConstantValue<KClassValue.Value>(value) {
}
}
class LongValue(value: Long) : IntegerValueConstant<Long>(value) {
internal class LongValue(value: Long) : IntegerValueConstant<Long>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitLongValue(this, data)
override fun toString(): String = "$value.toLong()"
}
object NullValue : ConstantValue<Nothing?>(null) {
internal object NullValue : ConstantValue<Nothing?>(null) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitNullValue(this, data)
}
class ShortValue(value: Short) : IntegerValueConstant<Short>(value) {
internal class ShortValue(value: Short) : IntegerValueConstant<Short>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitShortValue(this, data)
override fun toString(): String = "$value.toShort()"
}
class StringValue(value: String) : ConstantValue<String>(value) {
internal class StringValue(value: String) : ConstantValue<String>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitStringValue(this, data)
override fun toString(): String = "\"$value\""
}
class UByteValue(byteValue: Byte) : UnsignedValueConstant<Byte>(byteValue) {
internal class UByteValue(byteValue: Byte) : UnsignedValueConstant<Byte>(byteValue) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitUByteValue(this, data)
override fun toString(): String = "$value.toUByte()"
@@ -194,7 +194,7 @@ class UByteValue(byteValue: Byte) : UnsignedValueConstant<Byte>(byteValue) {
override fun stringTemplateValue(): String = (value.toInt() and 0xFF).toString()
}
class UShortValue(shortValue: Short) : UnsignedValueConstant<Short>(shortValue) {
internal class UShortValue(shortValue: Short) : UnsignedValueConstant<Short>(shortValue) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitUShortValue(this, data)
override fun toString(): String = "$value.toUShort()"
@@ -202,7 +202,7 @@ class UShortValue(shortValue: Short) : UnsignedValueConstant<Short>(shortValue)
override fun stringTemplateValue(): String = (value.toInt() and 0xFFFF).toString()
}
class UIntValue(intValue: Int) : UnsignedValueConstant<Int>(intValue) {
internal class UIntValue(intValue: Int) : UnsignedValueConstant<Int>(intValue) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitUIntValue(this, data)
override fun toString(): String = "$value.toUInt()"
@@ -210,7 +210,7 @@ class UIntValue(intValue: Int) : UnsignedValueConstant<Int>(intValue) {
override fun stringTemplateValue(): String = (value.toLong() and 0xFFFFFFFFL).toString()
}
class ULongValue(longValue: Long) : UnsignedValueConstant<Long>(longValue) {
internal class ULongValue(longValue: Long) : UnsignedValueConstant<Long>(longValue) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitULongValue(this, data)
override fun toString(): String = "$value.toULong()"
@@ -13,9 +13,9 @@ import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
fun FirExpression.toConstantValue(): ConstantValue<*>? = accept(FirToConstantValueTransformer, null)
internal fun FirExpression.toConstantValue(): ConstantValue<*>? = accept(FirToConstantValueTransformer, null)
object FirToConstantValueTransformer : FirDefaultVisitor<ConstantValue<*>?, Nothing?>() {
internal object FirToConstantValueTransformer : FirDefaultVisitor<ConstantValue<*>?, Nothing?>() {
override fun visitElement(
element: FirElement,
data: Nothing?