1 package org.hibernate.hql.ast.util; 3 4 import antlr.ASTFactory; 5 import antlr.collections.AST; 6 7 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 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 |