本文整理汇总了Java中antlr.collections.AST类的典型用法代码示例。如果您正苦于以下问题:Java AST类的具体用法?Java AST怎么用?Java AST使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AST类属于antlr.collections包,在下文中一共展示了AST类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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() );
}
}
}
示例2: ASTFrame
import antlr.collections.AST; //导入依赖的package包/类
public ASTFrame(String lab, AST r) {
super(lab);
// Create the TreeSelectionListener
TreeSelectionListener listener = new MyTreeSelectionListener();
JTreeASTPanel tp = new JTreeASTPanel(new JTreeASTModel(r), null);
Container content = getContentPane();
content.add(tp, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Frame f = (Frame)e.getSource();
f.setVisible(false);
f.dispose();
// System.exit(0);
}
});
setSize(WIDTH, HEIGHT);
}
示例3: getOrdering
import antlr.collections.AST; //导入依赖的package包/类
/**
* Locate the specified <tt>ordering specification</tt>, if one.
*
* @return The <tt>ordering specification</tt>, or null if none was specified.
*/
public OrderingSpecification getOrdering() {
// IMPL NOTE : the ordering-spec would be either the 2nd or 3rd child (of the overall sort-spec), if it existed,
// depending on whether a collation-spec was specified.
AST possible = getSortKey().getNextSibling();
if ( possible == null ) {
// There was no sort-spec parts specified other then the sort-key so there can be no ordering-spec...
return null;
}
if ( OrderByTemplateTokenTypes.COLLATE == possible.getType() ) {
// the 2nd child was a collation-spec, so we need to check the 3rd child instead.
possible = possible.getNextSibling();
}
return possible != null && OrderByTemplateTokenTypes.ORDER_SPEC == possible.getType()
? ( OrderingSpecification ) possible
: null;
}
示例4: generatePositionalParameter
import antlr.collections.AST; //导入依赖的package包/类
@Override
protected AST generatePositionalParameter(AST inputNode) throws SemanticException {
if ( namedParameters.size() > 0 ) {
throw new SemanticException(
"cannot define positional parameter after any named parameters have been defined"
);
}
LOG.warnf(
"[DEPRECATION] Encountered positional parameter near line %s, column %s. Positional parameter " +
"are considered deprecated; use named parameters or JPA-style positional parameters instead.",
inputNode.getLine(),
inputNode.getColumn()
);
ParameterNode parameter = (ParameterNode) astFactory.create( PARAM, "?" );
PositionalParameterSpecification paramSpec = new PositionalParameterSpecification(
inputNode.getLine(),
inputNode.getColumn(),
positionalParameterCount++
);
parameter.setHqlParameterSpecification( paramSpec );
parameters.add( paramSpec );
return parameter;
}
示例5: createCollectionJoin
import antlr.collections.AST; //导入依赖的package包/类
private FromElement createCollectionJoin(JoinSequence collectionJoinSequence, String tableAlias)
throws SemanticException {
String text = queryableCollection.getTableName();
AST ast = createFromElement( text );
FromElement destination = (FromElement) ast;
Type elementType = queryableCollection.getElementType();
if ( elementType.isCollectionType() ) {
throw new SemanticException( "Collections of collections are not supported!" );
}
destination.initializeCollection( fromClause, classAlias, tableAlias );
destination.setType( JOIN_FRAGMENT ); // Tag this node as a JOIN.
destination.setIncludeSubclasses( false ); // Don't include subclasses in the join.
destination.setCollectionJoin( true ); // This is a clollection join.
destination.setJoinSequence( collectionJoinSequence );
destination.setOrigin( origin, false );
destination.setCollectionTableAlias( tableAlias );
// origin.addDestination( destination );
// This was the cause of HHH-242
// origin.setType( FROM_FRAGMENT ); // Set the parent node type so that the AST is properly formed.
origin.setText( "" ); // The destination node will have all the FROM text.
origin.setCollectionJoin( true ); // The parent node is a collection join too (voodoo - see JoinProcessor)
fromClause.addCollectionJoinFromElementByPath( path, destination );
fromClause.getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() );
return destination;
}
示例6: 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");
}
示例7: processConstant
import antlr.collections.AST; //导入依赖的package包/类
public void processConstant(AST constant, boolean resolveIdent) throws SemanticException {
// If the constant is an IDENT, figure out what it means...
boolean isIdent = ( constant.getType() == IDENT || constant.getType() == WEIRD_IDENT );
if ( resolveIdent && isIdent && isAlias( constant.getText() ) ) {
// IDENT is a class alias in the FROM.
IdentNode ident = (IdentNode) constant;
// Resolve to an identity column.
ident.resolve( false, true );
}
else {
// IDENT might be the name of a class.
Queryable queryable = walker.getSessionFactoryHelper().findQueryableUsingImports( constant.getText() );
if ( isIdent && queryable != null ) {
constant.setText( queryable.getDiscriminatorSQLValue() );
}
// Otherwise, it's a literal.
else {
processLiteral( constant );
}
}
}
示例8: collectSelectExpressions
import antlr.collections.AST; //导入依赖的package包/类
/**
* Returns an array of SelectExpressions gathered from the children of the given parent AST node.
*
* @return an array of SelectExpressions gathered from the children of the given parent AST node.
*/
public SelectExpression[] collectSelectExpressions() {
// Get the first child to be considered. Sub-classes may do this differently in order to skip nodes that
// are not select expressions (e.g. DISTINCT).
AST firstChild = getFirstSelectExpression();
ArrayList<SelectExpression> list = new ArrayList<SelectExpression>();
int p = 0;
for ( AST n = firstChild; n != null; n = n.getNextSibling() ) {
if ( n instanceof SelectExpression ) {
list.add( (SelectExpression) n );
}
else if ( n instanceof ParameterNode ) {
parameterPositions.add( p );
}
else {
throw new IllegalStateException(
"Unexpected AST: " + n.getClass().getName() + " "
+ new ASTPrinter( SqlTokenTypes.class ).showAsString( n, "" )
);
}
p++;
}
return list.toArray( new SelectExpression[list.size()] );
}
示例9: generateNamedParameter
import antlr.collections.AST; //导入依赖的package包/类
@Override
protected AST generateNamedParameter(AST delimiterNode, AST nameNode) throws SemanticException {
String name = nameNode.getText();
trackNamedParameterPositions( name );
// create the node initially with the param name so that it shows
// appropriately in the "original text" attribute
ParameterNode parameter = (ParameterNode) astFactory.create( NAMED_PARAM, name );
parameter.setText( "?" );
NamedParameterSpecification paramSpec = new NamedParameterSpecification(
delimiterNode.getLine(),
delimiterNode.getColumn(),
name
);
parameter.setHqlParameterSpecification( paramSpec );
parameters.add( paramSpec );
return parameter;
}
示例10: getWhereClause
import antlr.collections.AST; //导入依赖的package包/类
@Override
public final AST getWhereClause() {
if ( whereClause == null ) {
whereClause = locateWhereClause();
// If there is no WHERE node, make one.
if ( whereClause == null ) {
getLog().debug( "getWhereClause() : Creating a new WHERE clause..." );
whereClause = getWalker().getASTFactory().create( HqlSqlTokenTypes.WHERE, "WHERE" );
// inject the WHERE after the parent
AST parent = ASTUtil.findTypeInChildren( this, getWhereClauseParentTokenType() );
whereClause.setNextSibling( parent.getNextSibling() );
parent.setNextSibling( whereClause );
}
}
return whereClause;
}
示例11: nextNode
import antlr.collections.AST; //导入依赖的package包/类
public AST nextNode() {
AST current = next;
if ( next != null ) {
AST child = next.getFirstChild();
if ( child == null ) {
AST sibling = next.getNextSibling();
if ( sibling == null ) {
AST parent = pop();
while ( parent != null && parent.getNextSibling() == null ) {
parent = pop();
}
next = ( parent != null ) ? parent.getNextSibling() : null;
}
else {
next = sibling;
}
}
else {
if ( next != tree ) {
push( next );
}
next = child;
}
}
return current;
}
示例12: out
import antlr.collections.AST; //导入依赖的package包/类
@Override
protected void out(AST n) {
if ( n instanceof Node ) {
out( ( (Node) n ).getRenderText( sessionFactory ) );
}
else {
super.out( n );
}
if ( n instanceof ParameterNode ) {
collectedParameters.add( ( (ParameterNode) n ).getHqlParameterSpecification() );
}
else if ( n instanceof ParameterContainer ) {
if ( ( (ParameterContainer) n ).hasEmbeddedParameters() ) {
ParameterSpecification[] specifications = ( (ParameterContainer) n ).getEmbeddedParameters();
if ( specifications != null ) {
collectedParameters.addAll( Arrays.asList( specifications ) );
}
}
}
}
示例13: isNonQualifiedPropertyRef
import antlr.collections.AST; //导入依赖的package包/类
@Override
protected boolean isNonQualifiedPropertyRef(AST ident) {
final String identText = ident.getText();
if ( currentFromClause.isFromElementAlias( identText ) ) {
return false;
}
List fromElements = currentFromClause.getExplicitFromElements();
if ( fromElements.size() == 1 ) {
final FromElement fromElement = (FromElement) fromElements.get( 0 );
try {
LOG.tracev( "Attempting to resolve property [{0}] as a non-qualified ref", identText );
return fromElement.getPropertyMapping( identText ).toType( identText ) != null;
}
catch (QueryException e) {
// Should mean that no such property was found
}
}
return false;
}
示例14: resolveSelectExpression
import antlr.collections.AST; //导入依赖的package包/类
@Override
protected void resolveSelectExpression(AST node) throws SemanticException {
// This is called when it's time to fully resolve a path expression.
int type = node.getType();
switch ( type ) {
case DOT: {
DotNode dot = (DotNode) node;
dot.resolveSelectExpression();
break;
}
case ALIAS_REF: {
// Notify the FROM element that it is being referenced by the select.
FromReferenceNode aliasRefNode = (FromReferenceNode) node;
//aliasRefNode.resolve( false, false, aliasRefNode.getText() ); //TODO: is it kosher to do it here?
aliasRefNode.resolve( false, false ); //TODO: is it kosher to do it here?
FromElement fromElement = aliasRefNode.getFromElement();
if ( fromElement != null ) {
fromElement.setIncludeSubclasses( true );
}
break;
}
default: {
break;
}
}
}
示例15: next
import antlr.collections.AST; //导入依赖的package包/类
/** Find the next subtree with structure and token types equal to
* those of 'template'.
*/
public AST next(AST template) {
AST t = null;
AST sibling = null;
if (cursor == null) { // do nothing if no tree to work on
return null;
}
// Start walking sibling list looking for subtree matches.
for (; cursor != null; cursor = cursor.getNextSibling()) {
// as a quick optimization, check roots first.
if (cursor.getType() == template.getType()) {
// if roots match, do full match test on children.
if (cursor.getFirstChild() != null) {
if (isSubtree(cursor.getFirstChild(), template.getFirstChild())) {
return cursor;
}
}
}
}
return t;
}