/** Return ordered list of all children of this node */ public static List<Tree> getChildren(Tree t) { List<Tree> kids = new ArrayList<Tree>(); for (int i=0; i<t.getChildCount(); i++) { kids.add(t.getChild(i)); } return kids; }
/** Print out a whole tree in LISP form. {@link #getNodeText} is used on the * node payloads to get the text for the nodes. */ public static String toStringTree(final Tree t, final List<String> ruleNames) { String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false); if ( t.getChildCount()==0 ) return s; StringBuilder buf = new StringBuilder(); buf.append("("); s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false); buf.append(s); buf.append(' '); for (int i = 0; i<t.getChildCount(); i++) { if ( i>0 ) buf.append(' '); buf.append(toStringTree(t.getChild(i), ruleNames)); } buf.append(")"); return buf.toString(); }
/** Return first node satisfying the pred * * @since 4.5.1 */ public static Tree findNodeSuchThat(Tree t, Predicate<Tree> pred) { if ( pred.test(t) ) return t; if ( t==null ) return null; int n = t.getChildCount(); for (int i = 0 ; i < n ; i++){ Tree u = findNodeSuchThat(t.getChild(i), pred); if ( u!=null ) return u; } return null; }
@Override public boolean hasNext() { return tree.getChildCount() > i; }
/** Return ordered list of all children of this node */ public static List<Tree> getChildren(Tree t) { List<Tree> kids = new ArrayList<Tree>(); for (int i=0; i<t.getChildCount(); i++) { kids.add(t.getChild(i)); } return kids; }
/** Return ordered list of all children of this node */ public static List<Tree> getChildren(Tree t) { List<Tree> kids = new ArrayList<Tree>(); for (int i=0; i<t.getChildCount(); i++) { kids.add(t.getChild(i)); } return kids; }
/** Return ordered list of all children of this node */ public static List<Tree> getChildren(Tree t) { List<Tree> kids = new ArrayList<Tree>(); for (int i=0; i<t.getChildCount(); i++) { kids.add(t.getChild(i)); } return kids; }
@Override public Tree getLastChild(Tree parentNode) { return parentNode.getChild(parentNode.getChildCount() - 1); }
private static RuleNode findChildRuleByType(Tree node, int ruleNum) { for (int i = 0; i < node.getChildCount(); i++) { Tree child = node.getChild(i); if (isRuleOfType(child, ruleNum)) { return (RuleNode) child; } } return null; }
private static RuleNode findChildRuleByType(Tree node, int ruleNum) { for (int i = 0; i < node.getChildCount(); i++) { Tree child = node.getChild(i); if (isRuleOfType(child, ruleNum)) { return (RuleNode) child; } } return null; }
public static void regExApplyActionRecursive(Tree node, Map<Tree, RowRecogExprNode> astRegExNodeMap, RegExAction action) { RowRecogExprNode expr = astRegExNodeMap.get(node); if (expr != null) { action.found(expr, astRegExNodeMap, node); return; } for (int i = 0; i < node.getChildCount(); i++) { regExApplyActionRecursive(node.getChild(i), astRegExNodeMap, action); } }
private static void recursiveFindRemoveChildExprNode(Tree node, Map<Tree, ExprNode> astExprNodeMap, ExprAction action) { ExprNode expr = astExprNodeMap.get(node); if (expr != null) { action.found(expr, astExprNodeMap, node); return; } for (int i = 0; i < node.getChildCount(); i++) { recursiveFindRemoveChildExprNode(node.getChild(i), astExprNodeMap, action); } }
private static void recursiveFindRemoveChildExprNode(Tree node, Map<Tree, ExprNode> astExprNodeMap, ExprAction action) { ExprNode expr = astExprNodeMap.get(node); if (expr != null) { action.found(expr, astExprNodeMap, node); return; } for (int i = 0; i < node.getChildCount(); i++) { recursiveFindRemoveChildExprNode(node.getChild(i), astExprNodeMap, action); } }
public static void _getAllLeaves(Tree t, List<? super Tree> leaves) { int n = t.getChildCount(); if ( t instanceof TerminalNode ) { Token tok = ((TerminalNode)t).getSymbol(); if ( tok.getType() != Token.INVALID_TYPE ) { leaves.add(t); } return; } for (int i = 0 ; i < n ; i++){ _getAllLeaves(t.getChild(i), leaves); } }
public static void patternCollectAddSubnodesAddParentNode(EvalForgeNode evalNode, Tree node, Map<Tree, EvalForgeNode> astPatternNodeMap) { if (evalNode == null) { throw ASTWalkException.from("Invalid null expression node for '" + ASTUtil.printNode(node) + "'"); } for (int i = 0; i < node.getChildCount(); i++) { Tree childNode = node.getChild(i); EvalForgeNode childEvalNode = patternGetRemoveTopNode(childNode, astPatternNodeMap); if (childEvalNode != null) { evalNode.addChildNode(childEvalNode); } } astPatternNodeMap.put(node, evalNode); }
public static void patternCollectAddSubnodesAddParentNode(EvalForgeNode evalNode, Tree node, Map<Tree, EvalForgeNode> astPatternNodeMap) { if (evalNode == null) { throw ASTWalkException.from("Invalid null expression node for '" + ASTUtil.printNode(node) + "'"); } for (int i = 0; i < node.getChildCount(); i++) { Tree childNode = node.getChild(i); EvalForgeNode childEvalNode = patternGetRemoveTopNode(childNode, astPatternNodeMap); if (childEvalNode != null) { evalNode.addChildNode(childEvalNode); } } astPatternNodeMap.put(node, evalNode); }
private static void fillTree(TreeNodeWrapper node, Tree tree, TreeViewer viewer) { if (tree == null) { return; } for (int i = 0; i < tree.getChildCount(); i++) { Tree childTree = tree.getChild(i); TreeNodeWrapper childNode = new TreeNodeWrapper(childTree, viewer); node.add(childNode); fillTree(childNode, childTree, viewer); } }
private static void fillTree(TreeNodeWrapper node, Tree tree, TreeViewer viewer) { if (tree == null) { return; } for (int i = 0; i < tree.getChildCount(); i++) { Tree childTree = tree.getChild(i); TreeNodeWrapper childNode = new TreeNodeWrapper(childTree, viewer); node.add(childNode); fillTree(childNode, childTree, viewer); } }
private static void fillTree(TreeNodeWrapper node, Tree tree, TreeViewer viewer) { if (tree == null) { return; } for (int i = 0; i < tree.getChildCount(); i++) { Tree childTree = tree.getChild(i); TreeNodeWrapper childNode = new TreeNodeWrapper(childTree, viewer); node.add(childNode); fillTree(childNode, childTree, viewer); } }
private static void fillTree(TreeNodeWrapper node, Tree tree, TreeViewer viewer) { if (tree == null) { return; } for (int i = 0; i < tree.getChildCount(); i++) { Tree childTree = tree.getChild(i); TreeNodeWrapper childNode = new TreeNodeWrapper(childTree, viewer); node.add(childNode); fillTree(childNode, childTree, viewer); } }