Simplify else if chains in POSTORDER

This prevents us from missing some nested cases.
master
Graham 5 years ago
parent a5e9a788e8
commit 6742120ab6
  1. 4
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.java

@ -1,9 +1,11 @@
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.IfStmt; import com.github.javaparser.ast.stmt.IfStmt;
import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.Statement;
import dev.openrs2.deob.ast.util.ExprUtils; import dev.openrs2.deob.ast.util.ExprUtils;
import dev.openrs2.deob.ast.util.NodeUtils;
public final class IfElseTransformer extends Transformer { public final class IfElseTransformer extends Transformer {
private static boolean isIf(Statement stmt) { private static boolean isIf(Statement stmt) {
@ -64,7 +66,7 @@ public final class IfElseTransformer extends Transformer {
}); });
}); });
unit.findAll(IfStmt.class).forEach(stmt -> { NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, IfStmt.class, stmt -> {
stmt.getElseStmt().ifPresent(elseStmt -> { stmt.getElseStmt().ifPresent(elseStmt -> {
if (isIf(elseStmt)) { if (isIf(elseStmt)) {
stmt.setElseStmt(getIf(elseStmt)); stmt.setElseStmt(getIf(elseStmt));

Loading…
Cancel
Save