Refactor: Pass buitlins into IntegerValueTypeConstant and IntegerValueTypeConstructor
This commit is contained in:
+1
-1
@@ -680,7 +680,7 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
expectedType: JetType
|
||||
): CompileTimeConstant<*>? {
|
||||
if (TypeUtils.noExpectedType(expectedType) || expectedType.isError()) {
|
||||
return IntegerValueTypeConstant(value, parameters)
|
||||
return IntegerValueTypeConstant(value, constantExpressionEvaluator.builtIns, parameters)
|
||||
}
|
||||
val integerValue = factory.createIntegerConstantValue(value, expectedType)
|
||||
if (integerValue != null) {
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import java.util.regex.Pattern
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor
|
||||
import org.jetbrains.kotlin.types.JetTypeImpl
|
||||
@@ -59,7 +60,7 @@ public class ConstraintSystemTestData(
|
||||
val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name)
|
||||
if (matcher.find()) {
|
||||
val number = matcher.group(1)!!
|
||||
return JetTypeImpl(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong()), false, listOf(), JetScope.Empty)
|
||||
return JetTypeImpl(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong(), KotlinBuiltIns.getInstance()), false, listOf(), JetScope.Empty)
|
||||
}
|
||||
return typeResolver.resolveType(
|
||||
scopeToResolveTypeParameters, JetPsiFactory(project).createType(name),
|
||||
|
||||
@@ -57,12 +57,13 @@ public class TypedCompileTimeConstant<out T>(
|
||||
|
||||
public class IntegerValueTypeConstant(
|
||||
private val value: Number,
|
||||
private val builtIns: KotlinBuiltIns,
|
||||
override val parameters: CompileTimeConstant.Parameters
|
||||
) : CompileTimeConstant<Number> {
|
||||
private val typeConstructor = IntegerValueTypeConstructor(value.toLong())
|
||||
private val typeConstructor = IntegerValueTypeConstructor(value.toLong(), builtIns)
|
||||
|
||||
override fun toConstantValue(expectedType: JetType): ConstantValue<Number> {
|
||||
val factory = ConstantValueFactory(KotlinBuiltIns.getInstance())
|
||||
val factory = ConstantValueFactory(builtIns)
|
||||
val type = getType(expectedType)
|
||||
return when {
|
||||
KotlinBuiltIns.isInt(type) -> {
|
||||
|
||||
+8
-5
@@ -26,17 +26,20 @@ import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import java.util.ArrayList
|
||||
import java.util.Collections
|
||||
|
||||
public class IntegerValueTypeConstructor(private val value: Long) : TypeConstructor {
|
||||
public class IntegerValueTypeConstructor(
|
||||
private val value: Long,
|
||||
private val builtIns: KotlinBuiltIns
|
||||
) : TypeConstructor {
|
||||
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())
|
||||
checkBoundsAndAddSuperType(value, Integer.MIN_VALUE.toLong(), Integer.MAX_VALUE.toLong(), builtIns.getIntType())
|
||||
checkBoundsAndAddSuperType(value, java.lang.Byte.MIN_VALUE.toLong(), java.lang.Byte.MAX_VALUE.toLong(), builtIns.getByteType())
|
||||
checkBoundsAndAddSuperType(value, java.lang.Short.MIN_VALUE.toLong(), java.lang.Short.MAX_VALUE.toLong(), builtIns.getShortType())
|
||||
supertypes.add(builtIns.getLongType())
|
||||
}
|
||||
|
||||
private fun checkBoundsAndAddSuperType(value: Long, minValue: Long, maxValue: Long, kotlinType: JetType) {
|
||||
|
||||
Reference in New Issue
Block a user