當前位置: 首頁>>代碼示例>>Java>>正文


Java Tree.getChildCount方法代碼示例

本文整理匯總了Java中org.antlr.runtime.tree.Tree.getChildCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Tree.getChildCount方法的具體用法?Java Tree.getChildCount怎麽用?Java Tree.getChildCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.antlr.runtime.tree.Tree的用法示例。


在下文中一共展示了Tree.getChildCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: treeToString

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static String treeToString(Tree tree, int depth)
{
    if (tree.getChildCount() == 0) {
        return quotedString(tree.toString());
    }
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    sb.append(tree.toString());
    for (Tree t : children(tree)) {
        if (hasSubtree(t) && (leafCount(tree) > 2)) {
            sb.append("\n");
            sb.append(repeat("   ", depth));
        }
        else {
            sb.append(" ");
        }
        sb.append(treeToString(t, depth + 1));
    }
    sb.append(")");
    return sb.toString();
}
 
開發者ID:ajoabraham,項目名稱:hue,代碼行數:22,代碼來源:TreePrinter.java

示例2: getChildren

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
/**
 * Gets the children as a List
 * @param tree Tree
 * @return either emptyList or the children.
 */
public static List<Tree> getChildren(Tree tree)
{
    if (tree!=null && tree.getChildCount() > 0)
    {
        List<Tree> children = new ArrayList<Tree>(tree.getChildCount());
        for (int i = 0; i < tree.getChildCount(); i++) {
            Tree child = tree.getChild(i);
            children.add(child);
        }
        return children;
    }

    //Default
    return Collections.emptyList();
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:21,代碼來源:QueryHelper.java

示例3: replaceWithCount

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
public void replaceWithCount(EntityReference entityRef) {
    Tree selectedItems = tree.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEMS);
    boolean isDistinct = "DISTINCT".equalsIgnoreCase(selectedItems.getChild(0).getText());
    if (!(isDistinct && selectedItems.getChildCount() == 2 ||
            selectedItems.getChildCount() == 1))
        throw new IllegalStateException("Cannot replace with count if multiple fields selected");

    SelectedItemNode selectedItemNode;
    if (isDistinct)
        selectedItems.deleteChild(0);

    selectedItemNode = (SelectedItemNode) selectedItems.getChild(0);
    AggregateExpressionNode countNode = createCountNode(entityRef, isDistinct);
    selectedItemNode.deleteChild(0);
    selectedItemNode.addChild(countNode);

    Tree orderBy = tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
    if (orderBy != null) {
        tree.deleteChild(orderBy.getChildIndex());
    }
    tree.freshenParentAndChildIndexes();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:23,代碼來源:QueryTreeTransformer.java

示例4: getSelectedPathNode

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
public PathNode getSelectedPathNode() {
    Tree selectedItems = tree.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEMS);
    boolean isDistinct = "DISTINCT".equalsIgnoreCase(selectedItems.getChild(0).getText());
    SelectedItemNode selectedItemNode;
    if (isDistinct) {
        if (selectedItems.getChildCount() != 2)
            throw new IllegalStateException("Cannot select path node if multiple fields selected");
        selectedItemNode = (SelectedItemNode) selectedItems.getChild(1);
    } else {
        if (selectedItems.getChildCount() != 1)
            throw new IllegalStateException("Cannot select path node if multiple fields selected");
        selectedItemNode = (SelectedItemNode) selectedItems.getChild(0);
    }

    if (!(selectedItemNode.getChild(0) instanceof PathNode)) {
        throw new IllegalStateException("An entity path is assumed to be selected");
    }
    return (PathNode) selectedItemNode.getChild(0);
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:20,代碼來源:QueryTreeAnalyzer.java

示例5: executeHelp

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private void executeHelp(Tree tree)
{
    if (tree.getChildCount() > 0)
    {
        String token = tree.getChild(0).getText();
        for (CliCommandHelp ch : getHelp().commands)
        {
            if (token.equals(ch.name))
            {
                sessionState.out.println(ch.help);
                break;
            }
        }
    }
    else
    {
        sessionState.out.println(getHelp().help);
    }
}
 
開發者ID:vcostet,項目名稱:cassandra-kmean,代碼行數:20,代碼來源:CliClient.java

示例6: getInputRelation

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
/**
 * We have a very crude heuristic here. If we ever make it public, would
 * need to clean this up.
 * 
 * @param input
 * @return
 * @throws SQLException
 * @throws DataLawyerException
 */
private static Relation getInputRelation(Tree input, Counters counters,
		boolean aliased) throws SQLException, DataLawyerException {
	String relation_name = input.getText().toLowerCase();
	if (input.getChildCount() == 0) {
		String[] names = DB.getDB().separateSchemaAndName(relation_name);
		Index index = new Index(names[1], names[0], counters);
		if (aliased)
			return new OpAlias(index, "alias_" + index.getId());
		else
			return index;
	} else if (input.getChildCount() == 1) {
		Relation base_relation = getInputRelation(input.getChild(0),
				counters, false);
		return new OpAlias(base_relation, relation_name);
	} else {
		Relation base_query = convertASTtoRelation(input, counters);
		return new OpAlias(base_query, relation_name);
	}
}
 
開發者ID:prup,項目名稱:data-lawyer,代碼行數:29,代碼來源:ParserWrapper.java

示例7: children

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static List<Tree> children(Tree tree) {
    List<Tree> list = new ArrayList<Tree>();

    for (int i = 0; i < tree.getChildCount(); i++) {
        list.add(tree.getChild(i));
    }
    return list;
}
 
開發者ID:ajoabraham,項目名稱:hue,代碼行數:9,代碼來源:TreePatcher.java

示例8: treeToPureString

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
public static String treeToPureString(Tree tree) {
    if (tree.getChildCount() == 0) {
        return quotedString(tree.toString());
    }
    StringBuilder sb = new StringBuilder();

    for (Tree t : children(tree)) {
        sb.append(treeToPureString(t));
    }

    return sb.toString();
}
 
開發者ID:ajoabraham,項目名稱:hue,代碼行數:13,代碼來源:TreePrinter.java

示例9: hasSubtree

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static boolean hasSubtree(Tree tree)
{
    for (Tree t : children(tree)) {
        if (t.getChildCount() > 0) {
            return true;
        }
    }
    return false;
}
 
開發者ID:ajoabraham,項目名稱:hue,代碼行數:10,代碼來源:TreePrinter.java

示例10: leafCount

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static int leafCount(Tree tree)
{
    if (tree.getChildCount() == 0) {
        return 1;
    }

    int n = 0;
    for (Tree t : children(tree)) {
        n += leafCount(t);
    }
    return n;
}
 
開發者ID:ajoabraham,項目名稱:hue,代碼行數:13,代碼來源:TreePrinter.java

示例11: children

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static List<Tree> children(Tree tree)
   {
List<Tree> list = new ArrayList<Tree>();

       for (int i = 0; i < tree.getChildCount(); i++) {
           list.add(tree.getChild(i));
       }
       return list;
   }
 
開發者ID:ajoabraham,項目名稱:hue,代碼行數:10,代碼來源:TreePrinter.java

示例12: findFuzzy

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
static private Float findFuzzy(Tree node)
{
    for (int i = 0, l = node.getChildCount(); i < l; i++)
    {
        CommonTree child = (CommonTree) node.getChild(i);
        if (child.getType() == FTSParser.FUZZY)
        {
            String fuzzyString = child.getChild(0).getText();
            float fuzzy = Float.parseFloat(fuzzyString);
            return Float.valueOf(fuzzy);
        }
    }
    return null;
}
 
開發者ID:Alfresco,項目名稱:alfresco-data-model,代碼行數:15,代碼來源:FTSQueryParser.java

示例13: getLexerAction

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
public ActionAST getLexerAction() {
	Tree blk = getFirstChildWithType(ANTLRParser.BLOCK);
	if ( blk.getChildCount()==1 ) {
		Tree onlyAlt = blk.getChild(0);
		Tree lastChild = onlyAlt.getChild(onlyAlt.getChildCount()-1);
		if ( lastChild.getType()==ANTLRParser.ACTION ) {
			return (ActionAST)lastChild;
		}
	}
	return null;
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:12,代碼來源:RuleAST.java

示例14: executeShowSchema

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private void executeShowSchema(Tree statement) throws TException, InvalidRequestException
{
    if (!CliMain.isConnected())
        return;

    printCQL3TablesWarning("show schema");

    final List<KsDef> keyspaces = thriftClient.describe_keyspaces();
    Collections.sort(keyspaces, new KsDefNamesComparator());
    final String keyspaceName = (statement.getChildCount() == 0)
                            ? keySpace
                            : CliCompiler.getKeySpace(statement, keyspaces);

    Iterator<KsDef> ksIter;
    if (keyspaceName != null)
        ksIter = Collections2.filter(keyspaces, new Predicate<KsDef>()
        {
            public boolean apply(KsDef ksDef)
            {
                return keyspaceName.equals(ksDef.name);
            }
        }).iterator();
    else
        ksIter = keyspaces.iterator();

    while (ksIter.hasNext())
        showKeyspace(sessionState.out, ksIter.next());

    sessionState.out.flush();
}
 
開發者ID:vcostet,項目名稱:cassandra-kmean,代碼行數:31,代碼來源:CliClient.java

示例15: children

import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private List<Predicate<T>> children(Tree r) throws QueryParseException, IllegalArgumentException {
  List<Predicate<T>> p = new ArrayList<>(r.getChildCount());
  for (int i = 0; i < r.getChildCount(); i++) {
    p.add(toPredicate(r.getChild(i)));
  }
  return p;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:8,代碼來源:QueryBuilder.java


注:本文中的org.antlr.runtime.tree.Tree.getChildCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。