org.hibernate.hql.ast.util

Class ASTPrinter


public class ASTPrinter
extends java.lang.Object

An 'ASCII art' AST printer for debugging ANTLR grammars.
Author:
Joshua Davis

Constructor Summary

ASTPrinter(Class tokenTypeConstants)
Constructs an org.hibernate.hql.antlr.ASTPrinter, given the class that contains the token type constants (typically the '{grammar}TokenTypes' interface generated by ANTLR).

Method Summary

static void
appendEscapedMultibyteChars(String text, StringBuffer buf)
static String
escapeMultibyteChars(String text)
static String
getConstantName(Class tokenTypeConstants, int type)
Get a single token type name in the specified set of token type constants (interface).
boolean
isShowClassNames()
Returns true if the node class names will be displayed.
String
nodeToString(AST ast, boolean showClassName)
void
setShowClassNames(boolean showClassNames)
Enables or disables AST node class name display.
String
showAsString(AST ast, String header)
Prints the AST in 'ASCII art' tree form into a string.
void
showAst(AST ast, PrintWriter pw)
Prints the AST in 'ASCII art' tree form to the specified print writer.

Constructor Details

ASTPrinter

public ASTPrinter(Class tokenTypeConstants)
Constructs an org.hibernate.hql.antlr.ASTPrinter, given the class that contains the token type constants (typically the '{grammar}TokenTypes' interface generated by ANTLR).
Parameters:
tokenTypeConstants - The class with token type constants in it.

Method Details

appendEscapedMultibyteChars

public static void appendEscapedMultibyteChars(String text,
                                               StringBuffer buf)

escapeMultibyteChars

public static String escapeMultibyteChars(String text)

getConstantName

public static String getConstantName(Class tokenTypeConstants,
                                     int type)
Get a single token type name in the specified set of token type constants (interface).
Parameters:
tokenTypeConstants - Token type constants interface (e.g. HqlSqlTokenTypes.class).
type - The token type ( typically from ast.getType() ).
Returns:
The token type name, *or* the integer value if the name could not be found for some reason.

isShowClassNames

public boolean isShowClassNames()
Returns true if the node class names will be displayed.
Returns:
true if the node class names will be displayed.

nodeToString

public String nodeToString(AST ast,
                           boolean showClassName)

setShowClassNames

public void setShowClassNames(boolean showClassNames)
Enables or disables AST node class name display.
Parameters:
showClassNames - true to enable class name display, false to disable

showAsString

public String showAsString(AST ast,
                           String header)
Prints the AST in 'ASCII art' tree form into a string.
Parameters:
ast - The AST to display.
header - The header for the display.
Returns:
The AST in 'ASCII art' form, as a string.

showAst

public void showAst(AST ast,
                    PrintWriter pw)
Prints the AST in 'ASCII art' tree form to the specified print writer.
Parameters:
ast - The AST to print.
pw - The print writer.