diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt index f368596084..eee041ed17 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.Expression import com.github.javaparser.ast.expr.UnaryExpr @@ -12,7 +11,7 @@ import dev.openrs2.deob.ast.util.walk class AddSubTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr -> + unit.walk { expr: BinaryExpr -> val op = expr.operator val left = expr.left val right = expr.right diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BinaryExprOrderTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BinaryExprOrderTransformer.kt index f6ea3b783c..64f59a3d3a 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BinaryExprOrderTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BinaryExprOrderTransformer.kt @@ -1,14 +1,13 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import dev.openrs2.deob.ast.util.isString import dev.openrs2.deob.ast.util.walk class BinaryExprOrderTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr -> + unit.walk { expr: BinaryExpr -> val op = flip(expr.operator) ?: return@walk val type = expr.calculateResolvedType() diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt index ba1802adb3..e8e1701ba3 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.IntegerLiteralExpr import dev.openrs2.deob.ast.util.createLong @@ -10,7 +9,7 @@ import dev.openrs2.deob.ast.util.walk class BitMaskTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr -> + unit.walk { expr: BinaryExpr -> val shiftOp = expr.operator val left = expr.left val shamtExpr = expr.right diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt index 355cf10190..2ce1f82d15 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.Expression import com.github.javaparser.ast.expr.IntegerLiteralExpr @@ -12,7 +11,7 @@ import dev.openrs2.deob.ast.util.walk class ComplementTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr -> + unit.walk { expr: BinaryExpr -> val op = complement(expr.operator) ?: return@walk val left = expr.left diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/EncloseTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/EncloseTransformer.kt index 5a6c340ae5..21feaae973 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/EncloseTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/EncloseTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.EnclosedExpr import com.github.javaparser.ast.expr.Expression @@ -73,7 +72,7 @@ class EncloseTransformer : Transformer() { } override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: Expression -> + unit.walk { expr: Expression -> when { expr.isArrayAccessExpr -> { val accessExpr = expr.asArrayAccessExpr() diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt index 1d014417c5..54213cf571 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.stmt.ForStmt import dev.openrs2.deob.ast.util.hasSideEffects @@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk class ForLoopConditionTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ForStmt -> + unit.walk { stmt: ForStmt -> stmt.compare.ifPresent { compare -> if (!compare.isBinaryExpr) { return@ifPresent diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IdentityTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IdentityTransformer.kt index 772ab54ccf..c4fdd66275 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IdentityTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IdentityTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.Expression import com.github.javaparser.ast.expr.UnaryExpr @@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk class IdentityTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr -> + unit.walk { expr: BinaryExpr -> @Suppress("NON_EXHAUSTIVE_WHEN") when (expr.operator) { BinaryExpr.Operator.PLUS -> { diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt index a02b7a121c..efd005e11e 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.stmt.BlockStmt import com.github.javaparser.ast.stmt.IfStmt import com.github.javaparser.ast.stmt.Statement @@ -11,7 +10,7 @@ import dev.openrs2.deob.ast.util.walk class IfElseTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt -> + unit.walk { stmt: IfStmt -> stmt.elseStmt.ifPresent { elseStmt: Statement -> val condition = stmt.condition val thenStmt = stmt.thenStmt @@ -44,7 +43,7 @@ class IfElseTransformer : Transformer() { } } - unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt -> + unit.walk { stmt: IfStmt -> stmt.elseStmt.ifPresent { elseStmt -> if (isIf(elseStmt)) { stmt.setElseStmt(getIf(elseStmt)) @@ -74,7 +73,7 @@ class IfElseTransformer : Transformer() { * throw ...; * } */ - unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt -> + unit.walk { stmt: IfStmt -> stmt.elseStmt.ifPresent { elseStmt -> // match if (!elseStmt.isBlockStmt) { diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IncrementTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IncrementTransformer.kt index c25e7459f2..bd577826ab 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IncrementTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IncrementTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.UnaryExpr import com.github.javaparser.ast.stmt.ExpressionStmt import com.github.javaparser.ast.stmt.ForStmt @@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk class IncrementTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ExpressionStmt -> + unit.walk { stmt: ExpressionStmt -> if (!stmt.expression.isUnaryExpr) { return@walk } @@ -18,7 +17,7 @@ class IncrementTransformer : Transformer() { unaryExpr.operator = prefixToPostfix(unaryExpr.operator) } - unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ForStmt -> + unit.walk { stmt: ForStmt -> for (expr in stmt.update) { if (!expr.isUnaryExpr) { continue diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NegativeLiteralTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NegativeLiteralTransformer.kt index 621c227b6d..0cac0b7706 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NegativeLiteralTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NegativeLiteralTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.UnaryExpr import dev.openrs2.deob.ast.util.isIntegerOrLongLiteral import dev.openrs2.deob.ast.util.negate @@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk class NegativeLiteralTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: UnaryExpr -> + unit.walk { expr: UnaryExpr -> val operand = expr.expression if (!operand.isIntegerOrLongLiteral()) { return@walk diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NewInstanceTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NewInstanceTransformer.kt index 25e7cd24bf..f855f9eee3 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NewInstanceTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NewInstanceTransformer.kt @@ -1,13 +1,12 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.MethodCallExpr import dev.openrs2.deob.ast.util.walk class NewInstanceTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: MethodCallExpr -> + unit.walk { expr: MethodCallExpr -> if (expr.nameAsString != "newInstance") { return@walk } diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.kt index b38ccd7b7c..07adf92cc5 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.ConditionalExpr import dev.openrs2.deob.ast.util.countNots import dev.openrs2.deob.ast.util.not @@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk class TernaryTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: ConditionalExpr -> + unit.walk { expr: ConditionalExpr -> val condition = expr.condition val notCondition = condition.not() if (notCondition.countNots() >= condition.countNots()) { diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/UnencloseTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/UnencloseTransformer.kt index 294fee0bb1..07ee4849ef 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/UnencloseTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/UnencloseTransformer.kt @@ -1,13 +1,12 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.EnclosedExpr import dev.openrs2.deob.ast.util.walk class UnencloseTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: EnclosedExpr -> + unit.walk { expr: EnclosedExpr -> expr.replace(expr.inner.clone()) } } diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.kt index e93f9c7b44..e1658b4c1e 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.kt @@ -1,7 +1,6 @@ package dev.openrs2.deob.ast.transform import com.github.javaparser.ast.CompilationUnit -import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.MethodCallExpr import com.github.javaparser.ast.expr.ObjectCreationExpr import com.github.javaparser.ast.expr.TypeExpr @@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk class ValueOfTransformer : Transformer() { override fun transform(unit: CompilationUnit) { - unit.walk(Node.TreeTraversal.POSTORDER) { expr: ObjectCreationExpr -> + unit.walk { expr: ObjectCreationExpr -> if (expr.type.isBoxedType) { expr.replace(MethodCallExpr(TypeExpr(expr.type), "valueOf", expr.arguments)) } diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/util/NodeUtils.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/util/NodeUtils.kt index 4bd09b871d..2cae102e0f 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/util/NodeUtils.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/util/NodeUtils.kt @@ -1,10 +1,9 @@ package dev.openrs2.deob.ast.util import com.github.javaparser.ast.Node -import com.github.javaparser.ast.Node.TreeTraversal -inline fun Node.walk(traversal: TreeTraversal, crossinline consumer: (T) -> Unit) { - this.walk(traversal) { +inline fun Node.walk(crossinline consumer: (T) -> Unit) { + this.walk(Node.TreeTraversal.POSTORDER) { if (it is T) { consumer(it) }