forked from openrs2/openrs2
This commit also changes walk() to be an extension function and use reified generics.bzip2
parent
9f09a81db1
commit
e3baede541
@ -1,20 +0,0 @@ |
||||
package dev.openrs2.deob.ast.util; |
||||
|
||||
import java.util.function.Consumer; |
||||
|
||||
import com.github.javaparser.ast.Node; |
||||
|
||||
public final class NodeUtils { |
||||
@SuppressWarnings("unchecked") |
||||
public static <T extends Node> void walk(Node node, Node.TreeTraversal traversal, Class<T> type, Consumer<T> consumer) { |
||||
node.walk(traversal, n -> { |
||||
if (type.isAssignableFrom(n.getClass())) { |
||||
consumer.accept((T) n); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private NodeUtils() { |
||||
/* empty */ |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package dev.openrs2.deob.ast.util |
||||
|
||||
import com.github.javaparser.ast.Node |
||||
import com.github.javaparser.ast.Node.TreeTraversal |
||||
|
||||
inline fun <reified T : Node> Node.walk(traversal: TreeTraversal, crossinline consumer: (T) -> Unit) { |
||||
this.walk(traversal) { |
||||
if (it is T) { |
||||
consumer(it) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue