From 0d6555cc63adaf29a87a6a5be066247cb1112b9c Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 27 Nov 2014 19:42:02 +0300 Subject: [PATCH] Prettify code in BinaryClassAnnotationAndConstantLoaderImpl --- ...aryClassAnnotationAndConstantLoaderImpl.kt | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt index 0e93275a843..07c12925ad3 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt @@ -49,28 +49,19 @@ public class BinaryClassAnnotationAndConstantLoaderImpl( storageManager, kotlinClassFinder, errorReporter ) { - override fun loadConstant(desc: String, initializer: Any): CompileTimeConstant? { - val normalizedValue: Any - if (desc in "ZBCS") { + override fun loadConstant(desc: String, initializer: Any): CompileTimeConstant<*>? { + val normalizedValue: Any = if (desc in "ZBCS") { val intValue = initializer as Int - if ("Z" == desc) { - normalizedValue = intValue != 0 - } - else if ("B" == desc) { - normalizedValue = (intValue.toByte()) - } - else if ("C" == desc) { - normalizedValue = (intValue.toChar()) - } - else if ("S" == desc) { - normalizedValue = (intValue.toShort()) - } - else { - throw AssertionError(desc) + when (desc) { + "Z" -> intValue != 0 + "B" -> intValue.toByte() + "C" -> intValue.toChar() + "S" -> intValue.toShort() + else -> throw AssertionError(desc) } } else { - normalizedValue = initializer + initializer } val compileTimeConstant = createCompileTimeConstant( @@ -140,7 +131,8 @@ public class BinaryClassAnnotationAndConstantLoaderImpl( } private fun createConstant(name: Name?, value: Any?): CompileTimeConstant<*> { - return createCompileTimeConstant(value, true, false, false, null) + return createCompileTimeConstant(value, canBeUsedInAnnotation = true, isPureIntConstant = false, + usesVariableAsConstant = false, expectedType = null) ?: ErrorValue.create("Unsupported annotation argument: $name") }