Java Code Examples for org.antlr.v4.runtime.tree.Tree#getChildCount()
The following examples show how to use
org.antlr.v4.runtime.tree.Tree#getChildCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Trees.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** Print out a whole tree in LISP form. Arg nodeTextProvider is used on the * node payloads to get the text for the nodes. * * @since 4.5.1 */ public static String toStringTree(Tree t, TreeTextProvider nodeTextProvider) { if ( t==null ) return "null"; String s = Utils.escapeWhitespace(nodeTextProvider.getText(t), false); if ( t.getChildCount()==0 ) return s; StringBuilder buf = new StringBuilder(); buf.append("("); s = Utils.escapeWhitespace(nodeTextProvider.getText(t), 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), nodeTextProvider)); } buf.append(")"); return buf.toString(); }
Example 2
Source File: HierarchyViewer.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 6 votes |
private MutableTreeNode wrap(final Tree tree) { if (tree == null) { return null; } DefaultMutableTreeNode root = new DefaultMutableTreeNode(tree) { @Override public String toString() { return treeTextProvider.getText((Tree) getUserObject()); } }; for (int i = 0; i < tree.getChildCount(); i++) { root.add(wrap(tree.getChild(i))); } return root; }
Example 3
Source File: TreeUtils.java From proleap-vb6-parser with MIT License | 5 votes |
/** * @see org.antlr.v4.runtime.tree.Trees.toStringTree(Tree, List<String>) */ public static String toStringTree(final Tree t, final List<String> ruleNames, final int depth) { String s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false); if (t.getChildCount() == 0) { return s; } final StringBuilder buf = new StringBuilder(); if (depth > 0) { buf.append(NEWLINE); } buf.append(indent(depth)); buf.append("("); s = Utils.escapeWhitespace(Trees.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, depth + 1)); } buf.append(")"); return buf.toString(); }
Example 4
Source File: ParsingUtils.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void _getAllLeaves(Tree t, List<TerminalNode> leaves) { int n = t.getChildCount(); if ( t instanceof TerminalNode ) { Token tok = ((TerminalNode)t).getSymbol(); if ( tok.getType() != Token.INVALID_TYPE ) { leaves.add((TerminalNode) t); } return; } for (int i = 0 ; i < n ; i++){ _getAllLeaves(t.getChild(i), leaves); } }
Example 5
Source File: TreeLayoutAdaptor.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean isLeaf(Tree node) { return node.getChildCount() == 0; }
Example 6
Source File: TreeViewer.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
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); } }