From b37e4d0d0b1b38c89f1e8b819a1667d6ae8b50c9 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 8 May 2021 18:06:02 +0100 Subject: [PATCH] Use alternatives for most methods deprecated in Kotlin 1.5 Signed-off-by: Graham --- .../org/openrs2/archive/cache/CacheExporter.kt | 2 +- .../org/openrs2/archive/cache/CacheImporter.kt | 6 +++--- .../org/openrs2/archive/web/CachesController.kt | 8 ++++---- .../kotlin/org/openrs2/buffer/generator/IntType.kt | 2 +- .../main/kotlin/org/openrs2/cache/Js5MasterIndex.kt | 2 +- .../main/kotlin/org/openrs2/compress/bzip2/Bzip2.kt | 7 ++++++- conf/src/main/kotlin/org/openrs2/conf/Config.kt | 2 +- .../src/main/kotlin/org/openrs2/crypto/Whirlpool.kt | 4 ++-- .../deob/ast/transform/CharLiteralTransformer.kt | 2 +- .../kotlin/org/openrs2/deob/ast/util/ExprUtils.kt | 4 ++-- .../openrs2/deob/bytecode/analysis/IntInterpreter.kt | 2 +- .../bytecode/transform/ConstantArgTransformer.kt | 2 +- .../main/kotlin/org/openrs2/patcher/Architecture.kt | 2 +- .../kotlin/org/openrs2/patcher/OperatingSystem.kt | 2 +- .../openrs2/protocol/js5/Js5ResponseDecoderTest.kt | 12 ++++++++++-- util/src/main/kotlin/org/openrs2/util/StringUtils.kt | 2 +- .../kotlin/org/openrs2/util/charset/Cp1252Charset.kt | 8 ++++---- .../org/openrs2/util/charset/ModifiedUtf8Charset.kt | 12 ++++++------ .../org/openrs2/util/charset/Cp1252CharsetTest.kt | 8 ++++---- .../org/openrs2/util/collect/IterableUtilsTest.kt | 4 ++-- 20 files changed, 53 insertions(+), 40 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt index c916361b..4ce091f6 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt @@ -181,7 +181,7 @@ public class CacheExporter @Inject constructor( return@execute null } - val format = MasterIndexFormat.valueOf(rows.getString(1).toUpperCase()) + val format = MasterIndexFormat.valueOf(rows.getString(1).uppercase()) masterIndex = Unpooled.wrappedBuffer(rows.getBytes(2)).use { compressed -> Js5Compression.uncompress(compressed).use { uncompressed -> diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt index e19c1239..f4a6f335 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt @@ -377,7 +377,7 @@ public class CacheImporter @Inject constructor( """.trimIndent() ).use { stmt -> stmt.setLong(1, containerId) - stmt.setString(2, masterIndex.index.format.name.toLowerCase()) + stmt.setString(2, masterIndex.index.format.name.lowercase()) stmt.executeQuery().use { rows -> if (rows.next()) { @@ -396,7 +396,7 @@ public class CacheImporter @Inject constructor( """.trimIndent() ).use { stmt -> stmt.setLong(1, containerId) - stmt.setString(2, masterIndex.index.format.name.toLowerCase()) + stmt.setString(2, masterIndex.index.format.name.lowercase()) stmt.executeQuery().use { rows -> check(rows.next()) @@ -484,7 +484,7 @@ public class CacheImporter @Inject constructor( RETURNING id """.trimIndent() ).use { stmt -> - stmt.setString(1, type.toString().toLowerCase()) + stmt.setString(1, type.toString().lowercase()) stmt.setInt(2, masterIndexId) stmt.setInt(3, gameId) stmt.setObject(4, build, Types.INTEGER) diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt index 3589f8d7..29746e2e 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt @@ -140,16 +140,16 @@ public class CachesController @Inject constructor( output.putNextEntry(entry) writer.write(key.key.k0.toString()) - writer.write('\n'.toInt()) + writer.write('\n'.code) writer.write(key.key.k1.toString()) - writer.write('\n'.toInt()) + writer.write('\n'.code) writer.write(key.key.k2.toString()) - writer.write('\n'.toInt()) + writer.write('\n'.code) writer.write(key.key.k3.toString()) - writer.write('\n'.toInt()) + writer.write('\n'.code) writer.flush() } diff --git a/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/IntType.kt b/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/IntType.kt index 22b9911e..8d98ea2c 100644 --- a/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/IntType.kt +++ b/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/IntType.kt @@ -12,7 +12,7 @@ public enum class IntType( SHORT(2, Short::class, Int::class, Int::class), INT(4, Int::class, Long::class, Int::class); - public val prettyName: String = name.toLowerCase().capitalize() + public val prettyName: String = name.lowercase().capitalize() public fun getReadType(signedness: Signedness): KClass<*> { return if (signedness == Signedness.SIGNED) { diff --git a/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt index 6cf1b854..ec0cca4c 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt @@ -140,7 +140,7 @@ public data class Js5MasterIndex( val version = index.version val groups = index.size - val totalUncompressedLength = index.sumBy(Js5Index.Group::uncompressedLength) + val totalUncompressedLength = index.sumOf(Js5Index.Group::uncompressedLength) // TODO(gpe): should we throw an exception if there are trailing bytes here or in the block above? Entry(version, checksum, groups, totalUncompressedLength, digest) diff --git a/compress/src/main/kotlin/org/openrs2/compress/bzip2/Bzip2.kt b/compress/src/main/kotlin/org/openrs2/compress/bzip2/Bzip2.kt index bc515f41..6d822266 100644 --- a/compress/src/main/kotlin/org/openrs2/compress/bzip2/Bzip2.kt +++ b/compress/src/main/kotlin/org/openrs2/compress/bzip2/Bzip2.kt @@ -10,7 +10,12 @@ import java.io.SequenceInputStream public object Bzip2 { private const val BLOCK_SIZE = 1 - private val HEADER = byteArrayOf('B'.toByte(), 'Z'.toByte(), 'h'.toByte(), ('0' + BLOCK_SIZE).toByte()) + private val HEADER = byteArrayOf( + 'B'.code.toByte(), + 'Z'.code.toByte(), + 'h'.code.toByte(), + ('0' + BLOCK_SIZE).code.toByte() + ) public fun createHeaderlessInputStream(input: InputStream): InputStream { return BZip2CompressorInputStream(SequenceInputStream(ByteArrayInputStream(HEADER), input)) diff --git a/conf/src/main/kotlin/org/openrs2/conf/Config.kt b/conf/src/main/kotlin/org/openrs2/conf/Config.kt index 97c01997..4c8bcdbf 100644 --- a/conf/src/main/kotlin/org/openrs2/conf/Config.kt +++ b/conf/src/main/kotlin/org/openrs2/conf/Config.kt @@ -12,7 +12,7 @@ public data class Config( private val INTERNAL_NAME_REGEX = Regex("(?i)[^a-z0-9]+") private fun String.toInternalName(): String { - return replace(INTERNAL_NAME_REGEX, "_").trim('_').toLowerCase() + return replace(INTERNAL_NAME_REGEX, "_").trim('_').lowercase() } } } diff --git a/crypto/src/main/kotlin/org/openrs2/crypto/Whirlpool.kt b/crypto/src/main/kotlin/org/openrs2/crypto/Whirlpool.kt index 9a5398db..93570965 100644 --- a/crypto/src/main/kotlin/org/openrs2/crypto/Whirlpool.kt +++ b/crypto/src/main/kotlin/org/openrs2/crypto/Whirlpool.kt @@ -219,9 +219,9 @@ public class Whirlpool { val c = sbox[x / 2] val v1 = if ((x and 1) == 0) { - c.toLong() ushr 8 + c.code.toLong() ushr 8 } else { - c.toLong() and 0xFF + c.code.toLong() and 0xFF } var v2 = v1 shl 1 diff --git a/deob-ast/src/main/kotlin/org/openrs2/deob/ast/transform/CharLiteralTransformer.kt b/deob-ast/src/main/kotlin/org/openrs2/deob/ast/transform/CharLiteralTransformer.kt index 135a53d0..6ba7479f 100644 --- a/deob-ast/src/main/kotlin/org/openrs2/deob/ast/transform/CharLiteralTransformer.kt +++ b/deob-ast/src/main/kotlin/org/openrs2/deob/ast/transform/CharLiteralTransformer.kt @@ -72,7 +72,7 @@ public class CharLiteralTransformer : Transformer() { else -> { val type = Character.getType(c).toByte() if (type in UNPRINTABLE_TYPES) { - "\\u" + Integer.toHexString(c.toInt()).padStart(4, '0') + "\\u" + Integer.toHexString(c.code).padStart(4, '0') } else { c.toString() } diff --git a/deob-ast/src/main/kotlin/org/openrs2/deob/ast/util/ExprUtils.kt b/deob-ast/src/main/kotlin/org/openrs2/deob/ast/util/ExprUtils.kt index a5afd3f7..e18dc649 100644 --- a/deob-ast/src/main/kotlin/org/openrs2/deob/ast/util/ExprUtils.kt +++ b/deob-ast/src/main/kotlin/org/openrs2/deob/ast/util/ExprUtils.kt @@ -21,7 +21,7 @@ public fun IntegerLiteralExpr.checkedAsInt(): Int { } public fun Int.toHexLiteralExpr(): IntegerLiteralExpr { - return IntegerLiteralExpr("0x${Integer.toUnsignedString(this, 16).toUpperCase()}") + return IntegerLiteralExpr("0x${Integer.toUnsignedString(this, 16).uppercase()}") } public fun LongLiteralExpr.checkedAsLong(): Long { @@ -33,7 +33,7 @@ public fun LongLiteralExpr.checkedAsLong(): Long { } public fun Long.toHexLiteralExpr(): LongLiteralExpr { - return LongLiteralExpr("0x${java.lang.Long.toUnsignedString(this, 16).toUpperCase()}L") + return LongLiteralExpr("0x${java.lang.Long.toUnsignedString(this, 16).uppercase()}L") } public fun Expression.isIntegerOrLongLiteral(): Boolean { diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/analysis/IntInterpreter.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/analysis/IntInterpreter.kt index 49b0dd4e..32f1b736 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/analysis/IntInterpreter.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/analysis/IntInterpreter.kt @@ -55,7 +55,7 @@ public class IntInterpreter(private val args: Array) : Interpreter< insn.opcode == Opcodes.INEG -> -v insn is IincInsnNode -> v + insn.incr insn.opcode == Opcodes.I2B -> v.toByte().toInt() - insn.opcode == Opcodes.I2C -> v.toChar().toInt() + insn.opcode == Opcodes.I2C -> v.toChar().code insn.opcode == Opcodes.I2S -> v.toShort().toInt() else -> return IntValue(basicValue) } diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/transform/ConstantArgTransformer.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/transform/ConstantArgTransformer.kt index c8e7eca7..ce8b8eaa 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/transform/ConstantArgTransformer.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/transform/ConstantArgTransformer.kt @@ -130,7 +130,7 @@ public class ConstantArgTransformer @Inject constructor(private val profile: Pro private fun getArgs(ref: MemberRef): Array { val partition = inheritedMethodSets[ref]!! - val size = Type.getArgumentTypes(ref.desc).sumBy { it.size } + val size = Type.getArgumentTypes(ref.desc).sumOf { it.size } return Array(size) { i -> argValues[ArgPartition(partition, i)] ?: IntValueSet.Unknown } } diff --git a/patcher/src/main/kotlin/org/openrs2/patcher/Architecture.kt b/patcher/src/main/kotlin/org/openrs2/patcher/Architecture.kt index 364503d0..d5896f61 100644 --- a/patcher/src/main/kotlin/org/openrs2/patcher/Architecture.kt +++ b/patcher/src/main/kotlin/org/openrs2/patcher/Architecture.kt @@ -7,5 +7,5 @@ public enum class Architecture( AMD64(listOf("amd64", "x86_64")), AARCH64(listOf("aarch64")); - public val id: String = name.toLowerCase() + public val id: String = name.lowercase() } diff --git a/patcher/src/main/kotlin/org/openrs2/patcher/OperatingSystem.kt b/patcher/src/main/kotlin/org/openrs2/patcher/OperatingSystem.kt index 3dc27473..cc0cbb41 100644 --- a/patcher/src/main/kotlin/org/openrs2/patcher/OperatingSystem.kt +++ b/patcher/src/main/kotlin/org/openrs2/patcher/OperatingSystem.kt @@ -14,5 +14,5 @@ public enum class OperatingSystem( MAC("mac", listOf(AARCH64, AMD64, I386), listOf("libjaggl.dylib")), LINUX("linux", listOf(AMD64, I386), listOf("libjaggl.so", "libjaggl_dri.so")); - public val id: String = name.toLowerCase() + public val id: String = name.lowercase() } diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt index d6ee0231..377c7a36 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt @@ -38,8 +38,16 @@ class Js5ResponseDecoderTest { val channel = EmbeddedChannel(Js5ResponseDecoder()) channel.writeInbound(wrappedBuffer(2, 0, 3, 0, 0, 0, 0)) - channel.writeInbound(wrappedBuffer(7, 'O'.toByte(), 'p'.toByte(), 'e'.toByte(), 'n'.toByte())) - channel.writeInbound(wrappedBuffer('R'.toByte(), 'S'.toByte(), '2'.toByte())) + channel.writeInbound( + wrappedBuffer( + 7, + 'O'.code.toByte(), + 'p'.code.toByte(), + 'e'.code.toByte(), + 'n'.code.toByte() + ) + ) + channel.writeInbound(wrappedBuffer('R'.code.toByte(), 'S'.code.toByte(), '2'.code.toByte())) ByteBufAllocator.DEFAULT.buffer().use { buf -> buf.writeByte(0) diff --git a/util/src/main/kotlin/org/openrs2/util/StringUtils.kt b/util/src/main/kotlin/org/openrs2/util/StringUtils.kt index 870b2c12..8ce100bd 100644 --- a/util/src/main/kotlin/org/openrs2/util/StringUtils.kt +++ b/util/src/main/kotlin/org/openrs2/util/StringUtils.kt @@ -5,7 +5,7 @@ import org.openrs2.util.charset.Cp1252Charset public fun CharSequence.indefiniteArticle(): String { require(isNotEmpty()) - return when (first().toLowerCase()) { + return when (first().lowercaseChar()) { 'a', 'e', 'i', 'o', 'u' -> "an" else -> "a" } diff --git a/util/src/main/kotlin/org/openrs2/util/charset/Cp1252Charset.kt b/util/src/main/kotlin/org/openrs2/util/charset/Cp1252Charset.kt index 7b3ada7c..86805966 100644 --- a/util/src/main/kotlin/org/openrs2/util/charset/Cp1252Charset.kt +++ b/util/src/main/kotlin/org/openrs2/util/charset/Cp1252Charset.kt @@ -17,7 +17,7 @@ public object Cp1252Charset : Charset("Cp1252", null) { private val ENCODE_TABLE = ByteArray(65536) private val DECODE_TABLE = CharArray(256) private const val REPLACEMENT_CHAR = '\uFFFD' - private const val REPLACEMENT_BYTE = '?'.toByte() + private const val REPLACEMENT_BYTE = '?'.code.toByte() init { for (b in 0 until 256) { @@ -28,7 +28,7 @@ public object Cp1252Charset : Charset("Cp1252", null) { } if (c != '\u0000') { - ENCODE_TABLE[c.toInt()] = b.toByte() + ENCODE_TABLE[c.code] = b.toByte() DECODE_TABLE[b] = c } } @@ -44,7 +44,7 @@ public object Cp1252Charset : Charset("Cp1252", null) { } public fun encode(char: Char): Byte { - val byte = ENCODE_TABLE[char.toInt()] + val byte = ENCODE_TABLE[char.code] return if (byte.toInt() == 0) { REPLACEMENT_BYTE } else { @@ -65,7 +65,7 @@ public object Cp1252Charset : Charset("Cp1252", null) { } val char = input.get() - val byte = ENCODE_TABLE[char.toInt()] + val byte = ENCODE_TABLE[char.code] if (byte.toInt() == 0) { input.position(input.position() - 1) diff --git a/util/src/main/kotlin/org/openrs2/util/charset/ModifiedUtf8Charset.kt b/util/src/main/kotlin/org/openrs2/util/charset/ModifiedUtf8Charset.kt index d58d65ad..9feab981 100644 --- a/util/src/main/kotlin/org/openrs2/util/charset/ModifiedUtf8Charset.kt +++ b/util/src/main/kotlin/org/openrs2/util/charset/ModifiedUtf8Charset.kt @@ -32,15 +32,15 @@ public object ModifiedUtf8Charset : Charset("ModifiedUtf8", null) { } when (len) { - 1 -> output.put(char.toByte()) + 1 -> output.put(char.code.toByte()) 2 -> { - output.put((0xC0 or ((char.toInt() shr 6) and 0x1F)).toByte()) - output.put((0x80 or (char.toInt() and 0x3F)).toByte()) + output.put((0xC0 or ((char.code shr 6) and 0x1F)).toByte()) + output.put((0x80 or (char.code and 0x3F)).toByte()) } else -> { - output.put((0xE0 or ((char.toInt() shr 12) and 0x1F)).toByte()) - output.put((0x80 or ((char.toInt() shr 6) and 0x1F)).toByte()) - output.put((0x80 or (char.toInt() and 0x3F)).toByte()) + output.put((0xE0 or ((char.code shr 12) and 0x1F)).toByte()) + output.put((0x80 or ((char.code shr 6) and 0x1F)).toByte()) + output.put((0x80 or (char.code and 0x3F)).toByte()) } } } diff --git a/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt b/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt index 72f86e34..d854747f 100644 --- a/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt @@ -10,14 +10,14 @@ class Cp1252CharsetTest { @Test fun testEncodeChar() { // edge cases - assertEquals(Cp1252Charset.encode('\u0000'), '?'.toByte()) + assertEquals(Cp1252Charset.encode('\u0000'), '?'.code.toByte()) assertEquals(Cp1252Charset.encode('\u0001'), 1.toByte()) assertEquals(Cp1252Charset.encode('\u007F'), 127.toByte()) assertEquals(Cp1252Charset.encode('€'), 128.toByte()) assertEquals(Cp1252Charset.encode('Ÿ'), 159.toByte()) assertEquals(Cp1252Charset.encode('\u00A0'), 160.toByte()) assertEquals(Cp1252Charset.encode('ÿ'), 255.toByte()) - assertEquals(Cp1252Charset.encode('\u0100'), '?'.toByte()) + assertEquals(Cp1252Charset.encode('\u0100'), '?'.code.toByte()) // 7-bit ASCII char assertEquals(Cp1252Charset.encode('A'), 65.toByte()) @@ -61,14 +61,14 @@ class Cp1252CharsetTest { fun testEncode() { assertArrayEquals( byteArrayOf( - '?'.toByte(), + '?'.code.toByte(), 1.toByte(), 127.toByte(), 128.toByte(), 159.toByte(), 160.toByte(), 255.toByte(), - '?'.toByte(), + '?'.code.toByte(), 65.toByte(), 138.toByte(), 214.toByte() diff --git a/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt b/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt index 5f65dbd9..187902d7 100644 --- a/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt @@ -18,7 +18,7 @@ class IterableUtilsTest { assertEquals(listOf(3), list) assertEquals(3, list.removeFirst()) - assertEquals(emptyList(), list) + assertEquals(emptyList(), list) assertFailsWith { list.removeFirst() @@ -35,7 +35,7 @@ class IterableUtilsTest { assertEquals(listOf(3), list) assertEquals(3, list.removeFirstOrNull()) - assertEquals(emptyList(), list) + assertEquals(emptyList(), list) assertNull(list.removeFirstOrNull()) }