Migrate deprecations in core, compiler, idea, tests

Replacing deprecated Char.toInt() with Char.code and
Number.toChar() with Number.toInt().toChar(), where Number is not Int.

KT-23451
This commit is contained in:
Ilya Gorbunov
2021-04-06 18:58:25 +03:00
parent b64b96eee6
commit e450a6494a
30 changed files with 35 additions and 34 deletions
@@ -18,7 +18,7 @@ fun mangleNameIfNeeded(name: String): String {
if (c.isValidCharacter()) {
append(c)
} else {
val hexString = Integer.toHexString(c.toInt())
val hexString = Integer.toHexString(c.code)
assert(hexString.length <= 4)
append("_u").append(hexString)
}
@@ -131,7 +131,7 @@ abstract class PrimitiveNumberRangeIntrinsicRangeValue(
if (isProhibitedCharConstEndValue(step, endCharValue))
null
else
createConstBoundedIntForLoopGenerator(codegen, forExpression, startValue, endCharValue.toInt(), step, isStartInclusive)
createConstBoundedIntForLoopGenerator(codegen, forExpression, startValue, endCharValue.code, step, isStartInclusive)
}
is LongValue -> {
@@ -140,8 +140,8 @@ private fun jsonEscape(value: String): String = buildString {
'\r' -> append("\\r")
'\"' -> append("\\\"")
'\\' -> append("\\\\")
else -> if (ch.toInt() < 32) {
append("\\u" + Integer.toHexString(ch.toInt()).padStart(4, '0'))
else -> if (ch.code < 32) {
append("\\u" + Integer.toHexString(ch.code).padStart(4, '0'))
}
else {
append(ch)
@@ -47,7 +47,7 @@ class LogStream(name: String) : OutputStream() {
val lineBuf = StringBuilder()
override fun write(byte: Int) {
if (byte.toChar() == '\n') flush()
if (byte == '\n'.code) flush()
else lineBuf.append(byte.toChar())
}
@@ -243,7 +243,7 @@ abstract class AbstractAnnotationDeserializer(
const(kind, value.intValue)
}
CHAR -> const(ConstantValueKind.Char, value.intValue.toChar())
CHAR -> const(ConstantValueKind.Char, value.intValue.toInt().toChar())
FLOAT -> const(ConstantValueKind.Float, value.floatValue)
DOUBLE -> const(ConstantValueKind.Double, value.doubleValue)
BOOLEAN -> const(ConstantValueKind.Boolean, (value.intValue != 0L))
@@ -54,7 +54,7 @@ class FirConstDeserializer(
): FirExpression? {
return when (constKind) {
"BYTE", "B" -> buildConstExpression(null, ConstantValueKind.Byte, ((protoValue?.intValue ?: sourceValue) as Number).toByte())
"CHAR", "C" -> buildConstExpression(null, ConstantValueKind.Char, ((protoValue?.intValue ?: sourceValue) as Number).toChar())
"CHAR", "C" -> buildConstExpression(null, ConstantValueKind.Char, ((protoValue?.intValue ?: sourceValue) as Number).toInt().toChar())
"SHORT", "S" -> buildConstExpression(null, ConstantValueKind.Short, ((protoValue?.intValue ?: sourceValue) as Number).toShort())
"INT", "I" -> buildConstExpression(null, ConstantValueKind.Int, protoValue?.intValue?.toInt() ?: sourceValue as Int)
"LONG", "J" -> buildConstExpression(null, ConstantValueKind.Long, protoValue?.intValue ?: sourceValue as Long)
@@ -35,7 +35,7 @@ internal object FirAnnotationArgumentVisitor : AnnotationArgumentVisitor<Unit, F
override fun visitCharValue(value: CharValue, data: FirAnnotationArgumentVisitorData) {
data.builder.type = ProtoBuf.Annotation.Argument.Value.Type.CHAR
data.builder.intValue = value.value.toLong()
data.builder.intValue = value.value.code.toLong()
}
override fun visitDoubleValue(value: DoubleValue, data: FirAnnotationArgumentVisitorData) {
@@ -53,7 +53,7 @@ internal class ByteValue(value: Byte) : IntegerValueConstant<Byte>(value) {
internal class CharValue(value: Char) : IntegerValueConstant<Char>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitCharValue(this, data)
override fun toString(): String = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value))
override fun toString(): String = "\\u%04X ('%s')".format(value.code, getPrintablePart(value))
private fun getPrintablePart(c: Char): String = when (c) {
'\b' -> "\\b"
@@ -847,10 +847,10 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
if (value !is Char) {
print(value.toString())
} else {
if (value.toInt() in 32..127) {
if (value.code in 32..127) {
print(value)
} else {
print(value.toInt())
print(value.code)
}
}
print(")")
@@ -82,8 +82,8 @@ internal class CharProgressionType(symbols: Symbols<CommonBackendContext>) :
ProgressionType(
elementClass = symbols.char.owner,
stepClass = symbols.int.owner,
minValueAsLong = Char.MIN_VALUE.toLong(),
maxValueAsLong = Char.MAX_VALUE.toLong(),
minValueAsLong = Char.MIN_VALUE.code.toLong(),
maxValueAsLong = Char.MAX_VALUE.code.toLong(),
// Uses `getProgressionLastElement(Int, Int, Int): Int`
getProgressionLastElementFunction = symbols.getProgressionLastElementByReturnType[symbols.int]
) {
@@ -76,7 +76,7 @@ internal val IrExpression.canHaveSideEffects: Boolean
private fun Any?.toLong(): Long? =
when (this) {
is Number -> toLong()
is Char -> toLong()
is Char -> code.toLong()
else -> null
}
@@ -60,7 +60,7 @@ class ConstTransformer(private val context: JsIrBackendContext) : IrElementTrans
}
return when {
expression.kind is IrConstKind.Char ->
lowerConst(charClassSymbol, IrConstImpl.Companion::int, IrConstKind.Char.valueOf(expression).toInt())
lowerConst(charClassSymbol, IrConstImpl.Companion::int, IrConstKind.Char.valueOf(expression).code)
expression.kind is IrConstKind.Long ->
createLong(IrConstKind.Long.valueOf(expression))
@@ -736,7 +736,7 @@ class ExpressionCodegen(
private fun isDefaultValueForType(type: Type, value: Any?): Boolean =
when (type) {
Type.BOOLEAN_TYPE -> value is Boolean && !value
Type.CHAR_TYPE -> value is Char && value.toInt() == 0
Type.CHAR_TYPE -> value is Char && value.code == 0
Type.BYTE_TYPE, Type.SHORT_TYPE, Type.INT_TYPE, Type.LONG_TYPE -> value is Number && value.toLong() == 0L
// Must use `equals` for these two to differentiate between +0.0 and -0.0:
Type.FLOAT_TYPE -> value is Number && value.toFloat().equals(0.0f)
@@ -836,7 +836,7 @@ class ExpressionCodegen(
mv.nop()
return BooleanConstant(this, value)
}
is Char -> mv.iconst(value.toInt())
is Char -> mv.iconst(value.code)
is Long -> mv.lconst(value)
is Float -> mv.fconst(value)
is Double -> mv.dconst(value)
@@ -53,7 +53,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
is IrConstKind.Short -> body.buildConstI32(kind.valueOf(expression).toInt())
is IrConstKind.Int -> body.buildConstI32(kind.valueOf(expression))
is IrConstKind.Long -> body.buildConstI64(kind.valueOf(expression))
is IrConstKind.Char -> body.buildConstI32(kind.valueOf(expression).toInt())
is IrConstKind.Char -> body.buildConstI32(kind.valueOf(expression).code)
is IrConstKind.Float -> body.buildConstF32(kind.valueOf(expression))
is IrConstKind.Double -> body.buildConstF64(kind.valueOf(expression))
is IrConstKind.String -> {
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.ir.interpreter.state.*
/** This file is generated by org.jetbrains.kotlin.backend.common.interpreter.builtins.GenerateBuiltInsMap.generateMap(). DO NOT MODIFY MANUALLY */
@Suppress("DEPRECATION_ERROR")
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Boolean>("hashCode", "Boolean") { a -> a.hashCode() },
unaryOperation<Boolean>("not", "Boolean") { a -> a.not() },
@@ -580,7 +580,7 @@ open class IrFileSerializer(
IrConstKind.Null -> proto.`null` = true
IrConstKind.Boolean -> proto.boolean = value.value as Boolean
IrConstKind.Byte -> proto.byte = (value.value as Byte).toInt()
IrConstKind.Char -> proto.char = (value.value as Char).toInt()
IrConstKind.Char -> proto.char = (value.value as Char).code
IrConstKind.Short -> proto.short = (value.value as Short).toInt()
IrConstKind.Int -> proto.int = value.value as Int
IrConstKind.Long -> proto.long = value.value as Long
@@ -73,7 +73,7 @@ open class AnnotationSerializer(private val stringTable: DescriptorAwareStringTa
override fun visitCharValue(value: CharValue, data: Unit) {
type = Type.CHAR
intValue = value.value.toLong()
intValue = value.value.code.toLong()
}
override fun visitDoubleValue(value: DoubleValue, data: Unit) {
@@ -46,7 +46,7 @@ class JvmNameResolverTest : KtUsefulTestCase() {
internalString?.let { setString(it) }
operation?.let { setOperation(it) }
substringIndex?.let { addAllSubstringIndex(it) }
replaceChar?.let { addAllReplaceChar(it.map(Char::toInt)) }
replaceChar?.let { addAllReplaceChar(it.map(Char::code)) }
}.build())
string?.let { strings.add(it) }