本文整理了Java中org.antlr.runtime.tree.Tree.addChild()
方法的一些代码示例,展示了Tree.addChild()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tree.addChild()
方法的具体详情如下:
包路径:org.antlr.runtime.tree.Tree
类名称:Tree
方法名:addChild
[英]Add t as a child to this node. If t is null, do nothing. If t is nil, add all children of t to this' children.
[中]
代码示例来源:origin: antlr/antlr3
/** Add a child to the tree t. If child is a flat tree (a list), make all
* in list children of t. Warning: if t has no children, but child does
* and child isNil then you can decide it is ok to move children to t via
* t.children = child.children; i.e., without copying the array. Just
* make sure that this is consistent with have the user will build
* ASTs.
*/
@Override
public void addChild(Object t, Object child) {
if ( t!=null && child!=null ) {
((Tree)t).addChild((Tree)child);
}
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics
/** Add a child to the tree t. If child is a flat tree (a list), make all
* in list children of t. Warning: if t has no children, but child does
* and child isNil then you can decide it is ok to move children to t via
* t.children = child.children; i.e., without copying the array. Just
* make sure that this is consistent with have the user will build
* ASTs.
*/
public void addChild(Object t, Object child) {
if ( t!=null && child!=null ) {
((Tree)t).addChild((Tree)child);
}
}
代码示例来源:origin: antlr/antlr3
/** Add a child to the tree t. If child is a flat tree (a list), make all
* in list children of t. Warning: if t has no children, but child does
* and child isNil then you can decide it is ok to move children to t via
* t.children = child.children; i.e., without copying the array. Just
* make sure that this is consistent with have the user will build
* ASTs.
*/
@Override
public void addChild(Object t, Object child) {
if ( t!=null && child!=null ) {
((Tree)t).addChild((Tree)child);
}
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/** Add a child to the tree t. If child is a flat tree (a list), make all
* in list children of t. Warning: if t has no children, but child does
* and child isNil then you can decide it is ok to move children to t via
* t.children = child.children; i.e., without copying the array. Just
* make sure that this is consistent with have the user will build
* ASTs.
*/
@Override
public void addChild(Object t, Object child) {
if ( t!=null && child!=null ) {
((Tree)t).addChild((Tree)child);
}
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/** Add a child to the tree t. If child is a flat tree (a list), make all
* in list children of t. Warning: if t has no children, but child does
* and child isNil then you can decide it is ok to move children to t via
* t.children = child.children; i.e., without copying the array. Just
* make sure that this is consistent with have the user will build
* ASTs.
*/
@Override
public void addChild(Object t, Object child) {
if ( t!=null && child!=null ) {
((Tree)t).addChild((Tree)child);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr-runtime
/** Add a child to the tree t. If child is a flat tree (a list), make all
* in list children of t. Warning: if t has no children, but child does
* and child isNil then you can decide it is ok to move children to t via
* t.children = child.children; i.e., without copying the array. Just
* make sure that this is consistent with have the user will build
* ASTs.
*/
@Override
public void addChild(Object t, Object child) {
if ( t!=null && child!=null ) {
((Tree)t).addChild((Tree)child);
}
}
代码示例来源:origin: org.hibernate.jpql/hibernate-jpql-parser
private Tree generateUpdateStatementTree(Object updateKey, Object entityName, Object aliasClause, Object setClause, Object whereClause) {
Tree result = new CommonTree();
EntityNameTree entityNameTree = (EntityNameTree) entityName;
for ( int i = 0; i < entityNameTree.getEntityCount(); i++ ) {
Tree updateRoot = new CommonTree( (CommonTree) updateKey );
updateRoot.addChild( new EntityNameTree( entityNameTree, entityNameTree.getEntityName( i ) ) );
if ( aliasClause != null ) {
updateRoot.addChild( (Tree) aliasClause );
}
updateRoot.addChild( (Tree) setClause );
if ( whereClause != null ) {
updateRoot.addChild( (Tree) whereClause );
}
result.addChild( updateRoot );
}
return result;
}
代码示例来源:origin: org.hibernate.jpql/hibernate-jpql-parser
private Tree generateDeleteStatementTree(Object deleteKey, Object entityName, Object aliasClause, Object whereClause) {
Tree result = new CommonTree();
EntityNameTree entityNameTree = (EntityNameTree) entityName;
for ( int i = 0; i < entityNameTree.getEntityCount(); i++ ) {
Tree deleteRoot = new CommonTree( (CommonTree) deleteKey );
deleteRoot.addChild( new EntityNameTree( entityNameTree, entityNameTree.getEntityName( i ) ) );
if ( aliasClause != null ) {
deleteRoot.addChild( (Tree) aliasClause );
}
if ( whereClause != null ) {
deleteRoot.addChild( (Tree) whereClause );
}
result.addChild( deleteRoot );
}
return result;
}
代码示例来源:origin: stackoverflow.com
public void bfs(Tree parent){
Iterator<V> ni = neighbors((V) parent.value());
while(ni.hasNext()){
V next = ni.next();
GraphMatrixVertex<V> vert = dict.get(next);
if(!vert.isVisited()){
Tree newNode = new Tree(next);
parent.addChild(newNode);
newNode.bfs(this);
}
}
}
代码示例来源:origin: stackoverflow.com
int weight; // this should be you node traversal cost
public LinkedList<Tree> bfs(Tree parent){
Iterator<V> ni = neighbors((V) parent.value());
LinkedList bestPath = null;
int bestScore = 0xFFFFFFFF;
while(ni.hasNext()){
V next = ni.next();
GraphMatrixVertex<V> vert = dict.get(next);
if(!vert.isVisited()){
Tree newNode = new Tree(next);
parent.addChild(newNode);
LinkedList path = newNode.bfs(this);
if(newNode.weight < bestScore){
bestScore = weight;
bestPath = path;
}
}
}
weight = bestScore + this.weight;
bestPath.addFirst(this);
return path;
}
代码示例来源:origin: stackoverflow.com
private static Tree addNodeFixed(Tree tree, Label posTag, Label value, int index) {
Tree posNode = new LabeledScoredTreeNode(posTag);
posNode.setValue(posTag.value());
Tree valueNode = new LabeledScoredTreeNode(value);
valueNode.setValue(value.value());
posNode.addChild(valueNode);
tree.insertDtr(posNode, index);
return tree;
}
代码示例来源:origin: com.google.code.byteseek/byteseek
private Tree getChildList(Tree parent) {
// nodes with no token are "nil" nodes in antlr,
// which act as lists of children.
Tree listNode = new CommonTree();
for (int childIndex = 0; childIndex < parent.getChildCount(); childIndex++) {
listNode.addChild(parent.getChild(childIndex));
}
return listNode;
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
public void addEntityInGroupBy(String entityAlias) {
Tree groupBy = queryTree.getAstGroupByNode();
if (groupBy != null) {
groupBy.addChild(new PathNode(JPA2Lexer.T_SELECTED_ENTITY, entityAlias));
groupBy.freshenParentAndChildIndexes();
}
}
代码示例来源:origin: org.hibernate.jpql/hibernate-jpql-parser
private Tree generateSelecFromTree(Object selectClause, Object fromClause, List aliasList){
Tree result = new CommonTree( new CommonToken( SELECT_FROM, "SELECT_FROM" ) );
Tree selectTree = null;
result.addChild( (Tree) fromClause );
if (selectClause == null && aliasList != null && aliasList.size() > 0) {
selectTree = new CommonTree( new CommonToken( SELECT, "SELECT") );
Tree selectList = new CommonTree( new CommonToken( SELECT_LIST, "SELECT_LIST" ) );
for ( Iterator iterator = aliasList.iterator(); iterator.hasNext(); ) {
String aliasName = (String) iterator.next();
Tree selectElement = new CommonTree( new CommonToken( SELECT_ITEM, "SELECT_ITEM" ) );
Tree aliasElement = new CommonTree( new CommonToken( ALIAS_REF, aliasName ) );
selectElement.addChild( aliasElement );
selectList.addChild( selectElement );
}
selectTree.addChild( selectList );
}
else {
selectTree = (Tree) selectClause;
}
result.addChild( selectTree );
return result;
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
public void addOrderByIdIfNotExists(PathEntityReference idReference) {
Tree orderBy = queryTree.getAstTree().getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
if (orderBy != null) {
return;
}
orderBy = new OrderByNode(JPA2Lexer.T_ORDER_BY);
queryTree.getAstTree().addChild(orderBy);
queryTree.getAstTree().freshenParentAndChildIndexes();
orderBy.addChild(new CommonTree(new CommonToken(JPA2Lexer.ORDER, "order")));
orderBy.addChild(new CommonTree(new CommonToken(JPA2Lexer.BY, "by")));
OrderByFieldNode orderByField = new OrderByFieldNode(JPA2Lexer.T_ORDER_BY_FIELD);
orderByField.addChild(idReference.createNode());
orderByField.addChild(new CommonTree(new CommonToken(JPA2Lexer.DESC, "asc")));
orderByField.freshenParentAndChildIndexes();
orderBy.addChild(orderByField);
orderBy.freshenParentAndChildIndexes();
}
代码示例来源:origin: org.apache.lens/lens-cube
/**
*
* @param selectAST Outer query selectAST
* @param cubeql Cubequery Context
*
* Update the final alias in the outer select expressions
* 1. Replace queriedAlias with finalAlias if both are not same
* 2. If queriedAlias is missing add finalAlias as alias
*/
static void updateFinalAlias(ASTNode selectAST, CubeQueryContext cubeql) {
for (int i = 0; i < selectAST.getChildCount(); i++) {
ASTNode selectExpr = (ASTNode) selectAST.getChild(i);
ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, Identifier);
String finalAlias = cubeql.getSelectPhrases().get(i).getFinalAlias().replaceAll("`", "");
if (aliasNode != null) {
String queryAlias = aliasNode.getText();
if (!queryAlias.equals(finalAlias)) {
// replace the alias node
ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, finalAlias));
selectAST.getChild(i).replaceChildren(selectExpr.getChildCount() - 1,
selectExpr.getChildCount() - 1, newAliasNode);
}
} else {
// add column alias
ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, finalAlias));
selectAST.getChild(i).addChild(newAliasNode);
}
}
}
static Set<String> getColumnsFromCandidates(Collection<? extends Candidate> scSet) {
代码示例来源:origin: org.apache.lens/lens-cube
public static ASTNode getDotAST(String tableAlias, String fieldAlias) {
ASTNode child = new ASTNode(new CommonToken(DOT, "."));
child.addChild(new ASTNode(new CommonToken(TOK_TABLE_OR_COL, "TOK_TABLE_OR_COL")));
child.getChild(0).addChild(new ASTNode(new CommonToken(Identifier, tableAlias)));
child.addChild(new ASTNode(new CommonToken(Identifier, fieldAlias)));
return child;
}
代码示例来源:origin: apache/lens
public static ASTNode getDotAST(String tableAlias, String fieldAlias) {
ASTNode child = new ASTNode(new CommonToken(DOT, "."));
child.addChild(new ASTNode(new CommonToken(TOK_TABLE_OR_COL, "TOK_TABLE_OR_COL")));
child.getChild(0).addChild(new ASTNode(new CommonToken(Identifier, tableAlias)));
child.addChild(new ASTNode(new CommonToken(Identifier, fieldAlias)));
return child;
}
代码示例来源:origin: org.apache.lens/lens-cube
private void updateAnswerableSelectColumns() throws LensException {
// update select AST with selected fields
int currentChild = 0;
for (int i = 0; i < getCubeQueryContext().getSelectAST().getChildCount(); i++) {
ASTNode selectExpr = (ASTNode) queryAst.getSelectAST().getChild(currentChild);
Set<String> exprCols = HQLParser.getColsInExpr(getCubeQueryContext().getAliasForTableName(getCube()), selectExpr);
if (getStorageCandidate().getColumns().containsAll(exprCols)) {
ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, HiveParser.Identifier);
String alias = getCubeQueryContext().getSelectPhrases().get(i).getSelectAlias();
if (aliasNode != null) {
String queryAlias = aliasNode.getText();
if (!queryAlias.equals(alias)) {
// replace the alias node
ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias));
queryAst.getSelectAST().getChild(currentChild)
.replaceChildren(selectExpr.getChildCount() - 1, selectExpr.getChildCount() - 1, newAliasNode);
}
} else {
// add column alias
ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias));
queryAst.getSelectAST().getChild(currentChild).addChild(newAliasNode);
}
} else {
queryAst.getSelectAST().deleteChild(currentChild);
currentChild--;
}
currentChild++;
}
}
代码示例来源:origin: apache/lens
private void updateAnswerableSelectColumns() throws LensException {
// update select AST with selected fields
int currentChild = 0;
for (int i = 0; i < getCubeQueryContext().getSelectAST().getChildCount(); i++) {
ASTNode selectExpr = (ASTNode) queryAst.getSelectAST().getChild(currentChild);
Set<String> exprCols = HQLParser.getColsInExpr(getCubeQueryContext().getAliasForTableName(getCube()), selectExpr);
if (getStorageCandidate().getColumns().containsAll(exprCols)) {
ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, HiveParser.Identifier);
String alias = getCubeQueryContext().getSelectPhrases().get(i).getSelectAlias();
if (aliasNode != null) {
String queryAlias = aliasNode.getText();
if (!queryAlias.equals(alias)) {
// replace the alias node
ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias));
queryAst.getSelectAST().getChild(currentChild)
.replaceChildren(selectExpr.getChildCount() - 1, selectExpr.getChildCount() - 1, newAliasNode);
}
} else {
// add column alias
ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias));
queryAst.getSelectAST().getChild(currentChild).addChild(newAliasNode);
}
} else {
queryAst.getSelectAST().deleteChild(currentChild);
currentChild--;
}
currentChild++;
}
}
内容来源于网络,如有侵权,请联系作者删除!