Methods Summary |
---|
public static void | appendSibling(antlr.collections.AST n, antlr.collections.AST s)
while ( n.getNextSibling() != null ) {
n = n.getNextSibling();
}
n.setNextSibling( s );
|
public static java.util.List | collectChildren(antlr.collections.AST root, org.hibernate.hql.ast.util.ASTUtil$FilterPredicate predicate)
// List children = new ArrayList();
// collectChildren( children, root, predicate );
// return children;
return new CollectingNodeVisitor( predicate ).collect( root );
|
private static void | collectChildren(java.util.List children, antlr.collections.AST root, org.hibernate.hql.ast.util.ASTUtil$FilterPredicate predicate)
for ( AST n = root.getFirstChild(); n != null; n = n.getNextSibling() ) {
if ( predicate == null || !predicate.exclude( n ) ) {
children.add( n );
}
collectChildren( children, n, predicate );
}
|
public static antlr.collections.AST | create(antlr.ASTFactory astFactory, int type, java.lang.String text)Creates a single node AST.
AST node = astFactory.create( type, text );
return node;
|
private static antlr.collections.impl.ASTArray | createAstArray(antlr.ASTFactory factory, int size, int parentType, java.lang.String parentText, antlr.collections.AST child1)
ASTArray array = new ASTArray( size );
array.add( factory.create( parentType, parentText ) );
array.add( child1 );
return array;
|
public static antlr.collections.AST | createBinarySubtree(antlr.ASTFactory factory, int parentType, java.lang.String parentText, antlr.collections.AST child1, antlr.collections.AST child2)Creates a 'binary operator' subtree, given the information about the
parent and the two child nodex.
ASTArray array = createAstArray( factory, 3, parentType, parentText, child1 );
array.add( child2 );
return factory.make( array );
|
public static antlr.collections.AST | createParent(antlr.ASTFactory factory, int parentType, java.lang.String parentText, antlr.collections.AST child)Creates a single parent of the specified child (i.e. a 'unary operator'
subtree).
ASTArray array = createAstArray( factory, 2, parentType, parentText, child );
return factory.make( array );
|
public static antlr.collections.AST | createSibling(antlr.ASTFactory astFactory, int type, java.lang.String text, antlr.collections.AST prevSibling)Creates a single node AST as a sibling.
AST node = astFactory.create( type, text );
node.setNextSibling( prevSibling.getNextSibling() );
prevSibling.setNextSibling( node );
return node;
|
public static antlr.collections.AST | createTree(antlr.ASTFactory factory, antlr.collections.AST[] nestedChildren)
AST[] array = new AST[2];
int limit = nestedChildren.length - 1;
for ( int i = limit; i >= 0; i-- ) {
if ( i != limit ) {
array[1] = nestedChildren[i + 1];
array[0] = nestedChildren[i];
factory.make( array );
}
}
return array[0];
|
public static antlr.collections.AST | findPreviousSibling(antlr.collections.AST parent, antlr.collections.AST child)Find the previous sibling in the parent for the given 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!" );
|
public static antlr.collections.AST | findTypeInChildren(antlr.collections.AST parent, int type)Finds the first node of the specified type in the chain of children.
AST n = parent.getFirstChild();
while ( n != null && n.getType() != type ) {
n = n.getNextSibling();
}
return n;
|
public static java.lang.String | getDebugString(antlr.collections.AST n)Returns the 'list' representation with some brackets around it for debugging.
StringBuffer buf = new StringBuffer();
buf.append( "[ " );
buf.append( ( n == null ) ? "{null}" : n.toStringTree() );
buf.append( " ]" );
return buf.toString();
|
public static antlr.collections.AST | getLastChild(antlr.collections.AST n)Returns the last direct child of 'n'.
return getLastSibling( n.getFirstChild() );
|
private static antlr.collections.AST | getLastSibling(antlr.collections.AST a)Returns the last sibling of 'a'.
AST last = null;
while ( a != null ) {
last = a;
a = a.getNextSibling();
}
return last;
|
public static java.lang.String | getPathText(antlr.collections.AST n)
StringBuffer buf = new StringBuffer();
getPathText( buf, n );
return buf.toString();
|
private static void | getPathText(java.lang.StringBuffer buf, antlr.collections.AST n)
AST firstChild = n.getFirstChild();
// If the node has a first child, recurse into the first child.
if ( firstChild != null ) {
getPathText( buf, firstChild );
}
// Append the text of the current node.
buf.append( n.getText() );
// If there is a second child (RHS), recurse into that child.
if ( firstChild != null && firstChild.getNextSibling() != null ) {
getPathText( buf, firstChild.getNextSibling() );
}
|
public static boolean | hasExactlyOneChild(antlr.collections.AST n)
return n != null && n.getFirstChild() != null && n.getFirstChild().getNextSibling() == null;
|
public static void | insertChild(antlr.collections.AST parent, antlr.collections.AST child)Inserts the child as the first child of the parent, all other children are shifted over to the 'right'.
if ( parent.getFirstChild() == null ) {
parent.setFirstChild( child );
}
else {
AST n = parent.getFirstChild();
parent.setFirstChild( child );
child.setNextSibling( n );
}
|
public static antlr.collections.AST | insertSibling(antlr.collections.AST node, antlr.collections.AST prevSibling)
node.setNextSibling( prevSibling.getNextSibling() );
prevSibling.setNextSibling( node );
return node;
|
public static boolean | isDirectChild(antlr.collections.AST fixture, antlr.collections.AST test)Determine if a given node (test) is a direct (throtle to one level down)
child of another given node (fixture).
AST n = fixture.getFirstChild();
while ( n != null ) {
if ( n == test ) {
return true;
}
n = n.getNextSibling();
}
return false;
|
public static boolean | isSubtreeChild(antlr.collections.AST fixture, antlr.collections.AST test)Determine if a given node (test) is contained anywhere in the subtree
of another given node (fixture).
AST n = fixture.getFirstChild();
while ( n != null ) {
if ( n == test ) {
return true;
}
if ( n.getFirstChild() != null && isSubtreeChild( n, test ) ) {
return true;
}
n = n.getNextSibling();
}
return false;
|
public static void | makeSiblingOfParent(antlr.collections.AST parent, antlr.collections.AST child)Makes the child node a sibling of the parent, reconnecting all siblings.
AST prev = findPreviousSibling( parent, child );
if ( prev != null ) {
prev.setNextSibling( child.getNextSibling() );
}
else { // child == parent.getFirstChild()
parent.setFirstChild( child.getNextSibling() );
}
child.setNextSibling( parent.getNextSibling() );
parent.setNextSibling( child );
|