Fix Kotlin inspections

master
Graham 5 years ago
parent 8f991ad772
commit d9762d65bc
  1. 3
      common/src/main/java/dev/openrs2/common/StringUtils.kt
  2. 18
      common/src/main/java/dev/openrs2/common/collect/ForestDisjointSet.kt
  3. 14
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt
  4. 2
      deob-ast/src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt
  5. 6
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt
  6. 3
      deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt

@ -3,8 +3,7 @@ package dev.openrs2.common
fun CharSequence.indefiniteArticle(): String { fun CharSequence.indefiniteArticle(): String {
require(isNotEmpty()) require(isNotEmpty())
val first = first().toLowerCase() return when (first().toLowerCase()) {
return when (first) {
'a', 'e', 'i', 'o', 'u' -> "an" 'a', 'e', 'i', 'o', 'u' -> "an"
else -> "a" else -> "a"
} }

@ -98,13 +98,17 @@ class ForestDisjointSet<T> : DisjointSet<T> {
return return
} }
if (xRoot.rank < yRoot.rank) { when {
xRoot.parent = yRoot xRoot.rank < yRoot.rank -> {
} else if (xRoot.rank > yRoot.rank) { xRoot.parent = yRoot
yRoot.parent = xRoot }
} else { xRoot.rank > yRoot.rank -> {
yRoot.parent = xRoot yRoot.parent = xRoot
xRoot.rank++ }
else -> {
yRoot.parent = xRoot
xRoot.rank++
}
} }
partitions-- partitions--

@ -115,13 +115,13 @@ class IfElseTransformer : Transformer() {
companion object { companion object {
private fun isIf(stmt: Statement): Boolean { private fun isIf(stmt: Statement): Boolean {
return if (stmt.isIfStmt) { return when {
true stmt.isIfStmt -> true
} else if (stmt.isBlockStmt) { stmt.isBlockStmt -> {
val stmts = stmt.asBlockStmt().statements val stmts = stmt.asBlockStmt().statements
stmts.size == 1 && stmts[0].isIfStmt stmts.size == 1 && stmts[0].isIfStmt
} else { }
false else -> false
} }
} }

@ -12,7 +12,7 @@ fun Expression.isIntegerOrLongLiteral(): Boolean {
} }
fun createLong(value: Long): LongLiteralExpr { fun createLong(value: Long): LongLiteralExpr {
return LongLiteralExpr(java.lang.Long.toString(value) + "L") return LongLiteralExpr(value.toString() + "L")
} }
fun Expression.negate(): Expression { fun Expression.negate(): Expression {

@ -39,13 +39,13 @@ class OpaquePredicateTransformer : Transformer() {
} }
private fun findFlowObstructors(library: Library, method: MethodNode) { private fun findFlowObstructors(library: Library, method: MethodNode) {
FLOW_OBSTRUCTOR_INITIALIZER_MATCHER.match(method).forEach { FLOW_OBSTRUCTOR_INITIALIZER_MATCHER.match(method).forEach { match ->
// add flow obstructor to set // add flow obstructor to set
val putstatic = it.last() as FieldInsnNode val putstatic = match.last() as FieldInsnNode
flowObstructors.add(MemberRef(putstatic)) flowObstructors.add(MemberRef(putstatic))
// remove initializer // remove initializer
it.forEach(method.instructions::remove) match.forEach(method.instructions::remove)
// remove field // remove field
val owner = library[putstatic.owner]!! val owner = library[putstatic.owner]!!

@ -56,8 +56,7 @@ class UnusedArgTransformer : Transformer() {
val stackSize = frame.stackSize val stackSize = frame.stackSize
val insn = method.instructions[i] when (val insn = method.instructions[i]) {
when (insn) {
is VarInsnNode -> { is VarInsnNode -> {
if (insn.opcode != Opcodes.ILOAD) { if (insn.opcode != Opcodes.ILOAD) {
continue@frame continue@frame

Loading…
Cancel
Save