|
|
@ -1,7 +1,6 @@ |
|
|
|
package dev.openrs2.deob.ast.transform |
|
|
|
package dev.openrs2.deob.ast.transform |
|
|
|
|
|
|
|
|
|
|
|
import com.github.javaparser.ast.CompilationUnit |
|
|
|
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.BlockStmt |
|
|
|
import com.github.javaparser.ast.stmt.IfStmt |
|
|
|
import com.github.javaparser.ast.stmt.IfStmt |
|
|
|
import com.github.javaparser.ast.stmt.Statement |
|
|
|
import com.github.javaparser.ast.stmt.Statement |
|
|
@ -11,7 +10,7 @@ import dev.openrs2.deob.ast.util.walk |
|
|
|
|
|
|
|
|
|
|
|
class IfElseTransformer : Transformer() { |
|
|
|
class IfElseTransformer : Transformer() { |
|
|
|
override fun transform(unit: CompilationUnit) { |
|
|
|
override fun transform(unit: CompilationUnit) { |
|
|
|
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt -> |
|
|
|
unit.walk { stmt: IfStmt -> |
|
|
|
stmt.elseStmt.ifPresent { elseStmt: Statement -> |
|
|
|
stmt.elseStmt.ifPresent { elseStmt: Statement -> |
|
|
|
val condition = stmt.condition |
|
|
|
val condition = stmt.condition |
|
|
|
val thenStmt = stmt.thenStmt |
|
|
|
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 -> |
|
|
|
stmt.elseStmt.ifPresent { elseStmt -> |
|
|
|
if (isIf(elseStmt)) { |
|
|
|
if (isIf(elseStmt)) { |
|
|
|
stmt.setElseStmt(getIf(elseStmt)) |
|
|
|
stmt.setElseStmt(getIf(elseStmt)) |
|
|
@ -74,7 +73,7 @@ class IfElseTransformer : Transformer() { |
|
|
|
* throw ...; |
|
|
|
* throw ...; |
|
|
|
* } |
|
|
|
* } |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt -> |
|
|
|
unit.walk { stmt: IfStmt -> |
|
|
|
stmt.elseStmt.ifPresent { elseStmt -> |
|
|
|
stmt.elseStmt.ifPresent { elseStmt -> |
|
|
|
// match |
|
|
|
// match |
|
|
|
if (!elseStmt.isBlockStmt) { |
|
|
|
if (!elseStmt.isBlockStmt) { |
|
|
|