@Test public void testIsDescendant() throws Exception { ScriptTree scriptTree = (ScriptTree) p.parse("function foo(){}"); FunctionDeclarationTree functionDeclarationTree = (FunctionDeclarationTree) scriptTree.items().items().get(0); assertThat(CheckUtils.isDescendant(functionDeclarationTree, scriptTree)).isTrue(); assertThat(CheckUtils.isDescendant(functionDeclarationTree.functionKeyword(), scriptTree)).isTrue(); assertThat(CheckUtils.isDescendant(functionDeclarationTree.parameterClause().closeParenthesisToken(), scriptTree)).isTrue(); assertThat(CheckUtils.isDescendant(scriptTree, functionDeclarationTree)).isFalse(); assertThat(CheckUtils.isDescendant(functionDeclarationTree.functionKeyword(), functionDeclarationTree.parameterClause())).isFalse(); }
public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null) { if (parent.equals(potentialParent)) { return true; } parent = parent.parent(); } return false; }
CheckUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null) { if (parent.equals(potentialParent)) { return true; } parent = parent.parent(); } return false; } }
CheckUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null) { if (parent.equals(potentialParent)) { return true; } parent = parent.parent(); } return false; } private  CheckUtils(); }
CheckUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null) { if (parent.equals(potentialParent)) { return true; } parent = parent.parent(); } return false; } private  CheckUtils(); static String asString(Tree tree); static ExpressionTree removeParenthesis(ExpressionTree expressionTree); static Tree parentIgnoreParentheses(Tree tree); static ControlFlowGraph buildControlFlowGraph(Tree tree); static boolean isDescendant(Tree tree, Tree potentialParent); @Nullable static Tree getFirstAncestor(Tree tree, Kinds... kind); static List<String> readLines(JavaScriptFile file); }
CheckUtils { public static boolean isDescendant(Tree tree, Tree potentialParent) { Tree parent = tree; while (parent != null) { if (parent.equals(potentialParent)) { return true; } parent = parent.parent(); } return false; } private  CheckUtils(); static String asString(Tree tree); static ExpressionTree removeParenthesis(ExpressionTree expressionTree); static Tree parentIgnoreParentheses(Tree tree); static ControlFlowGraph buildControlFlowGraph(Tree tree); static boolean isDescendant(Tree tree, Tree potentialParent); @Nullable static Tree getFirstAncestor(Tree tree, Kinds... kind); static List<String> readLines(JavaScriptFile file);  }