01: package org.hibernate.hql.ast.tree;
02:
03: import antlr.collections.AST;
04: import antlr.Token;
05: import org.hibernate.util.StringHelper;
06: import org.hibernate.engine.SessionFactoryImplementor;
07:
08: /**
09: * Base node class for use by Hibernate within its AST trees.
10: *
11: * @author Joshua Davis
12: * @author Steve Ebersole
13: */
14: public class Node extends antlr.CommonAST {
15: private String filename;
16: private int line;
17: private int column;
18: private int textLength;
19:
20: public Node() {
21: super ();
22: }
23:
24: public Node(Token tok) {
25: super (tok); // This will call initialize(tok)!
26: }
27:
28: /**
29: * Retrieve the text to be used for rendering this particular node.
30: *
31: * @param sessionFactory The session factory
32: * @return The text to use for rendering
33: */
34: public String getRenderText(SessionFactoryImplementor sessionFactory) {
35: // The basic implementation is to simply use the node's text
36: return getText();
37: }
38:
39: public void initialize(Token tok) {
40: super .initialize(tok);
41: filename = tok.getFilename();
42: line = tok.getLine();
43: column = tok.getColumn();
44: String text = tok.getText();
45: textLength = StringHelper.isEmpty(text) ? 0 : text.length();
46: }
47:
48: public void initialize(AST t) {
49: super .initialize(t);
50: if (t instanceof Node) {
51: Node n = (Node) t;
52: filename = n.filename;
53: line = n.line;
54: column = n.column;
55: textLength = n.textLength;
56: }
57: }
58:
59: public String getFilename() {
60: return filename;
61: }
62:
63: public int getLine() {
64: return line;
65: }
66:
67: public int getColumn() {
68: return column;
69: }
70:
71: public int getTextLength() {
72: return textLength;
73: }
74: }
|