KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > jdo > jdoql > ASTWithPositionInfo


1 package org.apache.ojb.jdo.jdoql;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import antlr.CommonAST;
19 import antlr.Token;
20 import antlr.collections.AST;
21
22 /**
23  * An AST node that also contains position info (for error handling).
24  *
25  * @author <a HREF="mailto:tomdz@apache.org">Thomas Dudziak</a>
26  */

27 public class ASTWithPositionInfo extends CommonAST
28 {
29     /** The line where the source of this node started. */
30     private int _line = 0;
31     /** The column where the source of this node started. */
32     private int _column = 0;
33
34     /**
35      * Creates a new node.
36      */

37     public ASTWithPositionInfo()
38     {
39         super();
40     }
41
42     /**
43      * Creates a new node for the given token.
44      *
45      * @param tok The token
46      */

47     public ASTWithPositionInfo(Token tok)
48     {
49         super(tok);
50     }
51
52     /**
53      * Returns the column where the source of this node started.
54      *
55      * @return The column
56      * @see antlr.collections.AST#getColumn()
57      */

58     public int getColumn()
59     {
60         return _column;
61     }
62
63     /**
64      * Returns the line where the source of this node started.
65      *
66      * @return The line
67      * @see antlr.collections.AST#getLine()
68      */

69     public int getLine()
70     {
71         return _line;
72     }
73
74     /* (non-Javadoc)
75      * @see antlr.collections.AST#initialize(antlr.collections.AST)
76      */

77     public void initialize(AST ast)
78     {
79         super.initialize(ast);
80         _line = ast.getLine();
81         _column = ast.getColumn();
82     }
83
84     /* (non-Javadoc)
85      * @see antlr.collections.AST#initialize(antlr.Token)
86      */

87     public void initialize(Token tok)
88     {
89         super.initialize(tok);
90         _line = tok.getLine();
91         _column = tok.getColumn();
92     }
93
94     /* (non-Javadoc)
95      * @see antlr.collections.AST#addChild(antlr.collections.AST)
96      */

97     public void addChild(AST ast)
98     {
99         if ((ast != null) && (down == null) && (_line == 0) && (_column == 0))
100         {
101             _line = ast.getLine();
102             _column = ast.getColumn();
103         }
104         super.addChild(ast);
105     }
106
107     /* (non-Javadoc)
108      * @see antlr.collections.AST#setFirstChild(antlr.collections.AST)
109      */

110     public void setFirstChild(AST ast)
111     {
112         if ((ast != null) && (_line == 0) && (_column == 0))
113         {
114             _line = ast.getLine();
115             _column = ast.getColumn();
116         }
117         super.setFirstChild(ast);
118     }
119 }
120
Popular Tags