KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
19  * A <code>for</code> statement. If specified at all, the initializer part is
20  * either a declaration of one or more variables, in which case
21  * {@link #getInitVars()} is used, or an expression, in which case
22  * {@link #getInitExpr()} is used. In the latter case, the comma operator is
23  * often used to create a compound expression.
24  *
25  * <p>
26  * Note that any of the parts of the <code>for</code> loop header can be
27  * <code>null</code>, although the body will never be null.
28  */

29 public class JsFor extends JsStatement {
30
31   private JsStatement body;
32
33   private JsExpression condition;
34
35   private JsExpression incrExpr;
36
37   private JsExpression initExpr;
38
39   private JsVars initVars;
40
41   public JsFor() {
42   }
43
44   public JsStatement getBody() {
45     return body;
46   }
47
48   public JsExpression getCondition() {
49     return condition;
50   }
51
52   public JsExpression getIncrExpr() {
53     return incrExpr;
54   }
55
56   public JsExpression getInitExpr() {
57     return initExpr;
58   }
59
60   public JsVars getInitVars() {
61     return initVars;
62   }
63
64   public void setBody(JsStatement body) {
65     this.body = body;
66   }
67
68   public void setCondition(JsExpression condition) {
69     this.condition = condition;
70   }
71
72   public void setIncrExpr(JsExpression incrExpr) {
73     this.incrExpr = incrExpr;
74   }
75
76   public void setInitExpr(JsExpression initExpr) {
77     this.initExpr = initExpr;
78   }
79
80   public void setInitVars(JsVars initVars) {
81     this.initVars = initVars;
82   }
83
84   public void traverse(JsVisitor v, JsContext ctx) {
85     if (v.visit(this, ctx)) {
86       assert (!(initExpr != null && initVars != null));
87
88       if (initExpr != null) {
89         initExpr = v.accept(initExpr);
90       } else if (initVars != null) {
91         initVars = (JsVars) v.accept(initVars);
92       }
93
94       if (condition != null) {
95         condition = v.accept(condition);
96       }
97
98       if (incrExpr != null) {
99         incrExpr = v.accept(incrExpr);
100       }
101       body = v.accept(body);
102     }
103     v.endVisit(this, ctx);
104   }
105 }
106
Popular Tags