当前位置: 首页>>代码示例>>Java>>正文


Java Tree.getChild方法代码示例

本文整理汇总了Java中org.antlr.runtime.tree.Tree.getChild方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.getChild方法的具体用法?Java Tree.getChild怎么用?Java Tree.getChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.runtime.tree.Tree的用法示例。


在下文中一共展示了Tree.getChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: hasImmediateRecursiveRuleRefs

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
/**
 * Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*)))
 * Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))
 */
public static boolean hasImmediateRecursiveRuleRefs(GrammarAST t, String ruleName) {
	if ( t==null ) return false;
	GrammarAST blk = (GrammarAST)t.getFirstChildWithType(BLOCK);
	if ( blk==null ) return false;
	int n = blk.getChildren().size();
	for (int i = 0; i < n; i++) {
		GrammarAST alt = (GrammarAST)blk.getChildren().get(i);
		Tree first = alt.getChild(0);
		if ( first==null ) continue;
		if (first.getType() == ELEMENT_OPTIONS) {
			first = alt.getChild(1);
			if (first == null) {
				continue;
			}
		}
		if ( first.getType()==RULE_REF && first.getText().equals(ruleName) ) return true;
		Tree rref = first.getChild(1);
		if ( rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName) ) return true;
	}
	return false;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:26,代码来源:LeftRecursiveRuleAnalyzer.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: scrubTree

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private void scrubTree(Tree tree) {
        // The top-level tree often has wrong position info, so start one down from the top
        for (int i = tree.getChildCount() - 1; i >= 0; i--) {
            Tree child = tree.getChild(i);
            if (child.getTokenStartIndex() > child.getTokenStopIndex()) {
                System.out.println("Deleting node " + child);
                tree.deleteChild(i);
                continue;
            }
            if (child.getTokenStartIndex() < 0) {
//                System.out.println("Deleting node " + child);
//                tree.deleteChild(i);
                continue;
            }
            scrubTree(child);
            if (child.getTokenStartIndex() < tree.getTokenStartIndex()) {
                tree.setTokenStartIndex(child.getTokenStartIndex());
            }
            if (child.getTokenStopIndex() > tree.getTokenStopIndex()) {
                tree.setTokenStopIndex(child.getTokenStopIndex());
            }
        }
    }
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:24,代码来源:F3Parser.java

示例6: 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

示例7: 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

示例8: replaceOrderBy

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
@Test
public void replaceOrderBy() throws RecognitionException {
    DomainModel model = prepareDomainModel();

    QueryTreeTransformer qa = new QueryTreeTransformer();
    qa.prepare(model, "select c from Car c order by c.model");

    CommonTree tree = qa.getTree();
    CommonTree orderByNode = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
    Tree orderByField = orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY_FIELD);
    assertEquals(1, orderByField.getChildCount());
    PathNode pathNode = (PathNode) orderByField.getChild(0);
    assertEquals("c", pathNode.getEntityVariableName());
    assertEquals("model", pathNode.getChild(0).getText());

    pathNode = new PathNode(JPA2Lexer.T_SELECTED_FIELD, "c");
    pathNode.addDefaultChild("regNumber");
    qa.replaceOrderBy(true, new PathEntityReference(pathNode, "Car"));

    orderByNode = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
    orderByField = orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY_FIELD);
    assertEquals(2, orderByField.getChildCount());
    pathNode = (PathNode) orderByField.getChild(0);
    assertEquals("c", pathNode.getEntityVariableName());
    assertEquals("regNumber", pathNode.getChild(0).getText());
    assertEquals("desc", orderByField.getChild(1).getText());
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:28,代码来源:QueryAnalyzerTest.java

示例9: replaceWithCount

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
@Test
public void replaceWithCount() throws RecognitionException {
    DomainModel model = prepareDomainModel();

    QueryTreeTransformer qa = new QueryTreeTransformer();
    qa.prepare(model, "select c from Car c order by c.model");

    CommonTree tree = qa.getTree();
    CommonTree selectedItems = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEMS);
    Tree selectedItem = selectedItems.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEM);
    PathNode pathNode = (PathNode) selectedItem.getChild(0);
    assertEquals("c", pathNode.getEntityVariableName());
    assertEquals(0, pathNode.getChildCount());
    CommonTree orderByNode = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);

    assertNotNull(orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY_FIELD));

    qa.replaceWithCount(new VariableEntityReference("Car", "c"));

    assertTrue(selectedItem.getChild(0) instanceof AggregateExpressionNode);
    AggregateExpressionNode countExpr = (AggregateExpressionNode) selectedItem.getChild(0);

    assertEquals("count", countExpr.getChild(0).getText());
    assertEquals("c", countExpr.getChild(2).getText());
    assertEquals(4, countExpr.getChildCount());
    assertNull(orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:28,代码来源:QueryAnalyzerTest.java

示例10: replaceWithCount_distinct

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
@Test
public void replaceWithCount_distinct() throws RecognitionException {
    DomainModel model = prepareDomainModel();

    QueryTreeTransformer qa = new QueryTreeTransformer();
    qa.prepare(model, "select distinct d from Car c, in(c.drivers) d order by d.name");

    CommonTree tree = qa.getTree();
    CommonTree selectedItems = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEMS);
    Tree selectedItem = selectedItems.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEM);
    PathNode pathNode = (PathNode) selectedItem.getChild(0);
    assertEquals("d", pathNode.getEntityVariableName());
    assertEquals(0, pathNode.getChildCount());
    CommonTree orderByNode = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);

    assertNotNull(orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY_FIELD));

    qa.replaceWithCount(new VariableEntityReference("Driver", "d"));

    selectedItems = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEMS);
    assertEquals(1, selectedItems.getChildCount());
    selectedItem = selectedItems.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEM);
    assertTrue(selectedItem.getChild(0) instanceof AggregateExpressionNode);
    AggregateExpressionNode countExpr = (AggregateExpressionNode) selectedItem.getChild(0);

    assertEquals("count", countExpr.getChild(0).getText());
    assertEquals("distinct", countExpr.getChild(2).getText());
    assertEquals("d", countExpr.getChild(3).getText());
    assertEquals(5, countExpr.getChildCount());
    assertNull(orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:32,代码来源:QueryAnalyzerTest.java

示例11: executeCount

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private void executeCount(Tree statement)
        throws TException, InvalidRequestException, UnavailableException, TimedOutException
{
    if (!CliMain.isConnected() || !hasKeySpace())
        return;

    Tree columnFamilySpec = statement.getChild(0);

    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, currentCfDefs());
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

    ColumnParent colParent = new ColumnParent(columnFamily).setSuper_column((ByteBuffer) null);

    if (columnSpecCnt != 0)
    {
        Tree columnTree = columnFamilySpec.getChild(2);

        byte[] superColumn = (columnTree.getType() == CliParser.FUNCTION_CALL)
                              ? convertValueByFunction(columnTree, null, null).array()
                              : columnNameAsByteArray(CliCompiler.getColumn(columnFamilySpec, 0), columnFamily);

        colParent = new ColumnParent(columnFamily).setSuper_column(superColumn);
    }

    SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, Integer.MAX_VALUE);
    SlicePredicate predicate = new SlicePredicate().setColumn_names(null).setSlice_range(range);

    int count = thriftClient.get_count(getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1)), colParent, predicate, consistencyLevel);
    sessionState.out.printf("%d cells%n", count);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:31,代码来源:CliClient.java

