[hibernate-commits] Hibernate SVN: r15870 - in core/branches/Branch_3_3/core: src/main/java/org/hibernate/hql/ast and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue Feb 3 15:45:03 EST 2009
Author: steve.ebersole at jboss.com
Date: 2009-02-03 15:45:03 -0500 (Tue, 03 Feb 2009)
New Revision: 15870
Modified:
core/branches/Branch_3_3/core/pom.xml
core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java
Log:
HHH-3751 : Antlr tree parser tracing
Modified: core/branches/Branch_3_3/core/pom.xml
===================================================================
--- core/branches/Branch_3_3/core/pom.xml 2009-02-03 20:37:01 UTC (rev 15869)
+++ core/branches/Branch_3_3/core/pom.xml 2009-02-03 20:45:03 UTC (rev 15870)
@@ -77,6 +77,7 @@
<artifactId>antlr-maven-plugin</artifactId>
<version>${antlrPluginVersion}</version>
<configuration>
+ <traceTreeParser>true</traceTreeParser>
<grammars>hql.g,hql-sql.g,sql-gen.g</grammars>
</configuration>
<executions>
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java 2009-02-03 20:37:01 UTC (rev 15869)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java 2009-02-03 20:45:03 UTC (rev 15870)
@@ -32,16 +32,22 @@
import antlr.RecognitionException;
import antlr.collections.AST;
import org.hibernate.QueryException;
+import org.hibernate.util.StringHelper;
import org.hibernate.param.ParameterSpecification;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.hql.antlr.SqlGeneratorBase;
+import org.hibernate.hql.antlr.SqlTokenTypes;
import org.hibernate.hql.ast.tree.MethodNode;
import org.hibernate.hql.ast.tree.FromElement;
import org.hibernate.hql.ast.tree.Node;
import org.hibernate.hql.ast.tree.ParameterNode;
import org.hibernate.hql.ast.tree.ParameterContainer;
+import org.hibernate.hql.ast.util.ASTPrinter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Generates SQL by overriding callback methods in the base class, which does
* the actual SQL AST walking.
@@ -50,6 +56,9 @@
* @author Steve Ebersole
*/
public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
+ private static final Logger log = LoggerFactory.getLogger( SqlGenerator.class );
+ private static final ASTPrinter printer = new ASTPrinter( SqlTokenTypes.class, true );
+
/**
* Handles parser errors.
*/
@@ -74,6 +83,45 @@
return collectedParameters;
}
+ public ASTPrinter getPrinter() {
+ return printer;
+ }
+
+
+ // handle trace logging ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ private int traceDepth = 0;
+
+ public void traceIn(String ruleName, AST tree) {
+ if ( inputState.guessing > 0 ) {
+ return;
+ }
+ String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "-> ";
+ String traceText = ruleName + " (" + buildTraceNodeName(tree) + ")";
+ trace( prefix + traceText );
+ }
+
+ private String buildTraceNodeName(AST tree) {
+ return tree == null
+ ? "???"
+ : tree.getText() + " [" + printer.getTokenTypeName( tree.getType() ) + "]";
+ }
+
+ public void traceOut(String ruleName, AST tree) {
+ if ( inputState.guessing > 0 ) {
+ return;
+ }
+ String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " ";
+ trace( prefix + ruleName );
+ }
+
+ private void trace(String msg) {
+ log.trace( msg );
+ }
+
+
+ // semantic action processing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
protected void out(String s) {
writer.clause( s );
}
More information about the hibernate-commits
mailing list