com.oracle.truffle.api.nodes.Node.getChildren()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(699)

本文整理了Java中com.oracle.truffle.api.nodes.Node.getChildren()方法的一些代码示例,展示了Node.getChildren()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getChildren()方法的具体详情如下:
包路径:com.oracle.truffle.api.nodes.Node
类名称:Node
方法名:getChildren

Node.getChildren介绍

[英]Iterator over the children of this node.
[中]迭代此节点的子节点。

代码示例

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. /** @since 0.8 or earlier */
  2. public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) {
  3. if (clazz.isInstance(root)) {
  4. return clazz.cast(root);
  5. }
  6. for (Node child : root.getChildren()) {
  7. T node = findFirstNodeInstance(child, clazz);
  8. if (node != null) {
  9. return node;
  10. }
  11. }
  12. return null;
  13. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. /** @since 0.8 or earlier */
  2. public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) {
  3. if (clazz.isInstance(root)) {
  4. return clazz.cast(root);
  5. }
  6. for (Node child : root.getChildren()) {
  7. T node = findFirstNodeInstance(child, clazz);
  8. if (node != null) {
  9. return node;
  10. }
  11. }
  12. return null;
  13. }

代码示例来源:origin: com.oracle/truffle

  1. private void adoptUnadoptedHelper() {
  2. Iterable<Node> children = this.getChildren();
  3. for (Node child : children) {
  4. if (child != null && child.getParent() == null) {
  5. this.adoptUnadoptedHelper(child);
  6. }
  7. }
  8. }

代码示例来源:origin: com.oracle/truffle

  1. private void adoptHelper() {
  2. Iterable<Node> children = this.getChildren();
  3. for (Node child : children) {
  4. if (child != null && child.getParent() != this) {
  5. this.adoptHelper(child);
  6. }
  7. }
  8. }

代码示例来源:origin: com.oracle/truffle

  1. private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) {
  2. if (node == null) {
  3. return;
  4. }
  5. for (int i = 0; i < level; i++) {
  6. p.print(" ");
  7. }
  8. if (parent == null) {
  9. p.println(nodeName(node));
  10. } else {
  11. p.print(getNodeFieldName(parent, node, "unknownField"));
  12. p.print(" = ");
  13. p.println(nodeName(node));
  14. }
  15. for (Node child : node.getChildren()) {
  16. printCompactTree(p, node, child, level + 1);
  17. }
  18. p.flush();
  19. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) {
  2. if (node == null) {
  3. return;
  4. }
  5. for (int i = 0; i < level; i++) {
  6. p.print(" ");
  7. }
  8. if (parent == null) {
  9. p.println(nodeName(node));
  10. } else {
  11. p.print(getNodeFieldName(parent, node, "unknownField"));
  12. p.print(" = ");
  13. p.println(nodeName(node));
  14. }
  15. for (Node child : node.getChildren()) {
  16. printCompactTree(p, node, child, level + 1);
  17. }
  18. p.flush();
  19. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) {
  2. if (node == null) {
  3. return;
  4. }
  5. for (int i = 0; i < level; i++) {
  6. p.print(" ");
  7. }
  8. if (parent == null) {
  9. p.println(nodeName(node));
  10. } else {
  11. p.print(getNodeFieldName(parent, node, "unknownField"));
  12. p.print(" = ");
  13. p.println(nodeName(node));
  14. }
  15. for (Node child : node.getChildren()) {
  16. printCompactTree(p, node, child, level + 1);
  17. }
  18. p.flush();
  19. }

