HHH-3751 : Antlr tree parser tracing
git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_3@15870 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
c7dcdc19a0
commit
9bfb17b497
|
@ -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>
|
||||
|
|
|
@ -32,15 +32,21 @@ import java.util.Arrays;
|
|||
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
|
||||
|
@ -50,6 +56,9 @@ import org.hibernate.hql.ast.tree.ParameterContainer;
|
|||
* @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 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue