From: <ste...@us...> - 2006-02-24 22:11:56
|
Update of /cvsroot/hibernate/Hibernate3/src/org/hibernate/hql/ast/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22750/src/org/hibernate/hql/ast/util Modified Files: ASTUtil.java JoinProcessor.java Added Files: NodeTraverser.java Log Message: HHH-1520 : with clause improvements --- NEW FILE: NodeTraverser.java --- package org.hibernate.hql.ast.util; import antlr.collections.AST; /** * A visitor for traversing an AST tree. * * @author Steve Ebersole */ public class NodeTraverser { public static interface VisitationStrategy { public void visit(AST node); } private final VisitationStrategy strategy; public NodeTraverser(VisitationStrategy strategy) { this.strategy = strategy; } /** * Traverse the AST tree depth first. * <p/> * Note that the AST passed in is not visited itself. Visitation starts * with its children. * * @param ast */ public void traverseDepthFirst(AST ast) { if ( ast == null ) { throw new IllegalArgumentException( "node to traverse cannot be null!" ); } visitDepthFirst( ast.getFirstChild() ); } private void visitDepthFirst(AST ast) { if ( ast == null ) { return; } strategy.visit( ast ); visitDepthFirst( ast.getFirstChild() ); visitDepthFirst( ast.getNextSibling() ); } } Index: ASTUtil.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/hql/ast/util/ASTUtil.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ASTUtil.java 12 Jul 2005 20:27:17 -0000 1.1 +++ ASTUtil.java 24 Feb 2006 22:11:53 -0000 1.2 @@ -112,8 +112,9 @@ */ public static AST findTypeInChildren(AST parent, int type) { AST n = parent.getFirstChild(); - while ( n != null && n.getType() != type ) + while ( n != null && n.getType() != type ) { n = n.getNextSibling(); + } return n; } @@ -219,8 +220,9 @@ } public static void appendSibling(AST n, AST s) { - while ( n.getNextSibling() != null ) + while ( n.getNextSibling() != null ) { n = n.getNextSibling(); + } n.setNextSibling( s ); } @@ -273,9 +275,35 @@ } public static List collectChildren(AST root, FilterPredicate predicate) { - List children = new ArrayList(); - collectChildren( children, root, predicate ); - return children; +// List children = new ArrayList(); +// collectChildren( children, root, predicate ); +// return children; + return new CollectingNodeVisitor( predicate ).collect( root ); + } + + private static class CollectingNodeVisitor implements NodeTraverser.VisitationStrategy { + private final FilterPredicate predicate; + private final List collectedNodes = new ArrayList(); + + public CollectingNodeVisitor(FilterPredicate predicate) { + this.predicate = predicate; + } + + public void visit(AST node) { + if ( predicate == null || !predicate.exclude( node ) ) { + collectedNodes.add( node ); + } + } + + public List getCollectedNodes() { + return collectedNodes; + } + + public List collect(AST root) { + NodeTraverser traverser = new NodeTraverser( this ); + traverser.traverseDepthFirst( root ); + return collectedNodes; + } } private static void collectChildren(List children, AST root, FilterPredicate predicate) { Index: JoinProcessor.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/hql/ast/util/JoinProcessor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- JoinProcessor.java 6 Oct 2005 20:10:46 -0000 1.4 +++ JoinProcessor.java 24 Feb 2006 22:11:53 -0000 1.5 @@ -107,7 +107,8 @@ JoinFragment joinFragment = join.toJoinFragment( inSubquery ? Collections.EMPTY_MAP : queryTranslatorImpl.getEnabledFilters(), fromElement.useFromFragment(), - fromElement.getAdHocOnClauseFragment() + fromElement.getWithClauseFragment(), + fromElement.getWithClauseJoinAlias() ); String frag = joinFragment.toFromFragmentString(); |