示例12: executeConnect

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private void executeConnect(Tree statement)
{
    Tree idList = statement.getChild(0);
    int portNumber = Integer.parseInt(statement.getChild(1).getText());

    StringBuilder hostName = new StringBuilder();
    int idCount = idList.getChildCount();
    for (int idx = 0; idx < idCount; idx++)
    {
        hostName.append(idList.getChild(idx).getText());
    }

    // disconnect current connection, if any.
    // This is a no-op, if you aren't currently connected.
    CliMain.disconnect();

    // now, connect to the newly specified host name and port
    sessionState.hostName = hostName.toString();
    sessionState.thriftPort = portNumber;

    // if we have user name and password
    if (statement.getChildCount() == 4)
    {
        sessionState.username = statement.getChild(2).getText();
        sessionState.password = CliUtils.unescapeSQLString(statement.getChild(3).getText());
    }

    CliMain.connect(sessionState.hostName, sessionState.thriftPort);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:30,代码来源:CliClient.java

示例13: getStrategyOptionsFromTree

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
/**
 * Used to get Map of the provided options by create/update keyspace commands
 * @param options - tree representing options
 * @return Map - strategy_options map
 */
private Map<String, String> getStrategyOptionsFromTree(Tree options)
{
    //Check for old [{}] syntax
    if (options.getText().equalsIgnoreCase("ARRAY"))
    {
        System.err.println("WARNING: [{}] strategy_options syntax is deprecated, please use {}");

        if (options.getChildCount() == 0)
            return Collections.EMPTY_MAP;

        return getStrategyOptionsFromTree(options.getChild(0));
    }

    // this map will be returned
    Map<String, String> strategyOptions = new HashMap<String, String>();

    // each child node is ^(PAIR $key $value)
    for (int j = 0; j < options.getChildCount(); j++)
    {
        Tree optionPair = options.getChild(j);

        // current $key
        String key = CliUtils.unescapeSQLString(optionPair.getChild(0).getText());
        // current $value
        String val = CliUtils.unescapeSQLString(optionPair.getChild(1).getText());

        strategyOptions.put(key, val);
    }

    return strategyOptions;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:37,代码来源:CliClient.java

示例14: operator

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private Predicate<T> operator(String name, Tree val) throws QueryParseException {
  switch (val.getType()) {
      // Expand multiple values, "foo:(a b c)", as though they were written
      // out with the longer form, "foo:a foo:b foo:c".
      //
    case AND:
    case OR:
      {
        List<Predicate<T>> p = new ArrayList<>(val.getChildCount());
        for (int i = 0; i < val.getChildCount(); i++) {
          final Tree c = val.getChild(i);
          if (c.getType() != DEFAULT_FIELD) {
            throw error("Nested operator not expected: " + c);
          }
          p.add(operator(name, onlyChildOf(c)));
        }
        return val.getType() == AND ? and(p) : or(p);
      }

    case SINGLE_WORD:
    case EXACT_PHRASE:
      if (val.getChildCount() != 0) {
        throw error("Expected no children under: " + val);
      }
      return operator(name, val.getText());

    default:
      throw error("Unsupported node in operator " + name + ": " + val);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:31,代码来源:QueryBuilder.java

示例15: assertSingleWord

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private static void assertSingleWord(String name, String value, Tree r) {
  assertEquals(QueryParser.FIELD_NAME, r.getType());
  assertEquals(name, r.getText());
  assertEquals(1, r.getChildCount());
  final Tree c = r.getChild(0);
  assertEquals(QueryParser.SINGLE_WORD, c.getType());
  assertEquals(value, c.getText());
  assertEquals(0, c.getChildCount());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:10,代码来源:QueryParserTest.java


注:本文中的org.antlr.runtime.tree.Tree.getChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。