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


Java Tree.addChild方法代码示例

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


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

示例1: patchTreeByString

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public static void patchTreeByString(CommonTree tree, List<String> columns, String goal) {
    if (tree.getChildCount() == 0) {
        // leaf
		if (columns.contains(tree.getText())) {
		    Tree parent = tree.getParent();

		    // only patch tree when it's QNAME node
		    if (parent.getText().equals("QNAME")) {
    		    Tree tmpTree = createGenericNode(goal);
    		    // remove QNAME at index 0
    		    tmpTree.deleteChild(0);
                tmpTree.setParent(tree.getParent());
                parent.deleteChild(0);
                parent.addChild(tmpTree);
                parent.addChild(tree);
    
    		    ((CommonTree)tmpTree).getToken().setText(goal);
    		    ((CommonTree)tmpTree).getToken().setType(tree.getType());
		    }
		}
		return;
    }

    // process children
    for (Tree t : children(tree)) {
        patchTreeByString((CommonTree)t, columns, goal);
    }

    return;
}
 
开发者ID:ajoabraham,项目名称:hue,代码行数:31,代码来源:TreePatcher.java

示例2: addEntityInGroupBy

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public void addEntityInGroupBy(String entityAlias) {
    Tree groupBy = tree.getFirstChildWithType(JPA2Lexer.T_GROUP_BY);
    if (groupBy != null) {
        groupBy.addChild(new PathNode(JPA2Lexer.T_SELECTED_ENTITY, entityAlias));
        groupBy.freshenParentAndChildIndexes();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:8,代码来源:QueryTreeTransformer.java

示例3: testPushPop

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public void testPushPop() throws Exception {
	// ^(101 ^(102 103) ^(104 105) ^(106 107) 108 109)
	// stream has 9 real + 8 nav nodes
	// Sequence of types: 101 DN 102 DN 103 UP 104 DN 105 UP 106 DN 107 UP 108 109 UP
	Tree r0 = new CommonTree(new CommonToken(101));
	Tree r1 = new CommonTree(new CommonToken(102));
	r1.addChild(new CommonTree(new CommonToken(103)));
	r0.addChild(r1);
	Tree r2 = new CommonTree(new CommonToken(104));
	r2.addChild(new CommonTree(new CommonToken(105)));
	r0.addChild(r2);
	Tree r3 = new CommonTree(new CommonToken(106));
	r3.addChild(new CommonTree(new CommonToken(107)));
	r0.addChild(r3);
	r0.addChild(new CommonTree(new CommonToken(108)));
	r0.addChild(new CommonTree(new CommonToken(109)));

	CommonTreeNodeStream stream = new CommonTreeNodeStream(r0);
	String expecting = " 101 2 102 2 103 3 104 2 105 3 106 2 107 3 108 109 3";
	String found = stream.toString();
	assertEquals(expecting, found);

	// Assume we want to hit node 107 and then "call 102" then return

	int indexOf102 = 2;
	int indexOf107 = 12;
	for (int k=1; k<=indexOf107; k++) { // consume til 107 node
		stream.consume();
	}
	// CALL 102
	assertEquals(107, ((Tree)stream.LT(1)).getType());
	stream.push(indexOf102);
	assertEquals(102, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 102
	assertEquals(Token.DOWN, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume DN
	assertEquals(103, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 103
	assertEquals(Token.UP, ((Tree)stream.LT(1)).getType());
	// RETURN
	stream.pop();
	assertEquals(107, ((Tree)stream.LT(1)).getType());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:44,代码来源:TestCommonTreeNodeStream.java

示例4: testNestedPushPop

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public void testNestedPushPop() throws Exception {
	// ^(101 ^(102 103) ^(104 105) ^(106 107) 108 109)
	// stream has 9 real + 8 nav nodes
	// Sequence of types: 101 DN 102 DN 103 UP 104 DN 105 UP 106 DN 107 UP 108 109 UP
	Tree r0 = new CommonTree(new CommonToken(101));
	Tree r1 = new CommonTree(new CommonToken(102));
	r1.addChild(new CommonTree(new CommonToken(103)));
	r0.addChild(r1);
	Tree r2 = new CommonTree(new CommonToken(104));
	r2.addChild(new CommonTree(new CommonToken(105)));
	r0.addChild(r2);
	Tree r3 = new CommonTree(new CommonToken(106));
	r3.addChild(new CommonTree(new CommonToken(107)));
	r0.addChild(r3);
	r0.addChild(new CommonTree(new CommonToken(108)));
	r0.addChild(new CommonTree(new CommonToken(109)));

	CommonTreeNodeStream stream = new CommonTreeNodeStream(r0);

	// Assume we want to hit node 107 and then "call 102", which
	// calls 104, then return

	int indexOf102 = 2;
	int indexOf107 = 12;
	for (int k=1; k<=indexOf107; k++) { // consume til 107 node
		stream.consume();
	}
	assertEquals(107, ((Tree)stream.LT(1)).getType());
	// CALL 102
	stream.push(indexOf102);
	assertEquals(102, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 102
	assertEquals(Token.DOWN, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume DN
	assertEquals(103, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 103

	// CALL 104
	int indexOf104 = 6;
	stream.push(indexOf104);
	assertEquals(104, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 102
	assertEquals(Token.DOWN, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume DN
	assertEquals(105, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 103
	assertEquals(Token.UP, ((Tree)stream.LT(1)).getType());
	// RETURN (to UP node in 102 subtree)
	stream.pop();

	assertEquals(Token.UP, ((Tree)stream.LT(1)).getType());
	// RETURN (to empty stack)
	stream.pop();
	assertEquals(107, ((Tree)stream.LT(1)).getType());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:56,代码来源:TestCommonTreeNodeStream.java

示例5: testPushPopFromEOF

import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public void testPushPopFromEOF() throws Exception {
	// ^(101 ^(102 103) ^(104 105) ^(106 107) 108 109)
	// stream has 9 real + 8 nav nodes
	// Sequence of types: 101 DN 102 DN 103 UP 104 DN 105 UP 106 DN 107 UP 108 109 UP
	Tree r0 = new CommonTree(new CommonToken(101));
	Tree r1 = new CommonTree(new CommonToken(102));
	r1.addChild(new CommonTree(new CommonToken(103)));
	r0.addChild(r1);
	Tree r2 = new CommonTree(new CommonToken(104));
	r2.addChild(new CommonTree(new CommonToken(105)));
	r0.addChild(r2);
	Tree r3 = new CommonTree(new CommonToken(106));
	r3.addChild(new CommonTree(new CommonToken(107)));
	r0.addChild(r3);
	r0.addChild(new CommonTree(new CommonToken(108)));
	r0.addChild(new CommonTree(new CommonToken(109)));

	CommonTreeNodeStream stream = new CommonTreeNodeStream(r0);

	while ( stream.LA(1)!=Token.EOF ) {
		stream.consume();
	}
	int indexOf102 = 2;
	int indexOf104 = 6;
	assertEquals(Token.EOF, ((Tree)stream.LT(1)).getType());

	// CALL 102
	stream.push(indexOf102);
	assertEquals(102, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 102
	assertEquals(Token.DOWN, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume DN
	assertEquals(103, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 103
	assertEquals(Token.UP, ((Tree)stream.LT(1)).getType());
	// RETURN (to empty stack)
	stream.pop();
	assertEquals(Token.EOF, ((Tree)stream.LT(1)).getType());

	// CALL 104
	stream.push(indexOf104);
	assertEquals(104, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 102
	assertEquals(Token.DOWN, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume DN
	assertEquals(105, ((Tree)stream.LT(1)).getType());
	stream.consume(); // consume 103
	assertEquals(Token.UP, ((Tree)stream.LT(1)).getType());
	// RETURN (to empty stack)
	stream.pop();
	assertEquals(Token.EOF, ((Tree)stream.LT(1)).getType());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:53,代码来源:TestCommonTreeNodeStream.java


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