Use alternatives for most methods deprecated in Kotlin 1.5

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 7f58b50a47
commit b37e4d0d0b
  1. 2
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt
  2. 6
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt
  3. 8
      archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt
  4. 2
      buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/IntType.kt
  5. 2
      cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt
  6. 7
      compress/src/main/kotlin/org/openrs2/compress/bzip2/Bzip2.kt
  7. 2
      conf/src/main/kotlin/org/openrs2/conf/Config.kt
  8. 4
      crypto/src/main/kotlin/org/openrs2/crypto/Whirlpool.kt
  9. 2
      deob-ast/src/main/kotlin/org/openrs2/deob/ast/transform/CharLiteralTransformer.kt
  10. 4
      deob-ast/src/main/kotlin/org/openrs2/deob/ast/util/ExprUtils.kt
  11. 2
      deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/analysis/IntInterpreter.kt
  12. 2
      deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/transform/ConstantArgTransformer.kt
  13. 2
      patcher/src/main/kotlin/org/openrs2/patcher/Architecture.kt
  14. 2
      patcher/src/main/kotlin/org/openrs2/patcher/OperatingSystem.kt
  15. 12
      protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt
  16. 2
      util/src/main/kotlin/org/openrs2/util/StringUtils.kt
  17. 8
      util/src/main/kotlin/org/openrs2/util/charset/Cp1252Charset.kt
  18. 12
      util/src/main/kotlin/org/openrs2/util/charset/ModifiedUtf8Charset.kt
  19. 8
      util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt
  20. 4
      util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt

