Top Description Fields Constructors Methods
org.hibernate.hql.ast.util

public Class ASTPrinter

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .PrintStream, .PrintWriter, java.util.ArrayList, .Map, org.hibernate.hql.ast.tree.DisplayableNode, org.hibernate.util.StringHelper, antlr.collections.AST

Utility for generating pretty "ASCII art" representations of syntax trees.
Authors
Joshua Davis, Steve Ebersole

Field Summary

Modifier and TypeField and Description
private final boolean
private final Map<K, V>

Constructor Summary

AccessConstructor and Description
public
ASTPrinter(Class<T>
The token types to use during printing; typically the {vocabulary}TokenTypes.java interface generated by ANTLR.
tokenTypeConstants
)

Constructs a printer.

public
ASTPrinter(boolean showClassNames)

public
ASTPrinter(Class<T>
The token types to use during printing; typically the {vocabulary}TokenTypes.java interface generated by ANTLR.
tokenTypeConstants
,
boolean
Should the AST class names be shown.
showClassNames
)

Constructs a printer.

private
ASTPrinter(Map<K, V> tokenTypeNameCache, boolean showClassNames)

Method Summary

Modifier and TypeMethod and Description
public static void
public static String
public String

Returns:

String - The token type name from the token type constant class, or just the integer as a string if none exists.
getTokenTypeName
(int
The token type.
type
)

Returns the token type name for the given token type.

public boolean

Returns:

Value for property 'showClassNames'.
isShowClassNames
()

Getter for property 'showClassNames'.

public String
nodeToString(AST ast, boolean showClassName)

public String

Returns:

The AST in 'ASCII art' form, as a string.
showAsString
(AST
The AST to display.
ast
,
String
The header for the display.
header
)

Renders the AST into 'ASCII art' form and returns that string representation.

public void
showAst(AST
The AST to print.
ast
,
PrintStream
The print stream to which the AST should be printed.
out
)

Prints the AST in 'ASCII art' form to the specified print stream.

public void
showAst(AST
The AST to print.
ast
,
PrintWriter
The print writer to which the AST should be written.
pw
)

Prints the AST in 'ASCII art' tree form to the specified print writer.

private void
showAst(ArrayList<E> parents, PrintWriter pw, AST ast)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

showClassNamesback to summary
private final boolean showClassNames
tokenTypeNameCacheback to summary
private final Map<K, V> tokenTypeNameCache

Constructor Detail

ASTPrinterback to summary
public ASTPrinter(Class<T> tokenTypeConstants)

Constructs a printer.

Delegates to ASTPrinter(Class, boolean) with showClassNames as true

Parameters
tokenTypeConstants:Class<T>

The token types to use during printing; typically the {vocabulary}TokenTypes.java interface generated by ANTLR.

ASTPrinterback to summary
public ASTPrinter(boolean showClassNames)
ASTPrinterback to summary
public ASTPrinter(Class<T> tokenTypeConstants, boolean showClassNames)

Constructs a printer.

Parameters
tokenTypeConstants:Class<T>

The token types to use during printing; typically the {vocabulary}TokenTypes.java interface generated by ANTLR.

showClassNames:boolean

Should the AST class names be shown.

ASTPrinterback to summary
private ASTPrinter(Map<K, V> tokenTypeNameCache, boolean showClassNames)

Method Detail

appendEscapedMultibyteCharsback to summary
public static void appendEscapedMultibyteChars(String text, StringBuffer buf)
escapeMultibyteCharsback to summary
public static String escapeMultibyteChars(String text)
getTokenTypeNameback to summary
public String getTokenTypeName(int type)

Returns the token type name for the given token type.

Parameters
type:int

The token type.

Returns:String

String - The token type name from the token type constant class, or just the integer as a string if none exists.

isShowClassNamesback to summary
public boolean isShowClassNames()

Getter for property 'showClassNames'.

Returns:boolean

Value for property 'showClassNames'.

nodeToStringback to summary
public String nodeToString(AST ast, boolean showClassName)
showAsStringback to summary
public String showAsString(AST ast, String header)

Renders the AST into 'ASCII art' form and returns that string representation.

Parameters
ast:AST

The AST to display.

header:String

The header for the display.

Returns:String

The AST in 'ASCII art' form, as a string.

showAstback to summary
public void showAst(AST ast, PrintStream out)

Prints the AST in 'ASCII art' form to the specified print stream.

Parameters
ast:AST

The AST to print.

out:PrintStream

The print stream to which the AST should be printed.

showAstback to summary
public void showAst(AST ast, PrintWriter pw)

Prints the AST in 'ASCII art' tree form to the specified print writer.

Parameters
ast:AST

The AST to print.

pw:PrintWriter

The print writer to which the AST should be written.

showAstback to summary
private void showAst(ArrayList<E> parents, PrintWriter pw, AST ast)
showNodeback to summary
private void showNode(PrintWriter pw, AST ast)