Convert compile constant classes to kotlin: prettify

This commit is contained in:
Pavel V. Talanov
2015-07-02 19:58:08 +03:00
parent 0369de86c7
commit ae88dd3f1f
21 changed files with 175 additions and 270 deletions
@@ -106,7 +106,7 @@ public class ConstantExpressionEvaluator private constructor(val trace: BindingT
if (text == null) return null
val nodeElementType = expression.getNode().getElementType()
if (nodeElementType == JetNodeTypes.NULL) return NullValue.NULL
if (nodeElementType == JetNodeTypes.NULL) return NullValue
val result: Any? = when (nodeElementType) {
JetNodeTypes.INTEGER_CONSTANT -> parseLong(text)
@@ -123,7 +123,7 @@ class LazyJavaAnnotationDescriptor(
if (valueParameter == null) return null
val values = elements.map {
argument -> resolveAnnotationArgument(argument) ?: NullValue.NULL
argument -> resolveAnnotationArgument(argument) ?: NullValue
}
return ArrayValue(values, valueParameter.getType(), true, values.any { it.usesVariableAsConstant() })
}
@@ -22,15 +22,9 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.types.JetType
public class AnnotationValue(value: AnnotationDescriptor) : CompileTimeConstant<AnnotationDescriptor>(value, true, false, false) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return value.getType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = value.getType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitAnnotationValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitAnnotationValue(this, data)
override fun toString(): String {
return value.toString()
}
override fun toString() = value.toString()
}
@@ -19,53 +19,29 @@ package org.jetbrains.kotlin.resolve.constants
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
import java.util.*
public class ArrayValue(value: List<CompileTimeConstant<*>>, private val type: JetType, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<List<CompileTimeConstant<*>>>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
public class ArrayValue(
value: List<CompileTimeConstant<*>>,
private val type: JetType,
canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean
) : CompileTimeConstant<List<CompileTimeConstant<*>>>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
init {
assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value }
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return type
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 {
if (this === other) return true
if (javaClass != other?.javaClass) return false
return value == (other as ArrayValue).value
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitArrayValue(this, data)
}
override fun toString(): String {
return value.toString()
}
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
val that = o as? ArrayValue ?: return false
if (value == null) {
return that.value == null
}
var i = 0
for (thisObject in value) {
if (thisObject != that.value.get(i)) {
return false
}
i++
}
return true
}
override fun hashCode(): Int {
var hashCode = 0
if (value == null) return hashCode
for (o in value) {
hashCode += o.hashCode()
}
return hashCode
}
override fun hashCode() = value.hashCode()
}
@@ -20,17 +20,12 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class BooleanValue(value: Boolean, canBeUseInAnnotation: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<Boolean>(value, canBeUseInAnnotation, false, usesVariableAsConstant) {
public class BooleanValue(
value: Boolean,
canBeUseInAnnotation: Boolean,
usesVariableAsConstant: Boolean
) : CompileTimeConstant<Boolean>(value, canBeUseInAnnotation, false, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getBooleanType()
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getBooleanType()
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitBooleanValue(this, data)
}
override fun toString(): String {
return "$value"
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitBooleanValue(this, data)
}
@@ -20,17 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class ByteValue(value: Byte, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVaraiableAsConstant: Boolean) : IntegerValueConstant<Byte>(value, canBeUsedInAnnotations, pure, usesVaraiableAsConstant) {
public class ByteValue(
value: Byte,
canBeUsedInAnnotations: Boolean,
pure: Boolean,
usesVaraiableAsConstant: Boolean
) : IntegerValueConstant<Byte>(value, canBeUsedInAnnotations, pure, usesVaraiableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getByteType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getByteType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitByteValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitByteValue(this, data)
override fun toString(): String {
return "$value.toByte()"
}
override fun toString(): String = "$value.toByte()"
}
@@ -20,15 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class CharValue(value: Char, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Char>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
public class CharValue(
value: Char,
canBeUsedInAnnotations: Boolean,
pure: Boolean,
usesVariableAsConstant: Boolean
) : IntegerValueConstant<Char>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getCharType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getCharType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitCharValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitCharValue(this, data)
override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value))
@@ -43,6 +43,8 @@ public abstract class CompileTimeConstant<T> protected constructor(public open v
public abstract fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R
override fun toString() = value.toString()
companion object {
/*
@@ -43,7 +43,7 @@ public fun createCompileTimeConstant(
is Double -> DoubleValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
is Boolean -> BooleanValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
is String -> StringValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
null -> NullValue.NULL
null -> NullValue
else -> null
}
}
@@ -20,17 +20,15 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class DoubleValue(value: Double, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<Double>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
public class DoubleValue(
value: Double,
canBeUsedInAnnotations: Boolean,
usesVariableAsConstant: Boolean
) : CompileTimeConstant<Double>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getDoubleType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getDoubleType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitDoubleValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitDoubleValue(this, data)
override fun toString(): String {
return "$value.toDouble()"
}
override fun toString() = "$value.toDouble()"
}
@@ -23,34 +23,26 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.classObjectType
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.sure
public class EnumValue(value: ClassDescriptor, usesVariableAsConstant: Boolean) : CompileTimeConstant<ClassDescriptor>(value, true, false, usesVariableAsConstant) {
public class EnumValue(
value: ClassDescriptor,
usesVariableAsConstant: Boolean
) : CompileTimeConstant<ClassDescriptor>(value, true, false, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return getType()
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = getType()
private fun getType() = 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 equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
return value == (other as EnumValue).value
}
private fun getType(): JetType {
val type = value.classObjectType
return type.sure { "Enum entry must have a class object type: " + value }
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitEnumValue(this, data)
}
override fun toString(): String {
return "${getType()}.${value.getName()}"
}
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
return value == (o as? EnumValue)?.value
}
override fun hashCode(): Int {
return value.hashCode()
}
override fun hashCode() = value.hashCode()
}
@@ -23,29 +23,20 @@ import org.jetbrains.kotlin.types.JetType
public abstract class ErrorValue : CompileTimeConstant<Unit>(Unit, true, false, false) {
deprecated("") // Should not be called, for this is not a real value, but a indication of an error
deprecated("Should not be called, for this is not a real value, but a indication of an error")
override val value: Unit
get() {
throw UnsupportedOperationException()
}
get() = throw UnsupportedOperationException()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitErrorValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitErrorValue(this, data)
public class ErrorValueWithMessage(public val message: String) : ErrorValue() {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return ErrorUtils.createErrorType(message)
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = ErrorUtils.createErrorType(message)
override fun toString(): String {
return message
}
override fun toString() = message
}
companion object {
public fun create(message: String): ErrorValue {
return ErrorValueWithMessage(message)
}
@@ -20,17 +20,15 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class FloatValue(value: Float, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<Float>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
public class FloatValue(
value: Float,
canBeUsedInAnnotations: Boolean,
usesVariableAsConstant: Boolean
) : CompileTimeConstant<Float>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getFloatType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getFloatType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitFloatValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitFloatValue(this, data)
override fun toString(): String {
return "$value.toFloat()"
}
override fun toString() = "$value.toFloat()"
}
@@ -20,32 +20,25 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class IntValue(value: Int, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Int>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
public class IntValue(
value: Int,
canBeUsedInAnnotations: Boolean,
pure: Boolean,
usesVariableAsConstant: Boolean
) : IntegerValueConstant<Int>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getIntType()
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getIntType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitIntValue(this, data)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
val intValue = other as IntValue
return value == intValue.value
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitIntValue(this, data)
}
override fun toString(): String {
return value.toString()
}
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
val intValue = o as? IntValue ?: return false
if (value !== intValue.value) return false
return true
}
override fun hashCode(): Int {
return value
}
override fun hashCode() = value
}
@@ -16,4 +16,9 @@
package org.jetbrains.kotlin.resolve.constants
public abstract class IntegerValueConstant<T> protected constructor(value: T, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<T>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant)
public abstract class IntegerValueConstant<T> protected constructor(
value: T,
canBeUsedInAnnotations: Boolean,
pure: Boolean,
usesVariableAsConstant: Boolean
) : CompileTimeConstant<T>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant)
@@ -23,25 +23,26 @@ import org.jetbrains.kotlin.types.*
import java.util.Collections
public class IntegerValueTypeConstant(value: Number, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Number>(value, canBeUsedInAnnotations, true, usesVariableAsConstant) {
public class IntegerValueTypeConstant(
value: Number,
canBeUsedInAnnotations: Boolean,
usesVariableAsConstant: Boolean
) : IntegerValueConstant<Number>(value, canBeUsedInAnnotations, true, usesVariableAsConstant) {
private val typeConstructor: IntegerValueTypeConstructor
init {
this.typeConstructor = IntegerValueTypeConstructor(value.toLong())
}
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))
return JetTypeImpl(
Annotations.EMPTY, typeConstructor, false, emptyList<TypeProjection>()
, ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)
)
}
deprecated("")
override val value: Number
get() = throw UnsupportedOperationException("Use IntegerValueTypeConstant.getValue(expectedType) instead")
public fun getType(expectedType: JetType): JetType {
return TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType)
}
public fun getType(expectedType: JetType): JetType = TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType)
public fun getValue(expectedType: JetType): Number {
val numberValue = typeConstructor.getValue()
@@ -62,11 +63,7 @@ public class IntegerValueTypeConstant(value: Number, canBeUsedInAnnotations: Boo
}
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitNumberTypeValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitNumberTypeValue(this, data)
override fun toString(): String {
return typeConstructor.toString()
}
override fun toString() = typeConstructor.toString()
}
@@ -30,13 +30,14 @@ public class IntegerValueTypeConstructor(private val value: Long) : TypeConstruc
private val supertypes = ArrayList<JetType>(4)
init {
// order of types matters
// 'getPrimitiveNumberType' returns first of supertypes that is a subtype of expected type
// for expected type 'Any' result type 'Int' should be returned
checkBoundsAndAddSuperType(value, Integer.MIN_VALUE.toLong(), Integer.MAX_VALUE.toLong(), KotlinBuiltIns.getInstance().getIntType())
checkBoundsAndAddSuperType(value, java.lang.Byte.MIN_VALUE.toLong(), java.lang.Byte.MAX_VALUE.toLong(), KotlinBuiltIns.getInstance().getByteType())
checkBoundsAndAddSuperType(value, java.lang.Short.MIN_VALUE.toLong(), java.lang.Short.MAX_VALUE.toLong(), KotlinBuiltIns.getInstance().getShortType())
supertypes.add(KotlinBuiltIns.getInstance().getLongType())
}// order of types matters
// 'getPrimitiveNumberType' returns first of supertypes that is a subtype of expected type
// for expected type 'Any' result type 'Int' should be returned
}
private fun checkBoundsAndAddSuperType(value: Long, minValue: Long, maxValue: Long, kotlinType: JetType) {
if (value >= minValue && value <= maxValue) {
@@ -44,35 +45,19 @@ public class IntegerValueTypeConstructor(private val value: Long) : TypeConstruc
}
}
override fun getSupertypes(): Collection<JetType> {
return supertypes
}
override fun getSupertypes(): Collection<JetType> = supertypes
override fun getParameters(): List<TypeParameterDescriptor> {
return emptyList()
}
override fun getParameters(): List<TypeParameterDescriptor> = emptyList()
override fun isFinal(): Boolean {
return false
}
override fun isFinal() = false
override fun isDenotable(): Boolean {
return false
}
override fun isDenotable() = false
override fun getDeclarationDescriptor(): ClassifierDescriptor? {
return null
}
override fun getDeclarationDescriptor() = null
override fun getAnnotations(): Annotations {
return Annotations.EMPTY
}
override fun getAnnotations() = Annotations.EMPTY
public fun getValue(): Long {
return value
}
public fun getValue(): Long = value
override fun toString(): String {
return "IntegerValueType(" + value + ")"
}
override fun toString() = "IntegerValueType(" + value + ")"
}
@@ -20,17 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class LongValue(value: Long, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Long>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
public class LongValue(
value: Long,
canBeUsedInAnnotations: Boolean,
pure: Boolean,
usesVariableAsConstant: Boolean
) : IntegerValueConstant<Long>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getLongType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getLongType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitLongValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitLongValue(this, data)
override fun toString(): String {
return "$value.toLong()"
}
override fun toString() = "$value.toLong()"
}
@@ -20,21 +20,11 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class NullValue private constructor() : CompileTimeConstant<Void?>(null, false, false, false) {
public object NullValue : CompileTimeConstant<Void?>(null, false, false, false) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getNullableNothingType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getNullableNothingType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitNullValue(this, data)
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitNullValue(this, data)
override fun toString(): String {
return "null"
}
companion object {
public val NULL: NullValue = NullValue()
}
override fun toString() = "null"
}
@@ -20,18 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class ShortValue(value: Short, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Short>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
public class ShortValue(
value: Short,
canBeUsedInAnnotations: Boolean,
pure: Boolean,
usesVariableAsConstant: Boolean
) : IntegerValueConstant<Short>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getShortType()
}
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getShortType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitShortValue(this, data)
}
override fun toString(): String {
return "$value.toShort()"
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitShortValue(this, data)
override fun toString() = "$value.toShort()"
}
@@ -20,32 +20,24 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.types.JetType
public class StringValue(value: String, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<String>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
public class StringValue(
value: String,
canBeUsedInAnnotations: Boolean,
usesVariableAsConstant: Boolean
) : CompileTimeConstant<String>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
return kotlinBuiltIns.getStringType()
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getStringType()
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitStringValue(this, data)
override fun toString() = "\"$value\""
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false
return value != (other as StringValue).value
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
return visitor.visitStringValue(this, data)
}
override fun toString(): String {
return "\"" + value + "\""
}
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
val that = o as? StringValue ?: return false
if (if (value != null) value != that.value else that.value != null) return false
return true
}
override fun hashCode(): Int {
return if (value != null) value.hashCode() else 0
}
override fun hashCode() = value.hashCode()
}