FileDocCategorySizeDatePackage
ASTParentsFirstIterator.javaAPI DocHibernate 3.2.51455Tue Jul 12 15:27:30 BST 2005org.hibernate.hql.ast.util

ASTParentsFirstIterator

public class ASTParentsFirstIterator extends Object implements Iterator
Depth first iteration of an ANTLR AST.
author
josh Sep 25, 2004 7:44:39 AM

Fields Summary
private antlr.collections.AST
next
private antlr.collections.AST
current
private antlr.collections.AST
tree
private LinkedList
parents
Constructors Summary
public ASTParentsFirstIterator(antlr.collections.AST tree)

		this.tree = next = tree;
	
Methods Summary
public booleanhasNext()

		return next != null;
	
public java.lang.Objectnext()

		return nextNode();
	
public antlr.collections.ASTnextNode()

		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;
	
private antlr.collections.ASTpop()

		if ( parents.size() == 0 ) {
			return null;
		}
		else {
			return ( AST ) parents.removeFirst();
		}
	
private voidpush(antlr.collections.AST parent)

		parents.addFirst( parent );
	
public voidremove()


	   
		throw new UnsupportedOperationException( "remove() is not supported" );