/** @since 0.8 or earlier */ public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) { if (clazz.isInstance(root)) { return clazz.cast(root); } for (Node child : root.getChildren()) { T node = findFirstNodeInstance(child, clazz); if (node != null) { return node; } } return null; }
/** @since 0.8 or earlier */ public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) { if (clazz.isInstance(root)) { return clazz.cast(root); } for (Node child : root.getChildren()) { T node = findFirstNodeInstance(child, clazz); if (node != null) { return node; } } return null; }
private void adoptUnadoptedHelper() { Iterable<Node> children = this.getChildren(); for (Node child : children) { if (child != null && child.getParent() == null) { this.adoptUnadoptedHelper(child); } } }
private void adoptHelper() { Iterable<Node> children = this.getChildren(); for (Node child : children) { if (child != null && child.getParent() != this) { this.adoptHelper(child); } } }
private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) { if (node == null) { return; } for (int i = 0; i < level; i++) { p.print(" "); } if (parent == null) { p.println(nodeName(node)); } else { p.print(getNodeFieldName(parent, node, "unknownField")); p.print(" = "); p.println(nodeName(node)); } for (Node child : node.getChildren()) { printCompactTree(p, node, child, level + 1); } p.flush(); }
private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) { if (node == null) { return; } for (int i = 0; i < level; i++) { p.print(" "); } if (parent == null) { p.println(nodeName(node)); } else { p.print(getNodeFieldName(parent, node, "unknownField")); p.print(" = "); p.println(nodeName(node)); } for (Node child : node.getChildren()) { printCompactTree(p, node, child, level + 1); } p.flush(); }
private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) { if (node == null) { return; } for (int i = 0; i < level; i++) { p.print(" "); } if (parent == null) { p.println(nodeName(node)); } else { p.print(getNodeFieldName(parent, node, "unknownField")); p.print(" = "); p.println(nodeName(node)); } for (Node child : node.getChildren()) { printCompactTree(p, node, child, level + 1); } p.flush(); }
private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) { if (node == null) { return; } if (parent == null) { // Add some preliminary information before starting with the root node final SourceSection sourceSection = node.getSourceSection(); if (sourceSection != null) { final String txt = sourceSection.getSource().getCode(); p.println("Full source len=(" + txt.length() + ") ___" + txt + "___"); p.println("AST source attribution:"); } } final StringBuilder sb = new StringBuilder(); for (int i = 0; i < level; i++) { sb.append("| "); } if (parent != null) { sb.append(getNodeFieldName(parent, node, "")); } sb.append(" (" + node.getClass().getSimpleName() + ") "); sb.append(printSyntaxTags(node)); sb.append(displaySourceAttribution(node)); p.println(sb.toString()); for (Node child : node.getChildren()) { printSourceAttributionTree(p, node, child, level + 1); } p.flush(); }
private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) { if (node == null) { return; } if (parent == null) { // Add some preliminary information before starting with the root node final SourceSection sourceSection = node.getSourceSection(); if (sourceSection != null) { final String txt = sourceSection.getSource().getCharacters().toString(); p.println("Full source len=(" + txt.length() + ") ___" + txt + "___"); p.println("AST source attribution:"); } } final StringBuilder sb = new StringBuilder(); for (int i = 0; i < level; i++) { sb.append("| "); } if (parent != null) { sb.append(getNodeFieldName(parent, node, "")); } sb.append(" (" + node.getClass().getSimpleName() + ") "); sb.append(printSyntaxTags(node)); sb.append(displaySourceAttribution(node)); p.println(sb.toString()); for (Node child : node.getChildren()) { printSourceAttributionTree(p, node, child, level + 1); } p.flush(); }
private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) { if (node == null) { return; } if (parent == null) { // Add some preliminary information before starting with the root node final SourceSection sourceSection = node.getSourceSection(); if (sourceSection != null) { final String txt = sourceSection.getSource().getCharacters().toString(); p.println("Full source len=(" + txt.length() + ") ___" + txt + "___"); p.println("AST source attribution:"); } } final StringBuilder sb = new StringBuilder(); for (int i = 0; i < level; i++) { sb.append("| "); } if (parent != null) { sb.append(getNodeFieldName(parent, node, "")); } sb.append(" (" + node.getClass().getSimpleName() + ") "); sb.append(printSyntaxTags(node)); sb.append(displaySourceAttribution(node)); p.println(sb.toString()); for (Node child : node.getChildren()) { printSourceAttributionTree(p, node, child, level + 1); } p.flush(); }
public static boolean verify(Node root) { Iterable<Node> children = root.getChildren(); for (Node child : children) { if (child != null) { if (child.getParent() != root) { throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root)); } verify(child); } } return true; }
/** @since 0.8 or earlier */ public static boolean verify(Node root) { Iterable<Node> children = root.getChildren(); for (Node child : children) { if (child != null) { if (child.getParent() != root) { throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root)); } verify(child); } } return true; }
/** @since 0.8 or earlier */ public static boolean verify(Node root) { Iterable<Node> children = root.getChildren(); for (Node child : children) { if (child != null) { if (child.getParent() != root) { throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root)); } verify(child); } } return true; }