1
// $Id: ASTIterator.java 7460 2005-07-12 20:27:29Z steveebersole $
2
package org.hibernate.hql.ast.util;
4
import java.util.Iterator;
5
import java.util.LinkedList;
7
import antlr.collections.AST;
10
* Depth first iteration of an ANTLR AST.
12
* @author josh Sep 25, 2004 7:44:39 AM
14
public class ASTIterator implements Iterator {
15
private AST next, current;
16
private LinkedList parents = new LinkedList();
18
public void remove() {
19
throw new UnsupportedOperationException( "remove() is not supported" );
22
public boolean hasNext() {
26
public Object next() {
30
public ASTIterator(AST tree) {
35
public AST nextNode() {
38
AST nextSibling = next.getNextSibling();
39
if ( nextSibling == null ) {
51
while ( next != null && next.getFirstChild() != null ) {
53
next = next.getFirstChild();
57
private void push(AST parent) {
58
parents.addFirst( parent );
62
if ( parents.size() == 0 ) {
66
return ( AST ) parents.removeFirst();