KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > ast > util > ASTAppender


1 // $Id: ASTAppender.java,v 1.1 2005/07/12 20:27:17 steveebersole Exp $
2
package org.hibernate.hql.ast.util;
3
4 import antlr.ASTFactory;
5 import antlr.collections.AST;
6
7 /**
8  * Appends child nodes to a parent efficiently.
9  *
10  * @author josh Jul 24, 2004 8:28:23 AM
11  */

12 public class ASTAppender {
13     private AST parent;
14     private AST last;
15     private ASTFactory factory;
16
17     public ASTAppender(ASTFactory factory, AST parent) {
18         this( parent );
19         this.factory = factory;
20     }
21
22     public ASTAppender(AST parent) {
23         this.parent = parent;
24         this.last = ASTUtil.getLastChild( parent );
25     }
26
27     public AST append(int type, String JavaDoc text, boolean appendIfEmpty) {
28         if ( text != null && ( appendIfEmpty || text.length() > 0 ) ) {
29             return append( factory.create( type, text ) );
30         }
31         else {
32             return null;
33         }
34     }
35
36     public AST append(AST child) {
37         if ( last == null ) {
38             parent.setFirstChild( child );
39         }
40         else {
41             last.setNextSibling( child );
42         }
43         last = child;
44         return last;
45     }
46 }
47
Popular Tags