ConstantExpressionEvaluator: avoid calling KotlinBuiltIns.getInstance()
This commit is contained in:
+19
-19
@@ -36,8 +36,7 @@ import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import java.math.BigInteger
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.*
|
||||
|
||||
public class ConstantExpressionEvaluator(
|
||||
internal val builtIns: KotlinBuiltIns
|
||||
@@ -656,6 +655,24 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
return createOperationArgument(argumentExpression, parameter.getType(), argumentCompileTimeType)
|
||||
}
|
||||
|
||||
|
||||
private fun getCompileTimeType(c: JetType): CompileTimeType<out Any>? {
|
||||
val builtIns = constantExpressionEvaluator.builtIns
|
||||
return when (TypeUtils.makeNotNullable(c)) {
|
||||
builtIns.intType -> INT
|
||||
builtIns.byteType -> BYTE
|
||||
builtIns.shortType -> SHORT
|
||||
builtIns.longType -> LONG
|
||||
builtIns.doubleType -> DOUBLE
|
||||
builtIns.floatType -> FLOAT
|
||||
builtIns.charType -> CHAR
|
||||
builtIns.booleanType -> BOOLEAN
|
||||
builtIns.stringType -> STRING
|
||||
builtIns.anyType -> ANY
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun createOperationArgument(expression: JetExpression, expressionType: JetType, compileTimeType: CompileTimeType<*>): OperationArgument? {
|
||||
val compileTimeConstant = constantExpressionEvaluator.evaluateExpression(expression, trace, expressionType) ?: return null
|
||||
val evaluationResult = compileTimeConstant.getValue(expressionType) ?: return null
|
||||
@@ -820,23 +837,6 @@ private fun getReceiverExpressionType(resolvedCall: ResolvedCall<*>): JetType? {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCompileTimeType(c: JetType): CompileTimeType<out Any>? {
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
return when (TypeUtils.makeNotNullable(c)) {
|
||||
builtIns.getIntType() -> INT
|
||||
builtIns.getByteType() -> BYTE
|
||||
builtIns.getShortType() -> SHORT
|
||||
builtIns.getLongType() -> LONG
|
||||
builtIns.getDoubleType() -> DOUBLE
|
||||
builtIns.getFloatType() -> FLOAT
|
||||
builtIns.getCharType() -> CHAR
|
||||
builtIns.getBooleanType() -> BOOLEAN
|
||||
builtIns.getStringType() -> STRING
|
||||
builtIns.getAnyType() -> ANY
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private class CompileTimeType<T>
|
||||
|
||||
internal val BYTE = CompileTimeType<Byte>()
|
||||
|
||||
Reference in New Issue
Block a user