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) }
@@ -85,7 +85,7 @@ class CharValue(value: Char) : IntegerValueConstant<Char>(value) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitCharValue(this, data)
override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value))
override fun toString() = "\\u%04X ('%s')".format(value.code, getPrintablePart(value))
private fun getPrintablePart(c: Char): String = when (c) {
'\b' -> "\\b"
@@ -73,7 +73,7 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n
return when (value.type) {
Type.BYTE -> value.intValue.toByte().letIf(isUnsigned, ::UByteValue, ::ByteValue)
Type.CHAR -> CharValue(value.intValue.toChar())
Type.CHAR -> CharValue(value.intValue.toInt().toChar())
Type.SHORT -> value.intValue.toShort().letIf(isUnsigned, ::UShortValue, ::ShortValue)
Type.INT -> value.intValue.toInt().letIf(isUnsigned, ::UIntValue, ::IntValue)
Type.LONG -> value.intValue.letIf(isUnsigned, ::ULongValue, ::LongValue)
@@ -62,7 +62,7 @@ fun stringsToBytes(strings: Array<String>): ByteArray {
var i = 0
for (s in strings) {
for (si in 0..s.length - 1) {
result[i++] = s[si].toByte()
result[i++] = s[si].code.toByte()
}
}
@@ -52,7 +52,7 @@ fun generateMap(): String {
val binaryIrOperationsMap = getBinaryIrOperationMap(irBuiltIns)
p.println("@Suppress(\"DEPRECATION_ERROR\")")
p.println("@Suppress(\"DEPRECATION\", \"DEPRECATION_ERROR\")")
p.println("val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(")
p.println(generateUnaryBody(unaryOperationsMap, irBuiltIns))
p.println(")")
@@ -21,7 +21,7 @@ class InlayScratchFileRenderer(val text: String, private val outputType: Scratch
val attributes = getAttributesForOutputType(outputType)
val fontStyle = attributes.fontType
return ComplementaryFontsRegistry.getFontAbleToDisplay(
'a'.toInt(), fontStyle, fontPreferences, FontInfo.getFontRenderContext(editor.contentComponent)
'a'.code, fontStyle, fontPreferences, FontInfo.getFontRenderContext(editor.contentComponent)
)
}
@@ -94,7 +94,7 @@ class LabelValue(value: LabelNode) : AbstractValue<LabelNode>(value, Type.VOID_T
fun boolean(v: Boolean) = IntValue(if (v) 1 else 0, Type.BOOLEAN_TYPE)
fun byte(v: Byte) = IntValue(v.toInt(), Type.BYTE_TYPE)
fun short(v: Short) = IntValue(v.toInt(), Type.SHORT_TYPE)
fun char(v: Char) = IntValue(v.toInt(), Type.CHAR_TYPE)
fun char(v: Char) = IntValue(v.code, Type.CHAR_TYPE)
fun int(v: Int) = IntValue(v, Type.INT_TYPE)
fun long(v: Long) = LongValue(v)
fun float(v: Float) = FloatValue(v)
@@ -167,7 +167,7 @@ private fun String.offsetOf(position: CodePosition): Int {
i++
offsetInLine++
if (isEndOfLine(c.toInt())) {
if (isEndOfLine(c.code)) {
offsetInLine = 0
lineCount++
assert(lineCount <= position.line)
@@ -80,7 +80,7 @@ fun String.underlineAsText(from: Int, to: Int): String {
marks.append(mark)
lineWasMarked = lineWasMarked || mark != ' '
if (isEndOfLine(c.toInt())) {
if (isEndOfLine(c.code)) {
if (lineWasMarked) {
lines.appendLine(marks.toString().trimEnd())
lineWasMarked = false
@@ -121,7 +121,7 @@ fun String.underlineAsHtml(from: Int, to: Int): String {
lines.append(mark)
if (isEndOfLine(c.toInt()) && openMarker) {
if (isEndOfLine(c.code) && openMarker) {
lines.append(underlineEnd + c + underlineStart)
} else {
lines.append(c)
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DEPRECATION") // TODO: needs an intensive rework for new Char API
package org.jetbrains.kotlin.js.parser.sourcemaps
import java.io.*
@@ -14,6 +14,7 @@
* limitations under the License.
*/
@file:Suppress("DEPRECATION") // TODO: needs an intensive rework for new Char API
package org.jetbrains.kotlin.js.parser.sourcemaps
import java.io.File
@@ -197,7 +197,7 @@ private constructor(private val whenExpression: KtWhenExpression, context: Trans
is Int -> JsIntLiteral(it)
is Short -> JsIntLiteral(it.toInt())
is Byte -> JsIntLiteral(it.toInt())
is Char -> JsIntLiteral(it.toInt())
is Char -> JsIntLiteral(it.code)
else -> null
}
}
@@ -1330,7 +1330,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
private fun convertValueOfPrimitiveTypeOrString(value: Any?): JCExpression? {
fun specialFpValueNumerator(value: Double): Double = if (value.isNaN()) 0.0 else 1.0 * value.sign
return when (value) {
is Char -> treeMaker.Literal(TypeTag.CHAR, value.toInt())
is Char -> treeMaker.Literal(TypeTag.CHAR, value.code)
is Byte -> treeMaker.TypeCast(treeMaker.TypeIdent(TypeTag.BYTE), treeMaker.Literal(TypeTag.INT, value.toInt()))
is Short -> treeMaker.TypeCast(treeMaker.TypeIdent(TypeTag.SHORT), treeMaker.Literal(TypeTag.INT, value.toInt()))
is Boolean, is Int, is Long, is String -> treeMaker.Literal(value)