01 
02 /*
03  *  Descripter 1.0 - Java Script Engines
04  *  Copyright (C) 2010-2015  Jianjun Liu (J.J.Liu)
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 package org.descripter.js.ss.parse;
20 
21 /**
22  * <p>An abstract base class for JJTree nodes.</p>
23  * 
24  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.descripter.org" target="_blank">http://www.descripter.org</a>
25  * @since Descripter 1.0
26  */
27 public abstract class AbstractNode extends SimpleNode
28 {
29     /**
30      * <p>Constructs a {@link AbstractNode} without a JJTreeParser.</p>
31      * @param i The id.
32      * @since Descripter 1.0
33      */
34     protected AbstractNode(int i) {
35         super(i);
36     }
37 
38     /**
39      * <p>Constructs a {@link AbstractNode} with a JSParser.</p>
40      * @param p The JSParser
41      * @param i The id.
42      * @since Descripter 1.0
43      */
44     protected AbstractNode(JSSPParser p, int i) {
45         super(p, i);
46     }
47 
48     /**
49      * <p>The first token of this node.</p>
50      * @since Descripter 1.0
51      */
52     public Token firstToken;
53     /**
54      * <p>The last token of this node.</p>
55      * @since Descripter 1.0
56      */
57     public Token lastToken;
58 
59     /** <p>Accepts children.</p>
60      * @param visitor A visitor
61      * @param data A datum
62      * @return A datum
63      * @since Descripter 1.0
64      */
65     public final Object acceptChildren(JSSPParserVisitor visitor, Object data) {
66         int n = jjtGetNumChildren();
67         for (int i = 0; i < n; ++i) {
68             data = getChild(i).jjtAccept(visitor, data);
69         }
70         return data;
71     }
72 
73     /** <p>Gets the child node specified.</p>
74      * @param i The index of the child one to get
75      * @return The specified child node
76      * @since Descripter 1.0
77      */
78     public final AbstractNode getChild(int i) {
79         return (AbstractNode)jjtGetChild(i);
80     }
81 }