001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.dev.js.ast;
017:
018: /**
019: * A <code>for</code> statement. If specified at all, the initializer part is
020: * either a declaration of one or more variables, in which case
021: * {@link #getInitVars()} is used, or an expression, in which case
022: * {@link #getInitExpr()} is used. In the latter case, the comma operator is
023: * often used to create a compound expression.
024: *
025: * <p>
026: * Note that any of the parts of the <code>for</code> loop header can be
027: * <code>null</code>, although the body will never be null.
028: */
029: public class JsFor extends JsStatement {
030:
031: private JsStatement body;
032:
033: private JsExpression condition;
034:
035: private JsExpression incrExpr;
036:
037: private JsExpression initExpr;
038:
039: private JsVars initVars;
040:
041: public JsFor() {
042: }
043:
044: public JsStatement getBody() {
045: return body;
046: }
047:
048: public JsExpression getCondition() {
049: return condition;
050: }
051:
052: public JsExpression getIncrExpr() {
053: return incrExpr;
054: }
055:
056: public JsExpression getInitExpr() {
057: return initExpr;
058: }
059:
060: public JsVars getInitVars() {
061: return initVars;
062: }
063:
064: public void setBody(JsStatement body) {
065: this .body = body;
066: }
067:
068: public void setCondition(JsExpression condition) {
069: this .condition = condition;
070: }
071:
072: public void setIncrExpr(JsExpression incrExpr) {
073: this .incrExpr = incrExpr;
074: }
075:
076: public void setInitExpr(JsExpression initExpr) {
077: this .initExpr = initExpr;
078: }
079:
080: public void setInitVars(JsVars initVars) {
081: this .initVars = initVars;
082: }
083:
084: public void traverse(JsVisitor v, JsContext<JsStatement> ctx) {
085: if (v.visit(this, ctx)) {
086: assert (!(initExpr != null && initVars != null));
087:
088: if (initExpr != null) {
089: initExpr = v.accept(initExpr);
090: } else if (initVars != null) {
091: initVars = v.accept(initVars);
092: }
093:
094: if (condition != null) {
095: condition = v.accept(condition);
096: }
097:
098: if (incrExpr != null) {
099: incrExpr = v.accept(incrExpr);
100: }
101: body = v.accept(body);
102: }
103: v.endVisit(this, ctx);
104: }
105: }
|