comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 21650:45ed86c4d127

Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
author Andreas Woess <andreas.woess@oracle.com>
date Mon, 01 Jun 2015 13:32:28 +0200
parents 286aef83a9a7
children f4cd6b1c2efc
comparison
equal deleted inserted replaced
21649:1c76a5662753 21650:45ed86c4d127
452 } 452 }
453 throw new IllegalArgumentException("Node " + parent + " is not a parent of " + child + "."); 453 throw new IllegalArgumentException("Node " + parent + " is not a parent of " + child + ".");
454 } 454 }
455 455
456 public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) { 456 public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) {
457 for (Node childNode : findNodeChildren(root)) { 457 if (clazz.isInstance(root)) {
458 if (clazz.isInstance(childNode)) { 458 return clazz.cast(root);
459 return clazz.cast(childNode); 459 }
460 } else { 460 for (Node child : root.getChildren()) {
461 T node = findFirstNodeInstance(childNode, clazz); 461 T node = findFirstNodeInstance(child, clazz);
462 if (node != null) { 462 if (node != null) {
463 return node; 463 return node;
464 }
465 } 464 }
466 } 465 }
467 return null; 466 return null;
468 } 467 }
469 468