comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 11622:ccf047a30f18

Truffle: NodeUtil.getNthParent.
author Chris Seaton <chris.seaton@oracle.com>
date Fri, 13 Sep 2013 13:02:40 +0100
parents 494b818b527c
children 136eaa90ef41 a21a54b7ead1
comparison
equal deleted inserted replaced
11621:46e708738717 11622:ccf047a30f18
421 T[] result = Arrays.copyOf(first, first.length + second.length); 421 T[] result = Arrays.copyOf(first, first.length + second.length);
422 System.arraycopy(second, 0, result, first.length, second.length); 422 System.arraycopy(second, 0, result, first.length, second.length);
423 return result; 423 return result;
424 } 424 }
425 425
426 /**
427 * Get the nth parent of a node, where the 0th parent is the node itself. Returns null if there
428 * are less than n ancestors.
429 */
430 public static Node getNthParent(Node node, int n) {
431 Node parent = node;
432
433 for (int i = 0; i < n; i++) {
434 parent = parent.getParent();
435
436 if (parent == null) {
437 return null;
438 }
439 }
440
441 return parent;
442 }
443
426 /** find annotation in class/interface hierarchy. */ 444 /** find annotation in class/interface hierarchy. */
427 public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) { 445 public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) {
428 if (clazz.getAnnotation(annotationClass) != null) { 446 if (clazz.getAnnotation(annotationClass) != null) {
429 return clazz.getAnnotation(annotationClass); 447 return clazz.getAnnotation(annotationClass);
430 } else { 448 } else {