001 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 002 // for details. All rights reserved. Use of this source code is governed by a 003 // BSD-style license that can be found in the LICENSE file. 004 005 package com.google.dart.compiler.backend.js.ast; 006 007 import com.google.dart.compiler.util.AstUtil; 008 import org.jetbrains.annotations.NotNull; 009 010 /** 011 * A JavaScript <code>while</code> statement. 012 */ 013 public class JsWhile extends SourceInfoAwareJsNode implements JsStatement { 014 protected JsStatement body; 015 protected JsExpression condition; 016 017 public JsWhile() { 018 } 019 020 public JsWhile(JsExpression condition, JsStatement body) { 021 this.condition = condition; 022 this.body = body; 023 } 024 025 public JsStatement getBody() { 026 return body; 027 } 028 029 public JsExpression getCondition() { 030 return condition; 031 } 032 033 public void setBody(JsStatement body) { 034 this.body = body; 035 } 036 037 public void setCondition(JsExpression condition) { 038 this.condition = condition; 039 } 040 041 @Override 042 public void accept(JsVisitor v) { 043 v.visitWhile(this); 044 } 045 046 @Override 047 public void acceptChildren(JsVisitor visitor) { 048 visitor.accept(condition); 049 visitor.accept(body); 050 } 051 052 @Override 053 public void traverse(JsVisitorWithContext v, JsContext ctx) { 054 if (v.visit(this, ctx)) { 055 condition = v.accept(condition); 056 body = v.acceptStatement(body); 057 } 058 v.endVisit(this, ctx); 059 } 060 061 @NotNull 062 @Override 063 public JsWhile deepCopy() { 064 JsExpression conditionCopy = AstUtil.deepCopy(condition); 065 JsStatement bodyCopy = AstUtil.deepCopy(body); 066 067 return new JsWhile(conditionCopy, bodyCopy).withMetadataFrom(this); 068 } 069 }