Convert TernaryTransformer to Kotlin

bzip2
Graham 5 years ago
parent 38a3e752f9
commit faec1f1a26
  1. 27
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.java
  2. 27
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.kt

@ -1,27 +0,0 @@
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.ExprUtils;
import dev.openrs2.deob.ast.util.NodeUtils;
public final class TernaryTransformer extends Transformer {
@Override
public void transform(CompilationUnit unit) {
NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, ConditionalExpr.class, expr -> {
var condition = expr.getCondition();
var notCondition = ExprUtils.not(condition);
if (ExprUtils.countNots(notCondition) >= ExprUtils.countNots(condition)) {
return;
}
var thenExpr = expr.getThenExpr();
var elseExpr = expr.getElseExpr();
expr.setCondition(notCondition);
expr.setThenExpr(elseExpr.clone());
expr.setElseExpr(thenExpr.clone());
});
}
}

@ -0,0 +1,27 @@
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.ExprUtils
import dev.openrs2.deob.ast.util.NodeUtils
class TernaryTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, ConditionalExpr::class.java) { expr ->
val condition = expr.condition
val notCondition = ExprUtils.not(condition)
if (ExprUtils.countNots(notCondition) >= ExprUtils.countNots(condition)) {
return@walk
}
val thenExpr = expr.thenExpr
val elseExpr = expr.elseExpr
expr.condition = notCondition
expr.thenExpr = elseExpr.clone()
expr.elseExpr = thenExpr.clone()
}
}
}
Loading…
Cancel
Save