@Test public void test_isDescendant() { Tree tree = PHPParserBuilder.createParser().parse("<?= for(;;) {} ?>"); StatementTree statementTree = ((CompilationUnitTree) tree).script().statements().get(0); assertThat(isDescendant(statementTree, tree)).isTrue(); assertThat(isDescendant(tree, statementTree)).isFalse(); assertThat(isDescendant(tree, tree)).isTrue(); assertThat(isDescendant(statementTree, statementTree)).isTrue(); }
public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null && !potentialParent.equals(parent)) { parent = parent.getParent(); } return potentialParent.equals(parent); }
TreeUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null && !potentialParent.equals(parent)) { parent = parent.getParent(); } return potentialParent.equals(parent); } }
TreeUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null && !potentialParent.equals(parent)) { parent = parent.getParent(); } return potentialParent.equals(parent); } private  TreeUtils(); }
TreeUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null && !potentialParent.equals(parent)) { parent = parent.getParent(); } return potentialParent.equals(parent); } private  TreeUtils(); static boolean isDescendant(Tree tree, Tree potentialParent); @CheckForNull static Tree findAncestorWithKind(Tree tree, Collection<Tree.Kind> kinds); static Stream<Tree> descendants(@Nullable Tree root); static Stream<T> descendants(@Nullable Tree root, Class<T> clazz); static Optional<Tree> firstDescendant(@Nullable Tree root, Predicate<Tree> predicate); static Optional<T> firstDescendant(Tree root, Class<T> clazz); }
TreeUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null && !potentialParent.equals(parent)) { parent = parent.getParent(); } return potentialParent.equals(parent); } private  TreeUtils(); static boolean isDescendant(Tree tree, Tree potentialParent); @CheckForNull static Tree findAncestorWithKind(Tree tree, Collection<Tree.Kind> kinds); static Stream<Tree> descendants(@Nullable Tree root); static Stream<T> descendants(@Nullable Tree root, Class<T> clazz); static Optional<Tree> firstDescendant(@Nullable Tree root, Predicate<Tree> predicate); static Optional<T> firstDescendant(Tree root, Class<T> clazz);  }