private static Node findFirstNode(Node contextNode, Set<Class<? extends Tag>> tags) { Node[] first = new Node[]{null}; contextNode.accept(new NodeVisitor() { @Override public boolean visit(Node node) { if (isTaggedWith(node, tags)) { first[0] = node; return false; } return true; } }); return first[0]; }
public void probeAST(Node node) { node.accept(this); } }
private static Node findFirstNode(Node contextNode, Set<Class<? extends Tag>> tags) { Node[] first = new Node[]{null}; contextNode.accept(new NodeVisitor() { @Override public boolean visit(Node node) { if (isTaggedWith(node, tags)) { first[0] = node; return false; } return true; } }); return first[0]; }
public static <T> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { final List<T> nodeList = new ArrayList<>(); root.accept(new NodeVisitor() { public boolean visit(Node node) { if (clazz.isInstance(node)) { nodeList.add(clazz.cast(node)); } return true; } }); return nodeList; }
/** @since 0.8 or earlier */ public static <T> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { final List<T> nodeList = new ArrayList<>(); root.accept(new NodeVisitor() { public boolean visit(Node node) { if (clazz.isInstance(node)) { nodeList.add(clazz.cast(node)); } return true; } }); return nodeList; }
/** @since 0.8 or earlier */ public static <T> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { final List<T> nodeList = new ArrayList<>(); root.accept(new NodeVisitor() { public boolean visit(Node node) { if (clazz.isInstance(node)) { nodeList.add(clazz.cast(node)); } return true; } }); return nodeList; }
/** * Like {@link #findAllNodeInstances(Node, Class)} but do not visit children of found nodes. */ public static <T> List<T> findNodeInstancesShallow(final Node root, final Class<T> clazz) { final List<T> nodeList = new ArrayList<>(); root.accept(new NodeVisitor() { public boolean visit(Node node) { if (clazz.isInstance(node)) { nodeList.add(clazz.cast(node)); return false; } return true; } }); return nodeList; }
/** @since 0.8 or earlier */ public static int countNodes(Node root, NodeCountFilter filter) { NodeCounter counter = new NodeCounter(filter); root.accept(counter); return counter.count; }
/** @since 0.8 or earlier */ public static int countNodes(Node root, NodeCountFilter filter) { NodeCounter counter = new NodeCounter(filter); root.accept(counter); return counter.count; }
/** * Walks an AST, looking for the first node with an assigned {@link SourceSection} and returning * the {@link Source}. */ private static Source findSource(Node node) { final FindSourceVisitor visitor = new FindSourceVisitor(); node.accept(visitor); return visitor.source; }
public static int countNodes(Node root, NodeCountFilter filter) { NodeCounter counter = new NodeCounter(filter); root.accept(counter); return counter.count; }
public static int calculateNonTrivialNodes(Node node) { NonTrivialNodeCountVisitor visitor = new NonTrivialNodeCountVisitor(); node.accept(visitor); return visitor.nodeCount; }