From ae88dd3f1f836dfe70b6cd6d046e6619bb0b825b Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 2 Jul 2015 19:58:08 +0300 Subject: [PATCH] Convert compile constant classes to kotlin: prettify --- .../evaluate/ConstantExpressionEvaluator.kt | 2 +- .../LazyJavaAnnotationDescriptor.kt | 2 +- .../resolve/constants/AnnotationValue.kt | 12 +--- .../kotlin/resolve/constants/ArrayValue.kt | 56 ++++++------------- .../kotlin/resolve/constants/BooleanValue.kt | 19 +++---- .../kotlin/resolve/constants/ByteValue.kt | 19 +++---- .../kotlin/resolve/constants/CharValue.kt | 15 ++--- .../resolve/constants/CompileTimeConstant.kt | 2 + .../kotlin/resolve/constants/ConstantUtils.kt | 2 +- .../kotlin/resolve/constants/DoubleValue.kt | 18 +++--- .../kotlin/resolve/constants/EnumValue.kt | 44 ++++++--------- .../kotlin/resolve/constants/ErrorValue.kt | 19 ++----- .../kotlin/resolve/constants/FloatValue.kt | 18 +++--- .../kotlin/resolve/constants/IntValue.kt | 43 ++++++-------- .../resolve/constants/IntegerValueConstant.kt | 7 ++- .../constants/IntegerValueTypeConstant.kt | 29 +++++----- .../constants/IntegerValueTypeConstructor.kt | 39 ++++--------- .../kotlin/resolve/constants/LongValue.kt | 19 +++---- .../kotlin/resolve/constants/NullValue.kt | 18 ++---- .../kotlin/resolve/constants/ShortValue.kt | 20 +++---- .../kotlin/resolve/constants/StringValue.kt | 42 ++++++-------- 21 files changed, 175 insertions(+), 270 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt index 0b947d2ade8..de81d30ac63 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt @@ -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) diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt index 09027521512..38b0a20fcbf 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt @@ -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() }) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/AnnotationValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/AnnotationValue.kt index f56c108ba1d..0fcc18648ed 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/AnnotationValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/AnnotationValue.kt @@ -22,15 +22,9 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.types.JetType public class AnnotationValue(value: AnnotationDescriptor) : CompileTimeConstant(value, true, false, false) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return value.getType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = value.getType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitAnnotationValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitAnnotationValue(this, data) - override fun toString(): String { - return value.toString() - } + override fun toString() = value.toString() } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.kt index fe16daf7fc9..44ee6d3f965 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.kt @@ -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>, private val type: JetType, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant>>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { +public class ArrayValue( + value: List>, + private val type: JetType, + canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean +) : 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 accept(visitor: AnnotationArgumentVisitor, 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 accept(visitor: AnnotationArgumentVisitor, 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() } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/BooleanValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/BooleanValue.kt index 410b580b059..aa691a535f5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/BooleanValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/BooleanValue.kt @@ -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(value, canBeUseInAnnotation, false, usesVariableAsConstant) { +public class BooleanValue( + value: Boolean, + canBeUseInAnnotation: Boolean, + usesVariableAsConstant: Boolean +) : CompileTimeConstant(value, canBeUseInAnnotation, false, usesVariableAsConstant) { + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getBooleanType() - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getBooleanType() - } - - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitBooleanValue(this, data) - } - - override fun toString(): String { - return "$value" - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitBooleanValue(this, data) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ByteValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ByteValue.kt index 7cb040452bb..973ec0af255 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ByteValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ByteValue.kt @@ -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(value, canBeUsedInAnnotations, pure, usesVaraiableAsConstant) { +public class ByteValue( + value: Byte, + canBeUsedInAnnotations: Boolean, + pure: Boolean, + usesVaraiableAsConstant: Boolean +) : IntegerValueConstant(value, canBeUsedInAnnotations, pure, usesVaraiableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getByteType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getByteType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitByteValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitByteValue(this, data) - override fun toString(): String { - return "$value.toByte()" - } + override fun toString(): String = "$value.toByte()" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CharValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CharValue.kt index 9bdf3e62a7d..fb9a93adda1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CharValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CharValue.kt @@ -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(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { +public class CharValue( + value: Char, + canBeUsedInAnnotations: Boolean, + pure: Boolean, + usesVariableAsConstant: Boolean +) : IntegerValueConstant(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getCharType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getCharType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitCharValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitCharValue(this, data) override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value)) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt index 05732ace9fa..d7c8c477387 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CompileTimeConstant.kt @@ -43,6 +43,8 @@ public abstract class CompileTimeConstant protected constructor(public open v public abstract fun accept(visitor: AnnotationArgumentVisitor, data: D): R + override fun toString() = value.toString() + companion object { /* diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt index 0dff6a49e5f..a82205ecf24 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt @@ -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 } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/DoubleValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/DoubleValue.kt index 3cc03222e55..351861c4c86 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/DoubleValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/DoubleValue.kt @@ -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(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { +public class DoubleValue( + value: Double, + canBeUsedInAnnotations: Boolean, + usesVariableAsConstant: Boolean +) : CompileTimeConstant(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getDoubleType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getDoubleType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitDoubleValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitDoubleValue(this, data) - override fun toString(): String { - return "$value.toDouble()" - } + override fun toString() = "$value.toDouble()" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.kt index ccca617b354..2afd293da3c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.kt @@ -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(value, true, false, usesVariableAsConstant) { +public class EnumValue( + value: ClassDescriptor, + usesVariableAsConstant: Boolean +) : CompileTimeConstant(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 accept(visitor: AnnotationArgumentVisitor, 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 accept(visitor: AnnotationArgumentVisitor, 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() } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ErrorValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ErrorValue.kt index 5d0444504e7..74164f3019d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ErrorValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ErrorValue.kt @@ -23,29 +23,20 @@ import org.jetbrains.kotlin.types.JetType public abstract class ErrorValue : CompileTimeConstant(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 accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitErrorValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, 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) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/FloatValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/FloatValue.kt index 7da1f85633d..ba1e4f037c6 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/FloatValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/FloatValue.kt @@ -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(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { +public class FloatValue( + value: Float, + canBeUsedInAnnotations: Boolean, + usesVariableAsConstant: Boolean +) : CompileTimeConstant(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getFloatType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getFloatType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitFloatValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitFloatValue(this, data) - override fun toString(): String { - return "$value.toFloat()" - } + override fun toString() = "$value.toFloat()" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntValue.kt index 5e2ca89cafe..bb3333e70de 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntValue.kt @@ -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(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { +public class IntValue( + value: Int, + canBeUsedInAnnotations: Boolean, + pure: Boolean, + usesVariableAsConstant: Boolean +) : IntegerValueConstant(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getIntType() + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getIntType() + + override fun accept(visitor: AnnotationArgumentVisitor, 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 accept(visitor: AnnotationArgumentVisitor, 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 } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueConstant.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueConstant.kt index 220a174d3ab..3c71270741f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueConstant.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueConstant.kt @@ -16,4 +16,9 @@ package org.jetbrains.kotlin.resolve.constants -public abstract class IntegerValueConstant protected constructor(value: T, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) +public abstract class IntegerValueConstant protected constructor( + value: T, + canBeUsedInAnnotations: Boolean, + pure: Boolean, + usesVariableAsConstant: Boolean +) : CompileTimeConstant(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstant.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstant.kt index 04778e7a327..65744390727 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstant.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstant.kt @@ -23,25 +23,26 @@ import org.jetbrains.kotlin.types.* import java.util.Collections -public class IntegerValueTypeConstant(value: Number, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant(value, canBeUsedInAnnotations, true, usesVariableAsConstant) { +public class IntegerValueTypeConstant( + value: Number, + canBeUsedInAnnotations: Boolean, + usesVariableAsConstant: Boolean +) : IntegerValueConstant(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(), ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)) + return JetTypeImpl( + Annotations.EMPTY, typeConstructor, false, emptyList() + , 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 accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitNumberTypeValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitNumberTypeValue(this, data) - override fun toString(): String { - return typeConstructor.toString() - } + override fun toString() = typeConstructor.toString() } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt index 93a736afdb4..92e9458bc7b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt @@ -30,13 +30,14 @@ public class IntegerValueTypeConstructor(private val value: Long) : TypeConstruc private val supertypes = ArrayList(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 { - return supertypes - } + override fun getSupertypes(): Collection = supertypes - override fun getParameters(): List { - return emptyList() - } + override fun getParameters(): List = 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 + ")" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/LongValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/LongValue.kt index b0f803bf7e2..c442492f435 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/LongValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/LongValue.kt @@ -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(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { +public class LongValue( + value: Long, + canBeUsedInAnnotations: Boolean, + pure: Boolean, + usesVariableAsConstant: Boolean +) : IntegerValueConstant(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getLongType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getLongType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitLongValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitLongValue(this, data) - override fun toString(): String { - return "$value.toLong()" - } + override fun toString() = "$value.toLong()" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.kt index 35fccaf9a49..8c28e6ca910 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.kt @@ -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(null, false, false, false) { +public object NullValue : CompileTimeConstant(null, false, false, false) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getNullableNothingType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getNullableNothingType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitNullValue(this, data) - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitNullValue(this, data) - override fun toString(): String { - return "null" - } - - companion object { - public val NULL: NullValue = NullValue() - } + override fun toString() = "null" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ShortValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ShortValue.kt index 45294ca2d27..f1d71050be2 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ShortValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ShortValue.kt @@ -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(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { +public class ShortValue( + value: Short, + canBeUsedInAnnotations: Boolean, + pure: Boolean, + usesVariableAsConstant: Boolean +) : IntegerValueConstant(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getShortType() - } + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getShortType() - override fun accept(visitor: AnnotationArgumentVisitor, data: D): R { - return visitor.visitShortValue(this, data) - } - - override fun toString(): String { - return "$value.toShort()" - } + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitShortValue(this, data) + override fun toString() = "$value.toShort()" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/StringValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/StringValue.kt index e1cb3feac4f..f8467927cd8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/StringValue.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/StringValue.kt @@ -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(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { +public class StringValue( + value: String, + canBeUsedInAnnotations: Boolean, + usesVariableAsConstant: Boolean +) : CompileTimeConstant(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { - override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType { - return kotlinBuiltIns.getStringType() + override fun getType(kotlinBuiltIns: KotlinBuiltIns) = kotlinBuiltIns.getStringType() + + override fun accept(visitor: AnnotationArgumentVisitor, 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 accept(visitor: AnnotationArgumentVisitor, 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() }