public final class

ASTUtil

extends Object
java.lang.Object
   ↳ org.hibernate.hql.ast.util.ASTUtil

Class Overview

Provides utility methods for AST traversal and manipulation.

Summary

Nested Classes
interface ASTUtil.FilterPredicate Filters nodes out of a tree. 
class ASTUtil.IncludePredicate A predicate that uses inclusion, rather than exclusion semantics. 
Public Methods
static void appendSibling(AST n, AST s)
static List collectChildren(AST root, ASTUtil.FilterPredicate predicate)
static AST create(ASTFactory astFactory, int type, String text)
This method is deprecated. silly
static AST createBinarySubtree(ASTFactory factory, int parentType, String parentText, AST child1, AST child2)
Creates a 'binary operator' subtree, given the information about the parent and the two child nodex.
static AST createParent(ASTFactory factory, int parentType, String parentText, AST child)
Creates a single parent of the specified child (i.e.
static AST createSibling(ASTFactory astFactory, int type, String text, AST prevSibling)
Creates a single node AST as a sibling of the passed prevSibling, taking care to reorganize the tree correctly to account for this newly created node.
static AST createTree(ASTFactory factory, AST[] nestedChildren)
static AST findPreviousSibling(AST parent, AST child)
Find the previous sibling in the parent for the given child.
static AST findTypeInChildren(AST parent, int type)
Finds the first node of the specified type in the chain of children.
static Map generateTokenNameCache(Class tokenTypeInterface)
Method to generate a map of token type names, keyed by their token type values.
static String getConstantName(Class owner, int value)
This method is deprecated. Use #getTokenTypeName instead
static String getDebugString(AST n)
Returns the 'list' representation with some brackets around it for debugging.
static AST getLastChild(AST n)
Returns the last direct child of 'n'.
static String getPathText(AST n)
static String getTokenTypeName(Class tokenTypeInterface, int tokenType)
Intended to retrieve the name of an AST token type based on the token type interface.
static boolean hasExactlyOneChild(AST n)
static void insertChild(AST parent, AST child)
Inserts the child as the first child of the parent, all other children are shifted over to the 'right'.
static AST insertSibling(AST node, AST prevSibling)
Inserts a node into a child subtree as a particularly positioned sibling taking care to properly reorganize the tree to account for this new addition.
static boolean isSubtreeChild(AST fixture, AST test)
Determine if a given node (test) is contained anywhere in the subtree of another given node (fixture).
static void makeSiblingOfParent(AST parent, AST child)
Makes the child node a sibling of the parent, reconnecting all siblings.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static void appendSibling (AST n, AST s)

public static List collectChildren (AST root, ASTUtil.FilterPredicate predicate)

public static AST create (ASTFactory astFactory, int type, String text)

This method is deprecated.
silly

Creates a single node AST.

TODO : this is silly, remove it...

Parameters
astFactory The factory.
type The node type.
text The node text.
Returns
  • AST - A single node tree.

public static AST createBinarySubtree (ASTFactory factory, int parentType, String parentText, AST child1, AST child2)

Creates a 'binary operator' subtree, given the information about the parent and the two child nodex.

Parameters
factory The AST factory.
parentType The type of the parent node.
parentText The text of the parent node.
child1 The first child.
child2 The second child.
Returns
  • AST - A new sub-tree of the form "(parent child1 child2)"

public static AST createParent (ASTFactory factory, int parentType, String parentText, AST child)

Creates a single parent of the specified child (i.e. a 'unary operator' subtree).

Parameters
factory The AST factory.
parentType The type of the parent node.
parentText The text of the parent node.
child The child.
Returns
  • AST - A new sub-tree of the form "(parent child)"

public static AST createSibling (ASTFactory astFactory, int type, String text, AST prevSibling)

Creates a single node AST as a sibling of the passed prevSibling, taking care to reorganize the tree correctly to account for this newly created node.

Parameters
astFactory The factory.
type The node type.
text The node text.
prevSibling The previous sibling.
Returns
  • The created AST node.

public static AST createTree (ASTFactory factory, AST[] nestedChildren)

public static AST findPreviousSibling (AST parent, AST child)

Find the previous sibling in the parent for the given child.

Parameters
parent the parent node
child the child to find the previous sibling of
Returns
  • the previous sibling of the child

public static AST findTypeInChildren (AST parent, int type)

Finds the first node of the specified type in the chain of children.

Parameters
parent The parent
type The type to find.
Returns
  • The first node of the specified type, or null if not found.

public static Map generateTokenNameCache (Class tokenTypeInterface)

Method to generate a map of token type names, keyed by their token type values.

Parameters
tokenTypeInterface The *TokenTypes interface (or implementor of said interface).
Returns
  • The generated map.

public static String getConstantName (Class owner, int value)

This method is deprecated.
Use #getTokenTypeName instead

Get the name of a constant defined on the given class which has the given value.

Note, if multiple constants have this value, the first will be returned which is known to be different on different JVM implementations.

Parameters
owner The class which defines the constant
value The value of the constant.
Returns
  • The token type name, *or* the integer value if the name could not be found.

public static String getDebugString (AST n)

Returns the 'list' representation with some brackets around it for debugging.

Parameters
n The tree.
Returns
  • The list representation of the tree.

public static AST getLastChild (AST n)

Returns the last direct child of 'n'.

Parameters
n The parent
Returns
  • The last direct child of 'n'.

public static String getPathText (AST n)

public static String getTokenTypeName (Class tokenTypeInterface, int tokenType)

Intended to retrieve the name of an AST token type based on the token type interface. However, this method can be used to look up the name of any constant defined on a class/interface based on the constant value. Note that if multiple constants have this value, the first will be returned which is known to be different on different JVM implementations.

Parameters
tokenTypeInterface The *TokenTypes interface (or one of its implementors).
tokenType The token type value.
Returns
  • The corresponding name.

public static boolean hasExactlyOneChild (AST n)

public static void insertChild (AST parent, AST child)

Inserts the child as the first child of the parent, all other children are shifted over to the 'right'.

Parameters
parent the parent
child the new first child

public static AST insertSibling (AST node, AST prevSibling)

Inserts a node into a child subtree as a particularly positioned sibling taking care to properly reorganize the tree to account for this new addition.

Parameters
node The node to insert
prevSibling The previous node at the sibling position where we want this node inserted.
Returns
  • The return is the same as the node parameter passed in.

public static boolean isSubtreeChild (AST fixture, AST test)

Determine if a given node (test) is contained anywhere in the subtree of another given node (fixture).

Parameters
fixture The node against which to testto be checked for children.
test The node to be tested as being a subtree child of the parent.
Returns
  • True if child is contained in the parent's collection of children.

public static void makeSiblingOfParent (AST parent, AST child)

Makes the child node a sibling of the parent, reconnecting all siblings.

Parameters
parent the parent
child the child