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


Java AST.getFirstChild方法代码示例

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


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

示例1: isFunctionName

import antlr.collections.AST; //导入方法依赖的package包/类
@Override
@SuppressWarnings("SimplifiableIfStatement")
protected boolean isFunctionName(AST ast) {
	/*
	 * Semantic predicate used to determine whether a given AST node represents a function call
	 */

	AST child = ast.getFirstChild();
	// assume it is a function if it has parameters
	if ( child != null && "{param list}".equals( child.getText() ) ) {
		return true;
	}

	// otherwise, in order for this to be a function logically it has to be a function that does not
	// have arguments.  So try to assert that using the registry of known functions
	final SQLFunction function = context.getSqlFunctionRegistry().findSQLFunction( ast.getText() );
	if ( function == null ) {
		// no registered function, so we cannot know for certain
		return false;
	}
	else {
		// if function.hasParenthesesIfNoArguments() is true, then assume the node is not a function
		return ! function.hasParenthesesIfNoArguments();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:OrderByFragmentParser.java

示例2: getIndexOfChild

import antlr.collections.AST; //导入方法依赖的package包/类
public int getIndexOfChild(Object parent, Object child) {
    if (parent == null || child == null) {
        throw new IllegalArgumentException("root or child is null");
    }
    AST p = (AST)parent;
    AST c = p.getFirstChild();
    if (c == null) {
        throw new ArrayIndexOutOfBoundsException("node has no children");
    }
    int i = 0;
    while (c != null && c != child) {
        c = c.getNextSibling();
        i++;
    }
    if (c == child) {
        return i;
    }
    throw new java.util.NoSuchElementException("node is not a child");
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:20,代码来源:JTreeASTModel.java

示例3: visitDepthFirst

import antlr.collections.AST; //导入方法依赖的package包/类
private void visitDepthFirst(AST ast) {
	if ( ast == null ) {
		return;
	}
	Deque<AST> stack = new ArrayDeque<AST>();
	stack.addLast( ast );
	while ( !stack.isEmpty() ) {
		ast = stack.removeLast();
		strategy.visit( ast );
		if ( ast.getNextSibling() != null ) {
			stack.addLast( ast.getNextSibling() );
		}
		if ( ast.getFirstChild() != null ) {
			stack.addLast( ast.getFirstChild() );
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:NodeTraverser.java

示例4: doWorkForFindAll

import antlr.collections.AST; //导入方法依赖的package包/类
private void doWorkForFindAll(Vector v, AST target, boolean partialMatch) {
    AST sibling;

    // Start walking sibling lists, looking for matches.
    siblingWalk:
    for (sibling = this;
         sibling != null;
         sibling = sibling.getNextSibling()) {
        if ((partialMatch && sibling.equalsTreePartial(target)) ||
            (!partialMatch && sibling.equalsTree(target))) {
            v.appendElement(sibling);
        }
        // regardless of match or not, check any children for matches
        if (sibling.getFirstChild() != null) {
            ((BaseAST)sibling.getFirstChild()).doWorkForFindAll(v, target, partialMatch);
        }
    }
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:19,代码来源:BaseAST.java

示例5: getChild

import antlr.collections.AST; //导入方法依赖的package包/类
public Object getChild(Object parent, int index) {
    if (parent == null) {
        return null;
    }
    AST p = (AST)parent;
    AST c = p.getFirstChild();
    if (c == null) {
        throw new ArrayIndexOutOfBoundsException("node has no children");
    }
    int i = 0;
    while (c != null && i < index) {
        c = c.getNextSibling();
        i++;
    }
    return c;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:17,代码来源:JTreeASTModel.java

示例6: dialectFunction

import antlr.collections.AST; //导入方法依赖的package包/类
private void dialectFunction(AST exprList) {
	function = getSessionFactoryHelper().findSQLFunction( methodName );
	if ( function != null ) {
		AST firstChild = exprList != null ? exprList.getFirstChild() : null;
		Type functionReturnType = getSessionFactoryHelper()
				.findFunctionReturnType( methodName, function, firstChild );
		setDataType( functionReturnType );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:MethodNode.java

示例7: getDataType

import antlr.collections.AST; //导入方法依赖的package包/类
public Type getDataType() {
	final AST expression = getFirstChild();
	// option is used to hold each WHEN/ELSE in turn
	AST option = expression.getNextSibling();
	while ( option != null ) {
		final AST result;
		if ( option.getType() == HqlSqlTokenTypes.WHEN ) {
			result = option.getFirstChild().getNextSibling();
		}
		else if ( option.getType() == HqlSqlTokenTypes.ELSE ) {
			result = option.getFirstChild();
		}
		else {
			throw new QueryException(
					"Unexpected node type :" +
							ASTUtil.getTokenTypeName( HqlSqlTokenTypes.class, option.getType() ) +
							"; expecting WHEN or ELSE"
			);
		}

		if ( SqlNode.class.isInstance( result ) ) {
			final Type nodeDataType = ( (SqlNode) result ).getDataType();
			if ( nodeDataType != null ) {
				return nodeDataType;
			}
		}

		option = option.getNextSibling();
	}

	throw new QueryException( "Could not determine data type for simple case statement" );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:SimpleCaseNode.java

示例8: toStringList

import antlr.collections.AST; //导入方法依赖的package包/类
/** Print out a child-sibling tree in LISP notation */
public String toStringList() {
    AST t = this;
    String ts = "";
    if (t.getFirstChild() != null) ts += " (";
    ts += " " + this.toString();
    if (t.getFirstChild() != null) {
        ts += ((BaseAST)t.getFirstChild()).toStringList();
    }
    if (t.getFirstChild() != null) ts += " )";
    if (t.getNextSibling() != null) {
        ts += ((BaseAST)t.getNextSibling()).toStringList();
    }
    return ts;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:16,代码来源:BaseAST.java

示例9: isLeaf

import antlr.collections.AST; //导入方法依赖的package包/类
public boolean isLeaf(Object node) {
    if (node == null) {
        throw new IllegalArgumentException("node is null");
    }
    AST t = (AST)node;
    return t.getFirstChild() == null;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:8,代码来源:JTreeASTModel.java

示例10: make

import antlr.collections.AST; //导入方法依赖的package包/类
/** Make a tree from a list of nodes.  The first element in the
 *  array is the root.  If the root is null, then the tree is
 *  a simple list not a tree.  Handles null children nodes correctly.
 *  For example, build(a, b, null, c) yields tree (a b c).  build(null,a,b)
 *  yields tree (nil a b).
 */
public AST make(AST[] nodes) {
    if (nodes == null || nodes.length == 0) return null;
    AST root = nodes[0];
    AST tail = null;
    if (root != null) {
        root.setFirstChild(null);	// don't leave any old pointers set
    }
    // link in children;
    for (int i = 1; i < nodes.length; i++) {
        if (nodes[i] == null) continue;	// ignore null nodes
        if (root == null) {
            // Set the root and set it up for a flat list
            root = tail = nodes[i];
        }
        else if (tail == null) {
            root.setFirstChild(nodes[i]);
            tail = root.getFirstChild();
        }
        else {
            tail.setNextSibling(nodes[i]);
            tail = tail.getNextSibling();
        }
        // Chase tail to last sibling
        while (tail.getNextSibling() != null) {
            tail = tail.getNextSibling();
        }
    }
    return root;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:36,代码来源:ASTFactory.java

示例11: findPreviousSibling

import antlr.collections.AST; //导入方法依赖的package包/类
/**
 * Find the previous sibling in the parent for the given child.
 *
 * @param parent the parent node
 * @param child the child to find the previous sibling of
 *
 * @return the previous sibling of the child
 */
public static AST findPreviousSibling(AST parent, AST child) {
	AST prev = null;
	AST n = parent.getFirstChild();
	while ( n != null ) {
		if ( n == child ) {
			return prev;
		}
		prev = n;
		n = n.getNextSibling();
	}
	throw new IllegalArgumentException( "Child not found in parent!" );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:ASTUtil.java

示例12: toStringTree

import antlr.collections.AST; //导入方法依赖的package包/类
public String toStringTree() {
    AST t = this;
    String ts = "";
    if (t.getFirstChild() != null) ts += " (";
    ts += " " + this.toString();
    if (t.getFirstChild() != null) {
        ts += ((BaseAST)t.getFirstChild()).toStringList();
    }
    if (t.getFirstChild() != null) ts += " )";
    return ts;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:12,代码来源:BaseAST.java

示例13: insertChild

import antlr.collections.AST; //导入方法依赖的package包/类
/**
 * Inserts the child as the first child of the parent, all other children are shifted over to the 'right'.
 *
 * @param parent the parent
 * @param child the new first child
 */
public static void insertChild(AST parent, AST child) {
	if ( parent.getFirstChild() == null ) {
		parent.setFirstChild( child );
	}
	else {
		AST n = parent.getFirstChild();
		parent.setFirstChild( child );
		child.setNextSibling( n );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ASTUtil.java

示例14: showAst

import antlr.collections.AST; //导入方法依赖的package包/类
private void showAst(ArrayList<AST> parents, PrintWriter pw, AST ast) {
	if ( ast == null ) {
		pw.println( "AST is null!" );
		return;
	}

	for ( AST parent : parents ) {
		if ( parent.getNextSibling() == null ) {

			pw.print( "   " );
		}
		else {
			pw.print( " | " );
		}
	}

	if ( ast.getNextSibling() == null ) {
		pw.print( " \\-" );
	}
	else {
		pw.print( " +-" );
	}

	showNode( pw, ast );

	ArrayList<AST> newParents = new ArrayList<AST>( parents );
	newParents.add( ast );
	for ( AST child = ast.getFirstChild(); child != null; child = child.getNextSibling() ) {
		showAst( newParents, pw, child );
	}
	newParents.clear();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:ASTPrinter.java

示例15: processEqualityExpression

import antlr.collections.AST; //导入方法依赖的package包/类
/**
 * Post process equality expressions, clean up the subtree.
 *
 * @param x The equality expression.
 *
 * @return AST - The clean sub-tree.
 */
@Override
public AST processEqualityExpression(AST x) {
	if ( x == null ) {
		LOG.processEqualityExpression();
		return null;
	}

	int type = x.getType();
	if ( type == EQ || type == NE ) {
		boolean negated = type == NE;
		if ( x.getNumberOfChildren() == 2 ) {
			AST a = x.getFirstChild();
			AST b = a.getNextSibling();
			// (EQ NULL b) => (IS_NULL b)
			if ( a.getType() == NULL && b.getType() != NULL ) {
				return createIsNullParent( b, negated );
			}
			// (EQ a NULL) => (IS_NULL a)
			else if ( b.getType() == NULL && a.getType() != NULL ) {
				return createIsNullParent( a, negated );
			}
			else if ( b.getType() == EMPTY ) {
				return processIsEmpty( a, negated );
			}
			else {
				return x;
			}
		}
		else {
			return x;
		}
	}
	else {
		return x;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:44,代码来源:HqlParser.java


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