KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > js > ast > JsVars


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

16 package com.google.gwt.dev.js.ast;
17
18 import java.util.Iterator JavaDoc;
19
20 /**
21  * A JavaScript <code>var</code> statement.
22  */

23 public class JsVars extends JsStatement {
24
25   /**
26    * A var declared using the JavaScript <code>var</code> statement.
27    */

28   public static class JsVar extends JsNode implements HasName {
29
30     private JsExpression initExpr;
31
32     private final JsName name;
33
34     public JsVar(JsName name) {
35       this.name = name;
36     }
37
38     public JsExpression getInitExpr() {
39       return initExpr;
40     }
41
42     public JsName getName() {
43       return name;
44     }
45
46     public void setInitExpr(JsExpression initExpr) {
47       this.initExpr = initExpr;
48     }
49
50     public void traverse(JsVisitor v, JsContext ctx) {
51       if (v.visit(this, ctx)) {
52         if (initExpr != null) {
53           initExpr = v.accept(initExpr);
54         }
55       }
56       v.endVisit(this, ctx);
57     }
58   }
59
60   private static class JsVarCollection extends JsCollection {
61     
62     public void add(JsVar expr) {
63       super.addNode(expr);
64     }
65
66     public void add(int index, JsVar expr) {
67       super.addNode(index, expr);
68     }
69
70     public JsVar get(int i) {
71       return (JsVar) super.getNode(i);
72     }
73
74     public void set(int i, JsVar expr) {
75       super.setNode(i, expr);
76     }
77   }
78   
79   private final JsVarCollection vars = new JsVarCollection();
80
81   public JsVars() {
82   }
83
84   public void add(JsVar var) {
85     vars.add(var);
86   }
87
88   public boolean isEmpty() {
89     return vars.isEmpty();
90   }
91
92   // Iterator returns JsVar objects
93
public Iterator JavaDoc iterator() {
94     return vars.iterator();
95   }
96
97   public void traverse(JsVisitor v, JsContext ctx) {
98     if (v.visit(this, ctx)) {
99       v.acceptWithInsertRemove(vars);
100     }
101     v.endVisit(this, ctx);
102   }
103 }
104
Popular Tags