Convert NewInstanceTransformer to Kotlin

bzip2
Graham 5 years ago
parent faec1f1a26
commit 320a8a7f8a
  1. 25
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NewInstanceTransformer.java
  2. 22
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NewInstanceTransformer.kt

@ -1,25 +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.MethodCallExpr;
import dev.openrs2.deob.ast.util.NodeUtils;
public final class NewInstanceTransformer extends Transformer {
@Override
public void transform(CompilationUnit unit) {
NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, MethodCallExpr.class, expr -> {
if (!expr.getNameAsString().equals("newInstance")) {
return;
}
expr.getScope().ifPresent(scope -> {
if (scope.isMethodCallExpr() && scope.asMethodCallExpr().getNameAsString().equals("getConstructor")) {
return;
}
expr.setScope(new MethodCallExpr(scope.clone(), "getDeclaredConstructor"));
});
});
}
}

@ -0,0 +1,22 @@
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.NodeUtils
class NewInstanceTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, MethodCallExpr::class.java) { expr ->
if (expr.nameAsString != "newInstance") {
return@walk
}
expr.scope.ifPresent { scope ->
if (!scope.isMethodCallExpr || scope.asMethodCallExpr().nameAsString != "getConstructor") {
expr.setScope(MethodCallExpr(scope.clone(), "getDeclaredConstructor"))
}
}
}
}
}
Loading…
Cancel
Save