代码示例来源:origin: com.oracle/truffle

  1. private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) {
  2. if (node == null) {
  3. return;
  4. }
  5. if (parent == null) {
  6. // Add some preliminary information before starting with the root node
  7. final SourceSection sourceSection = node.getSourceSection();
  8. if (sourceSection != null) {
  9. final String txt = sourceSection.getSource().getCode();
  10. p.println("Full source len=(" + txt.length() + ") ___" + txt + "___");
  11. p.println("AST source attribution:");
  12. }
  13. }
  14. final StringBuilder sb = new StringBuilder();
  15. for (int i = 0; i < level; i++) {
  16. sb.append("| ");
  17. }
  18. if (parent != null) {
  19. sb.append(getNodeFieldName(parent, node, ""));
  20. }
  21. sb.append(" (" + node.getClass().getSimpleName() + ") ");
  22. sb.append(printSyntaxTags(node));
  23. sb.append(displaySourceAttribution(node));
  24. p.println(sb.toString());
  25. for (Node child : node.getChildren()) {
  26. printSourceAttributionTree(p, node, child, level + 1);
  27. }
  28. p.flush();
  29. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) {
  2. if (node == null) {
  3. return;
  4. }
  5. if (parent == null) {
  6. // Add some preliminary information before starting with the root node
  7. final SourceSection sourceSection = node.getSourceSection();
  8. if (sourceSection != null) {
  9. final String txt = sourceSection.getSource().getCharacters().toString();
  10. p.println("Full source len=(" + txt.length() + ") ___" + txt + "___");
  11. p.println("AST source attribution:");
  12. }
  13. }
  14. final StringBuilder sb = new StringBuilder();
  15. for (int i = 0; i < level; i++) {
  16. sb.append("| ");
  17. }
  18. if (parent != null) {
  19. sb.append(getNodeFieldName(parent, node, ""));
  20. }
  21. sb.append(" (" + node.getClass().getSimpleName() + ") ");
  22. sb.append(printSyntaxTags(node));
  23. sb.append(displaySourceAttribution(node));
  24. p.println(sb.toString());
  25. for (Node child : node.getChildren()) {
  26. printSourceAttributionTree(p, node, child, level + 1);
  27. }
  28. p.flush();
  29. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) {
  2. if (node == null) {
  3. return;
  4. }
  5. if (parent == null) {
  6. // Add some preliminary information before starting with the root node
  7. final SourceSection sourceSection = node.getSourceSection();
  8. if (sourceSection != null) {
  9. final String txt = sourceSection.getSource().getCharacters().toString();
  10. p.println("Full source len=(" + txt.length() + ") ___" + txt + "___");
  11. p.println("AST source attribution:");
  12. }
  13. }
  14. final StringBuilder sb = new StringBuilder();
  15. for (int i = 0; i < level; i++) {
  16. sb.append("| ");
  17. }
  18. if (parent != null) {
  19. sb.append(getNodeFieldName(parent, node, ""));
  20. }
  21. sb.append(" (" + node.getClass().getSimpleName() + ") ");
  22. sb.append(printSyntaxTags(node));
  23. sb.append(displaySourceAttribution(node));
  24. p.println(sb.toString());
  25. for (Node child : node.getChildren()) {
  26. printSourceAttributionTree(p, node, child, level + 1);
  27. }
  28. p.flush();
  29. }

代码示例来源:origin: com.oracle/truffle

  1. public static boolean verify(Node root) {
  2. Iterable<Node> children = root.getChildren();
  3. for (Node child : children) {
  4. if (child != null) {
  5. if (child.getParent() != root) {
  6. throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root));
  7. }
  8. verify(child);
  9. }
  10. }
  11. return true;
  12. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. /** @since 0.8 or earlier */
  2. public static boolean verify(Node root) {
  3. Iterable<Node> children = root.getChildren();
  4. for (Node child : children) {
  5. if (child != null) {
  6. if (child.getParent() != root) {
  7. throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root));
  8. }
  9. verify(child);
  10. }
  11. }
  12. return true;
  13. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. /** @since 0.8 or earlier */
  2. public static boolean verify(Node root) {
  3. Iterable<Node> children = root.getChildren();
  4. for (Node child : children) {
  5. if (child != null) {
  6. if (child.getParent() != root) {
  7. throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root));
  8. }
  9. verify(child);
  10. }
  11. }
  12. return true;
  13. }

相关文章