Convert compile constant classes to kotlin: prettify
This commit is contained in:
+1
-1
@@ -106,7 +106,7 @@ public class ConstantExpressionEvaluator private constructor(val trace: BindingT
|
|||||||
if (text == null) return null
|
if (text == null) return null
|
||||||
|
|
||||||
val nodeElementType = expression.getNode().getElementType()
|
val nodeElementType = expression.getNode().getElementType()
|
||||||
if (nodeElementType == JetNodeTypes.NULL) return NullValue.NULL
|
if (nodeElementType == JetNodeTypes.NULL) return NullValue
|
||||||
|
|
||||||
val result: Any? = when (nodeElementType) {
|
val result: Any? = when (nodeElementType) {
|
||||||
JetNodeTypes.INTEGER_CONSTANT -> parseLong(text)
|
JetNodeTypes.INTEGER_CONSTANT -> parseLong(text)
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@ class LazyJavaAnnotationDescriptor(
|
|||||||
if (valueParameter == null) return null
|
if (valueParameter == null) return null
|
||||||
|
|
||||||
val values = elements.map {
|
val values = elements.map {
|
||||||
argument -> resolveAnnotationArgument(argument) ?: NullValue.NULL
|
argument -> resolveAnnotationArgument(argument) ?: NullValue
|
||||||
}
|
}
|
||||||
return ArrayValue(values, valueParameter.getType(), true, values.any { it.usesVariableAsConstant() })
|
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
|
import org.jetbrains.kotlin.types.JetType
|
||||||
|
|
||||||
public class AnnotationValue(value: AnnotationDescriptor) : CompileTimeConstant<AnnotationDescriptor>(value, true, false, false) {
|
public class AnnotationValue(value: AnnotationDescriptor) : CompileTimeConstant<AnnotationDescriptor>(value, true, false, false) {
|
||||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = value.getType()
|
||||||
return value.getType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitAnnotationValue(this, data)
|
||||||
return visitor.visitAnnotationValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = value.toString()
|
||||||
return value.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,53 +19,29 @@ package org.jetbrains.kotlin.resolve.constants
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
init {
|
||||||
assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value }
|
assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = type
|
||||||
return 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 {
|
override fun hashCode() = value.hashCode()
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,17 +20,12 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitBooleanValue(this, data)
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getByteType()
|
||||||
return kotlinBuiltIns.getByteType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitByteValue(this, data)
|
||||||
return visitor.visitByteValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String = "$value.toByte()"
|
||||||
return "$value.toByte()"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getCharType()
|
||||||
return kotlinBuiltIns.getCharType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitCharValue(this, data)
|
||||||
return visitor.visitCharValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value))
|
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
|
public abstract fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R
|
||||||
|
|
||||||
|
override fun toString() = value.toString()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public fun createCompileTimeConstant(
|
|||||||
is Double -> DoubleValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
|
is Double -> DoubleValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
|
||||||
is Boolean -> BooleanValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
|
is Boolean -> BooleanValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
|
||||||
is String -> StringValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
|
is String -> StringValue(value, canBeUsedInAnnotation, usesVariableAsConstant)
|
||||||
null -> NullValue.NULL
|
null -> NullValue
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,15 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getDoubleType()
|
||||||
return kotlinBuiltIns.getDoubleType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitDoubleValue(this, data)
|
||||||
return visitor.visitDoubleValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = "$value.toDouble()"
|
||||||
return "$value.toDouble()"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,34 +23,26 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.classObjectType
|
|||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.utils.sure
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = getType()
|
||||||
return 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 {
|
override fun hashCode() = value.hashCode()
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,29 +23,20 @@ import org.jetbrains.kotlin.types.JetType
|
|||||||
|
|
||||||
public abstract class ErrorValue : CompileTimeConstant<Unit>(Unit, true, false, false) {
|
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
|
override val value: Unit
|
||||||
get() {
|
get() = throw UnsupportedOperationException()
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitErrorValue(this, data)
|
||||||
return visitor.visitErrorValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ErrorValueWithMessage(public val message: String) : ErrorValue() {
|
public class ErrorValueWithMessage(public val message: String) : ErrorValue() {
|
||||||
|
|
||||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = ErrorUtils.createErrorType(message)
|
||||||
return ErrorUtils.createErrorType(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = message
|
||||||
return message
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
public fun create(message: String): ErrorValue {
|
public fun create(message: String): ErrorValue {
|
||||||
return ErrorValueWithMessage(message)
|
return ErrorValueWithMessage(message)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,15 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getFloatType()
|
||||||
return kotlinBuiltIns.getFloatType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitFloatValue(this, data)
|
||||||
return visitor.visitFloatValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = "$value.toFloat()"
|
||||||
return "$value.toFloat()"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,32 +20,25 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getIntType()
|
||||||
return 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 {
|
override fun hashCode() = value
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,4 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.constants
|
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)
|
||||||
|
|||||||
+13
-16
@@ -23,25 +23,26 @@ import org.jetbrains.kotlin.types.*
|
|||||||
|
|
||||||
import java.util.Collections
|
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
|
private val typeConstructor = IntegerValueTypeConstructor(value.toLong())
|
||||||
|
|
||||||
init {
|
|
||||||
this.typeConstructor = IntegerValueTypeConstructor(value.toLong())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
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("")
|
deprecated("")
|
||||||
override val value: Number
|
override val value: Number
|
||||||
get() = throw UnsupportedOperationException("Use IntegerValueTypeConstant.getValue(expectedType) instead")
|
get() = throw UnsupportedOperationException("Use IntegerValueTypeConstant.getValue(expectedType) instead")
|
||||||
|
|
||||||
public fun getType(expectedType: JetType): JetType {
|
public fun getType(expectedType: JetType): JetType = TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType)
|
||||||
return TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType)
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getValue(expectedType: JetType): Number {
|
public fun getValue(expectedType: JetType): Number {
|
||||||
val numberValue = typeConstructor.getValue()
|
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 {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitNumberTypeValue(this, data)
|
||||||
return visitor.visitNumberTypeValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = typeConstructor.toString()
|
||||||
return typeConstructor.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-27
@@ -30,13 +30,14 @@ public class IntegerValueTypeConstructor(private val value: Long) : TypeConstruc
|
|||||||
private val supertypes = ArrayList<JetType>(4)
|
private val supertypes = ArrayList<JetType>(4)
|
||||||
|
|
||||||
init {
|
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, 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.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())
|
checkBoundsAndAddSuperType(value, java.lang.Short.MIN_VALUE.toLong(), java.lang.Short.MAX_VALUE.toLong(), KotlinBuiltIns.getInstance().getShortType())
|
||||||
supertypes.add(KotlinBuiltIns.getInstance().getLongType())
|
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) {
|
private fun checkBoundsAndAddSuperType(value: Long, minValue: Long, maxValue: Long, kotlinType: JetType) {
|
||||||
if (value >= minValue && value <= maxValue) {
|
if (value >= minValue && value <= maxValue) {
|
||||||
@@ -44,35 +45,19 @@ public class IntegerValueTypeConstructor(private val value: Long) : TypeConstruc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSupertypes(): Collection<JetType> {
|
override fun getSupertypes(): Collection<JetType> = supertypes
|
||||||
return supertypes
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getParameters(): List<TypeParameterDescriptor> {
|
override fun getParameters(): List<TypeParameterDescriptor> = emptyList()
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isFinal(): Boolean {
|
override fun isFinal() = false
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isDenotable(): Boolean {
|
override fun isDenotable() = false
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getDeclarationDescriptor(): ClassifierDescriptor? {
|
override fun getDeclarationDescriptor() = null
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAnnotations(): Annotations {
|
override fun getAnnotations() = Annotations.EMPTY
|
||||||
return Annotations.EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getValue(): Long {
|
public fun getValue(): Long = value
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = "IntegerValueType(" + value + ")"
|
||||||
return "IntegerValueType(" + value + ")"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getLongType()
|
||||||
return kotlinBuiltIns.getLongType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitLongValue(this, data)
|
||||||
return visitor.visitLongValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = "$value.toLong()"
|
||||||
return "$value.toLong()"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,21 +20,11 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getNullableNothingType()
|
||||||
return kotlinBuiltIns.getNullableNothingType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitNullValue(this, data)
|
||||||
return visitor.visitNullValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = "null"
|
||||||
return "null"
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
public val NULL: NullValue = NullValue()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getShortType()
|
||||||
return kotlinBuiltIns.getShortType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitShortValue(this, data)
|
||||||
return visitor.visitShortValue(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return "$value.toShort()"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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.descriptors.annotations.AnnotationArgumentVisitor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
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 {
|
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getStringType()
|
||||||
return 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 {
|
override fun hashCode() = value.hashCode()
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user