package org.hibernate.hql.internal.ast.util;
import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.jboss.logging.Logger;
import antlr.ASTFactory;
import antlr.collections.AST;
public final class PathHelper {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, PathHelper.class.getName() );
private PathHelper() {
}
public static AST parsePath(String path, ASTFactory factory) {
String[] identifiers = StringHelper.split( ".", path );
AST lhs = null;
for ( int i = 0; i < identifiers.length; i++ ) {
String identifier = identifiers[i];
AST child = ASTUtil.create( factory, HqlSqlTokenTypes.IDENT, identifier );
if ( i == 0 ) {
lhs = child;
}
else {
lhs = ASTUtil.createBinarySubtree( factory, HqlSqlTokenTypes.DOT, ".", lhs, child );
}
}
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "parsePath() : %s -> %s", path, ASTUtil.getDebugString( lhs ) );
}
return lhs;
}
public static String getAlias(String path) {
return StringHelper.root( path );
}
}