Fix Kotlin inspections

master
Graham 5 years ago
parent 8f991ad772
commit d9762d65bc
  1. 3
      common/src/main/java/dev/openrs2/common/StringUtils.kt
  2. 10
      common/src/main/java/dev/openrs2/common/collect/ForestDisjointSet.kt
  3. 10
      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 {
require(isNotEmpty())
val first = first().toLowerCase()
return when (first) {
return when (first().toLowerCase()) {
'a', 'e', 'i', 'o', 'u' -> "an"
else -> "a"
}

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

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

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

@ -39,13 +39,13 @@ class OpaquePredicateTransformer : Transformer() {
}
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
val putstatic = it.last() as FieldInsnNode
val putstatic = match.last() as FieldInsnNode
flowObstructors.add(MemberRef(putstatic))
// remove initializer
it.forEach(method.instructions::remove)
match.forEach(method.instructions::remove)
// remove field
val owner = library[putstatic.owner]!!

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

Loading…
Cancel
Save