@ -181,7 +181,7 @@ public class CacheExporter @Inject constructor(
return@execute null 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 -> masterIndex = Unpooled.wrappedBuffer(rows.getBytes(2)).use { compressed ->
Js5Compression.uncompress(compressed).use { uncompressed -> Js5Compression.uncompress(compressed).use { uncompressed ->

@ -377,7 +377,7 @@ public class CacheImporter @Inject constructor(
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
stmt.setLong(1, containerId) stmt.setLong(1, containerId)
stmt.setString(2, masterIndex.index.format.name.toLowerCase()) stmt.setString(2, masterIndex.index.format.name.lowercase())
stmt.executeQuery().use { rows -> stmt.executeQuery().use { rows ->
if (rows.next()) { if (rows.next()) {
@ -396,7 +396,7 @@ public class CacheImporter @Inject constructor(
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
stmt.setLong(1, containerId) stmt.setLong(1, containerId)
stmt.setString(2, masterIndex.index.format.name.toLowerCase()) stmt.setString(2, masterIndex.index.format.name.lowercase())
stmt.executeQuery().use { rows -> stmt.executeQuery().use { rows ->
check(rows.next()) check(rows.next())
@ -484,7 +484,7 @@ public class CacheImporter @Inject constructor(
RETURNING id RETURNING id
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
stmt.setString(1, type.toString().toLowerCase()) stmt.setString(1, type.toString().lowercase())
stmt.setInt(2, masterIndexId) stmt.setInt(2, masterIndexId)
stmt.setInt(3, gameId) stmt.setInt(3, gameId)
stmt.setObject(4, build, Types.INTEGER) stmt.setObject(4, build, Types.INTEGER)

@ -140,16 +140,16 @@ public class CachesController @Inject constructor(
output.putNextEntry(entry) output.putNextEntry(entry)
writer.write(key.key.k0.toString()) writer.write(key.key.k0.toString())
writer.write('\n'.toInt()) writer.write('\n'.code)
writer.write(key.key.k1.toString()) writer.write(key.key.k1.toString())
writer.write('\n'.toInt()) writer.write('\n'.code)
writer.write(key.key.k2.toString()) writer.write(key.key.k2.toString())
writer.write('\n'.toInt()) writer.write('\n'.code)
writer.write(key.key.k3.toString()) writer.write(key.key.k3.toString())
writer.write('\n'.toInt()) writer.write('\n'.code)
writer.flush() writer.flush()
} }

@ -12,7 +12,7 @@ public enum class IntType(
SHORT(2, Short::class, Int::class, Int::class), SHORT(2, Short::class, Int::class, Int::class),
INT(4, Int::class, Long::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<*> { public fun getReadType(signedness: Signedness): KClass<*> {
return if (signedness == Signedness.SIGNED) { return if (signedness == Signedness.SIGNED) {

@ -140,7 +140,7 @@ public data class Js5MasterIndex(
val version = index.version val version = index.version
val groups = index.size 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? // TODO(gpe): should we throw an exception if there are trailing bytes here or in the block above?
Entry(version, checksum, groups, totalUncompressedLength, digest) Entry(version, checksum, groups, totalUncompressedLength, digest)

@ -10,7 +10,12 @@ import java.io.SequenceInputStream
public object Bzip2 { public object Bzip2 {
private const val BLOCK_SIZE = 1 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 { public fun createHeaderlessInputStream(input: InputStream): InputStream {
return BZip2CompressorInputStream(SequenceInputStream(ByteArrayInputStream(HEADER), input)) return BZip2CompressorInputStream(SequenceInputStream(ByteArrayInputStream(HEADER), input))

@ -12,7 +12,7 @@ public data class Config(
private val INTERNAL_NAME_REGEX = Regex("(?i)[^a-z0-9]+") private val INTERNAL_NAME_REGEX = Regex("(?i)[^a-z0-9]+")
private fun String.toInternalName(): String { private fun String.toInternalName(): String {
return replace(INTERNAL_NAME_REGEX, "_").trim('_').toLowerCase() return replace(INTERNAL_NAME_REGEX, "_").trim('_').lowercase()
} }
} }
} }

@ -219,9 +219,9 @@ public class Whirlpool {
val c = sbox[x / 2] val c = sbox[x / 2]
val v1 = if ((x and 1) == 0) { val v1 = if ((x and 1) == 0) {
c.toLong() ushr 8 c.code.toLong() ushr 8
} else { } else {
c.toLong() and 0xFF c.code.toLong() and 0xFF
} }
var v2 = v1 shl 1 var v2 = v1 shl 1

@ -72,7 +72,7 @@ public class CharLiteralTransformer : Transformer() {
else -> { else -> {
val type = Character.getType(c).toByte() val type = Character.getType(c).toByte()
if (type in UNPRINTABLE_TYPES) { if (type in UNPRINTABLE_TYPES) {
"\\u" + Integer.toHexString(c.toInt()).padStart(4, '0') "\\u" + Integer.toHexString(c.code).padStart(4, '0')
} else { } else {
c.toString() c.toString()
} }

@ -21,7 +21,7 @@ public fun IntegerLiteralExpr.checkedAsInt(): Int {
} }
public fun Int.toHexLiteralExpr(): IntegerLiteralExpr { 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 { public fun LongLiteralExpr.checkedAsLong(): Long {
@ -33,7 +33,7 @@ public fun LongLiteralExpr.checkedAsLong(): Long {
} }
public fun Long.toHexLiteralExpr(): LongLiteralExpr { 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 { public fun Expression.isIntegerOrLongLiteral(): Boolean {

@ -55,7 +55,7 @@ public class IntInterpreter(private val args: Array<IntValueSet>) : Interpreter<
insn.opcode == Opcodes.INEG -> -v insn.opcode == Opcodes.INEG -> -v
insn is IincInsnNode -> v + insn.incr insn is IincInsnNode -> v + insn.incr
insn.opcode == Opcodes.I2B -> v.toByte().toInt() 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() insn.opcode == Opcodes.I2S -> v.toShort().toInt()
else -> return IntValue(basicValue) else -> return IntValue(basicValue)
} }

@ -130,7 +130,7 @@ public class ConstantArgTransformer @Inject constructor(private val profile: Pro
private fun getArgs(ref: MemberRef): Array<IntValueSet> { private fun getArgs(ref: MemberRef): Array<IntValueSet> {
val partition = inheritedMethodSets[ref]!! 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 } return Array(size) { i -> argValues[ArgPartition(partition, i)] ?: IntValueSet.Unknown }
} }

@ -7,5 +7,5 @@ public enum class Architecture(
AMD64(listOf("amd64", "x86_64")), AMD64(listOf("amd64", "x86_64")),
AARCH64(listOf("aarch64")); AARCH64(listOf("aarch64"));
public val id: String = name.toLowerCase() public val id: String = name.lowercase()
} }

@ -14,5 +14,5 @@ public enum class OperatingSystem(
MAC("mac", listOf(AARCH64, AMD64, I386), listOf("libjaggl.dylib")), MAC("mac", listOf(AARCH64, AMD64, I386), listOf("libjaggl.dylib")),
LINUX("linux", listOf(AMD64, I386), listOf("libjaggl.so", "libjaggl_dri.so")); LINUX("linux", listOf(AMD64, I386), listOf("libjaggl.so", "libjaggl_dri.so"));
public val id: String = name.toLowerCase() public val id: String = name.lowercase()
} }

@ -38,8 +38,16 @@ class Js5ResponseDecoderTest {
val channel = EmbeddedChannel(Js5ResponseDecoder()) val channel = EmbeddedChannel(Js5ResponseDecoder())
channel.writeInbound(wrappedBuffer(2, 0, 3, 0, 0, 0, 0)) channel.writeInbound(wrappedBuffer(2, 0, 3, 0, 0, 0, 0))
channel.writeInbound(wrappedBuffer(7, 'O'.toByte(), 'p'.toByte(), 'e'.toByte(), 'n'.toByte())) channel.writeInbound(
channel.writeInbound(wrappedBuffer('R'.toByte(), 'S'.toByte(), '2'.toByte())) 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 -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
buf.writeByte(0) buf.writeByte(0)

@ -5,7 +5,7 @@ import org.openrs2.util.charset.Cp1252Charset
public fun CharSequence.indefiniteArticle(): String { public fun CharSequence.indefiniteArticle(): String {
require(isNotEmpty()) require(isNotEmpty())
return when (first().toLowerCase()) { return when (first().lowercaseChar()) {
'a', 'e', 'i', 'o', 'u' -> "an" 'a', 'e', 'i', 'o', 'u' -> "an"
else -> "a" else -> "a"
} }

@ -17,7 +17,7 @@ public object Cp1252Charset : Charset("Cp1252", null) {
private val ENCODE_TABLE = ByteArray(65536) private val ENCODE_TABLE = ByteArray(65536)
private val DECODE_TABLE = CharArray(256) private val DECODE_TABLE = CharArray(256)
private const val REPLACEMENT_CHAR = '\uFFFD' private const val REPLACEMENT_CHAR = '\uFFFD'
private const val REPLACEMENT_BYTE = '?'.toByte() private const val REPLACEMENT_BYTE = '?'.code.toByte()
init { init {
for (b in 0 until 256) { for (b in 0 until 256) {
@ -28,7 +28,7 @@ public object Cp1252Charset : Charset("Cp1252", null) {
} }
if (c != '\u0000') { if (c != '\u0000') {
ENCODE_TABLE[c.toInt()] = b.toByte() ENCODE_TABLE[c.code] = b.toByte()
DECODE_TABLE[b] = c DECODE_TABLE[b] = c
} }
} }
@ -44,7 +44,7 @@ public object Cp1252Charset : Charset("Cp1252", null) {
} }
public fun encode(char: Char): Byte { public fun encode(char: Char): Byte {
val byte = ENCODE_TABLE[char.toInt()] val byte = ENCODE_TABLE[char.code]
return if (byte.toInt() == 0) { return if (byte.toInt() == 0) {
REPLACEMENT_BYTE REPLACEMENT_BYTE
} else { } else {
@ -65,7 +65,7 @@ public object Cp1252Charset : Charset("Cp1252", null) {
} }
val char = input.get() val char = input.get()
val byte = ENCODE_TABLE[char.toInt()] val byte = ENCODE_TABLE[char.code]
if (byte.toInt() == 0) { if (byte.toInt() == 0) {
input.position(input.position() - 1) input.position(input.position() - 1)

@ -32,15 +32,15 @@ public object ModifiedUtf8Charset : Charset("ModifiedUtf8", null) {
} }
when (len) { when (len) {
1 -> output.put(char.toByte()) 1 -> output.put(char.code.toByte())
2 -> { 2 -> {
output.put((0xC0 or ((char.toInt() shr 6) and 0x1F)).toByte()) output.put((0xC0 or ((char.code shr 6) and 0x1F)).toByte())
output.put((0x80 or (char.toInt() and 0x3F)).toByte()) output.put((0x80 or (char.code and 0x3F)).toByte())
} }
else -> { else -> {
output.put((0xE0 or ((char.toInt() shr 12) and 0x1F)).toByte()) output.put((0xE0 or ((char.code shr 12) and 0x1F)).toByte())
output.put((0x80 or ((char.toInt() shr 6) and 0x1F)).toByte()) output.put((0x80 or ((char.code shr 6) and 0x1F)).toByte())
output.put((0x80 or (char.toInt() and 0x3F)).toByte()) output.put((0x80 or (char.code and 0x3F)).toByte())
} }
} }
} }

@ -10,14 +10,14 @@ class Cp1252CharsetTest {
@Test @Test
fun testEncodeChar() { fun testEncodeChar() {
// edge cases // edge cases
assertEquals(Cp1252Charset.encode('\u0000'), '?'.toByte()) assertEquals(Cp1252Charset.encode('\u0000'), '?'.code.toByte())
assertEquals(Cp1252Charset.encode('\u0001'), 1.toByte()) assertEquals(Cp1252Charset.encode('\u0001'), 1.toByte())
assertEquals(Cp1252Charset.encode('\u007F'), 127.toByte()) assertEquals(Cp1252Charset.encode('\u007F'), 127.toByte())
assertEquals(Cp1252Charset.encode('€'), 128.toByte()) assertEquals(Cp1252Charset.encode('€'), 128.toByte())
assertEquals(Cp1252Charset.encode('Ÿ'), 159.toByte()) assertEquals(Cp1252Charset.encode('Ÿ'), 159.toByte())
assertEquals(Cp1252Charset.encode('\u00A0'), 160.toByte()) assertEquals(Cp1252Charset.encode('\u00A0'), 160.toByte())
assertEquals(Cp1252Charset.encode('ÿ'), 255.toByte()) assertEquals(Cp1252Charset.encode('ÿ'), 255.toByte())
assertEquals(Cp1252Charset.encode('\u0100'), '?'.toByte()) assertEquals(Cp1252Charset.encode('\u0100'), '?'.code.toByte())
// 7-bit ASCII char // 7-bit ASCII char
assertEquals(Cp1252Charset.encode('A'), 65.toByte()) assertEquals(Cp1252Charset.encode('A'), 65.toByte())
@ -61,14 +61,14 @@ class Cp1252CharsetTest {
fun testEncode() { fun testEncode() {
assertArrayEquals( assertArrayEquals(
byteArrayOf( byteArrayOf(
'?'.toByte(), '?'.code.toByte(),
1.toByte(), 1.toByte(),
127.toByte(), 127.toByte(),
128.toByte(), 128.toByte(),
159.toByte(), 159.toByte(),
160.toByte(), 160.toByte(),
255.toByte(), 255.toByte(),
'?'.toByte(), '?'.code.toByte(),
65.toByte(), 65.toByte(),
138.toByte(), 138.toByte(),
214.toByte() 214.toByte()

@ -18,7 +18,7 @@ class IterableUtilsTest {
assertEquals(listOf(3), list) assertEquals(listOf(3), list)
assertEquals(3, list.removeFirst()) assertEquals(3, list.removeFirst())
assertEquals(emptyList<Int>(), list) assertEquals(emptyList(), list)
assertFailsWith<NoSuchElementException> { assertFailsWith<NoSuchElementException> {
list.removeFirst() list.removeFirst()
@ -35,7 +35,7 @@ class IterableUtilsTest {
assertEquals(listOf(3), list) assertEquals(listOf(3), list)
assertEquals(3, list.removeFirstOrNull()) assertEquals(3, list.removeFirstOrNull())
assertEquals(emptyList<Int>(), list) assertEquals(emptyList(), list)
assertNull(list.removeFirstOrNull()) assertNull(list.removeFirstOrNull())
} }

Loading…
Cancel
Save