本文整理汇总了Java中org.antlr.v4.runtime.tree.Tree.getChildCount方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.getChildCount方法的具体用法?Java Tree.getChildCount怎么用?Java Tree.getChildCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.tree.Tree
的用法示例。
在下文中一共展示了Tree.getChildCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toStringTree
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
/** 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();
}
示例2: toStringTree
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
private String toStringTree(Tree tree, List<String> ruleNames) {
String s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
if(tree.getChildCount() == 0) return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
buf.append(s);
buf.append(' ');
for(int i = 0; i < tree.getChildCount(); i++)
{
if(i > 0)
buf.append(' ');
buf.append(toStringTree(tree.getChild(i), ruleNames));
}
buf.append(")");
return buf.toString();
}
示例3: dumpAST
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
public static void dumpAST(PrintWriter printer, Tree ast, int ident) {
char[] identChars = new char[ident];
Arrays.fill(identChars, ' ');
if (ast == null) {
renderNode(identChars, null, printer);
return;
}
for (int i = 0; i < ast.getChildCount(); i++) {
Tree node = ast.getChild(i);
if (node == null) {
throw new NullPointerException("Null AST node");
}
renderNode(identChars, node, printer);
dumpAST(printer, node, ident + 2);
}
}
示例4: toStringTree
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
private String toStringTree(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
if (t.getChildCount() == 0) {
return Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
}
StringBuilder buf = new StringBuilder();
buf.append(" ( ");
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
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();
}
示例5: wrap
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
private MutableTreeNode wrap(final Tree tree) {
if (tree == null) {
return null;
}
DefaultMutableTreeNode root = new DefaultMutableTreeNode(tree) {
@Override
public String toString() {
String name = treeTextProvider.getText((Tree) getUserObject());
if (tree instanceof TerminalNode) {
return name.equals("<EOF>") ? name : "\"" + name + "\"";
}
return name;
}
};
for (int i = 0; i < tree.getChildCount(); i++) {
root.add(wrap(tree.getChild(i)));
}
return root;
}
示例6: _getAllLeaves
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
public static void _getAllLeaves(Tree t, List<? super Tree> leaves,
final int startIndex,
final int stopIndex)
{
int n = t.getChildCount();
if ( n==0 ) { // must be leaf
Token tok = ((TerminalNode)t).getSymbol();
int i = tok.getTokenIndex();
if ( i>=startIndex && i<=stopIndex && tok.getType() != Token.INVALID_TYPE ) {
leaves.add(t);
}
return;
}
for (int i = 0 ; i < n ; i++){
_getAllLeaves(t.getChild(i), leaves, startIndex, stopIndex);
}
}
示例7: patternCollectAddSubnodesAddParentNode
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
public static void patternCollectAddSubnodesAddParentNode(EvalFactoryNode evalNode, Tree node, Map<Tree, EvalFactoryNode> 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);
EvalFactoryNode childEvalNode = patternGetRemoveTopNode(childNode, astPatternNodeMap);
if (childEvalNode != null) {
evalNode.addChildNode(childEvalNode);
}
}
astPatternNodeMap.put(node, evalNode);
}
示例8: patternGetRemoveTopNode
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
public static EvalFactoryNode patternGetRemoveTopNode(Tree node, Map<Tree, EvalFactoryNode> astPatternNodeMap) {
EvalFactoryNode pattern = astPatternNodeMap.get(node);
if (pattern != null) {
astPatternNodeMap.remove(node);
return pattern;
}
for (int i = 0; i < node.getChildCount(); i++) {
pattern = patternGetRemoveTopNode(node.getChild(i), astPatternNodeMap);
if (pattern != null) {
return pattern;
}
}
return null;
}
示例9: regExApplyActionRecursive
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
public static void regExApplyActionRecursive(Tree node, Map<Tree, RowRegexExprNode> astRegExNodeMap, RegExAction action) {
RowRegexExprNode 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);
}
}
示例10: recursiveFindRemoveChildExprNode
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
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);
}
}
示例11: regExGetRemoveTopNode
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
public static RowRegexExprNode regExGetRemoveTopNode(Tree node, Map<Tree, RowRegexExprNode> astRowRegexNodeMap) {
RowRegexExprNode regex = astRowRegexNodeMap.get(node);
if (regex != null) {
astRowRegexNodeMap.remove(node);
return regex;
}
for (int i = 0; i < node.getChildCount(); i++) {
regex = regExGetRemoveTopNode(node.getChild(i), astRowRegexNodeMap);
if (regex != null) {
return regex;
}
}
return null;
}
示例12: findChildRuleByType
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
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;
}
示例13: process
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
private String process(final Tree t, final List<String> ruleNames) {
if (t.getChildCount() == 0) return Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
StringBuilder sb = new StringBuilder();
sb.append(lead(level));
level++;
String s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
sb.append(s + ' ');
for (int i = 0; i < t.getChildCount(); i++) {
sb.append(process(t.getChild(i), ruleNames));
}
level--;
sb.append(lead(level));
return sb.toString();
}
示例14: countTree
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
/** Recursive call to compute the complexity of this (sub)tree. */
protected void countTree(@NotNull Tree t, Long depth) {
if (treeDepth < depth) treeDepth = depth;
for (int i = 0; i<t.getChildCount(); i++) {
countTree(t.getChild(i), depth+1);
numNodes++;
}
}
示例15: printTree
import org.antlr.v4.runtime.tree.Tree; //导入方法依赖的package包/类
/**
* Recursive call to print out a sub-tree in indented form.
* {@link #appendNodeText} is used on the node payloads to get the text for the
* nodes. Detect parse trees and extract data appropriately.
*/
protected void printTree(@NotNull Tree t, String indent) {
buf.append("\n");
buf.append(indent);
appendNodeText(t);
String childIndent = newIndent(indent);
for (int i = 0; i<t.getChildCount(); i++) {
printTree(t.getChild(i), childIndent);
}
}