1
// $Id: PathHelper.java 7460 2005-07-12 20:27:29Z steveebersole $
2
package org.hibernate.hql.ast.util;
4
import org.hibernate.hql.antlr.HqlSqlTokenTypes;
5
import org.hibernate.util.StringHelper;
7
import antlr.ASTFactory;
8
import antlr.collections.AST;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
14
* Provides utility methods for paths.
16
* @author josh Sep 14, 2004 8:16:29 AM
18
public final class PathHelper {
20
private static final Log log = LogFactory.getLog( PathHelper.class );
22
private PathHelper() {
26
* Turns a path into an AST.
28
* @param path The path.
29
* @param factory The AST factory to use.
30
* @return An HQL AST representing the path.
32
public static AST parsePath(String path, ASTFactory factory) {
33
String[] identifiers = StringHelper.split( ".", path );
35
for ( int i = 0; i < identifiers.length; i++ ) {
36
String identifier = identifiers[i];
37
AST child = ASTUtil.create( factory, HqlSqlTokenTypes.IDENT, identifier );
42
lhs = ASTUtil.createBinarySubtree( factory, HqlSqlTokenTypes.DOT, ".", lhs, child );
45
if ( log.isDebugEnabled() ) {
46
log.debug( "parsePath() : " + path + " -> " + ASTUtil.getDebugString( lhs ) );
51
public static String getAlias(String path) {
52
return StringHelper.root( path );