Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 16465:456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Thu, 10 Jul 2014 18:08:29 +0200 |
parents | 76081918079d |
children | d41922beb512 |
comparison
equal
deleted
inserted
replaced
16464:76081918079d | 16465:456abab80eb5 |
---|---|
540 } | 540 } |
541 } | 541 } |
542 return null; | 542 return null; |
543 } | 543 } |
544 | 544 |
545 public static <T extends Node> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { | 545 public static <T> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { |
546 final List<T> nodeList = new ArrayList<>(); | 546 final List<T> nodeList = new ArrayList<>(); |
547 root.accept(new NodeVisitor() { | 547 root.accept(new NodeVisitor() { |
548 | |
549 @SuppressWarnings("unchecked") | |
550 @Override | |
551 public boolean visit(Node node) { | 548 public boolean visit(Node node) { |
552 if (clazz.isInstance(node)) { | 549 if (clazz.isInstance(node)) { |
553 nodeList.add((T) node); | 550 nodeList.add(clazz.cast(node)); |
554 } | 551 } |
555 return true; | 552 return true; |
556 } | 553 } |
557 }); | 554 }); |
558 return nodeList; | 555 return nodeList; |
559 } | 556 } |
560 | 557 |
561 // Don't visit found node instances. | 558 /** |
562 public static <T extends Node> List<T> findNodeInstancesShallow(final Node root, final Class<T> clazz) { | 559 * Like {@link #findAllNodeInstances(Node, Class)} but do not visit children of found nodes. |
560 */ | |
561 public static <T> List<T> findNodeInstancesShallow(final Node root, final Class<T> clazz) { | |
563 final List<T> nodeList = new ArrayList<>(); | 562 final List<T> nodeList = new ArrayList<>(); |
564 root.accept(new NodeVisitor() { | 563 root.accept(new NodeVisitor() { |
565 | |
566 @SuppressWarnings("unchecked") | |
567 @Override | |
568 public boolean visit(Node node) { | 564 public boolean visit(Node node) { |
569 if (clazz.isInstance(node)) { | 565 if (clazz.isInstance(node)) { |
570 nodeList.add((T) node); | 566 nodeList.add(clazz.cast(node)); |
571 return false; | |
572 } | |
573 return true; | |
574 } | |
575 }); | |
576 return nodeList; | |
577 } | |
578 | |
579 /** Find node instances within current function only (not in nested functions). */ | |
580 public static <T extends Node> List<T> findNodeInstancesInFunction(final Node root, final Class<T> clazz) { | |
581 final List<T> nodeList = new ArrayList<>(); | |
582 root.accept(new NodeVisitor() { | |
583 | |
584 @SuppressWarnings("unchecked") | |
585 @Override | |
586 public boolean visit(Node node) { | |
587 if (clazz.isInstance(node)) { | |
588 nodeList.add((T) node); | |
589 } else if (node instanceof RootNode && node != root) { | |
590 return false; | |
591 } | |
592 return true; | |
593 } | |
594 }); | |
595 return nodeList; | |
596 } | |
597 | |
598 public static <I> List<I> findNodeInstancesInFunctionInterface(final Node root, final Class<I> clazz) { | |
599 final List<I> nodeList = new ArrayList<>(); | |
600 root.accept(new NodeVisitor() { | |
601 | |
602 @SuppressWarnings("unchecked") | |
603 @Override | |
604 public boolean visit(Node node) { | |
605 if (clazz.isInstance(node)) { | |
606 nodeList.add((I) node); | |
607 } else if (node instanceof RootNode && node != root) { | |
608 return false; | 567 return false; |
609 } | 568 } |
610 return true; | 569 return true; |
611 } | 570 } |
612 }); | 571 }); |