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 return statement.
012     */
013    public final class JsReturn extends SourceInfoAwareJsNode implements JsStatement {
014        private JsExpression expression;
015    
016        public JsReturn() {
017        }
018    
019        public JsReturn(JsExpression expression) {
020            this.expression = expression;
021        }
022    
023        public JsExpression getExpression() {
024            return expression;
025        }
026    
027        public void setExpression(JsExpression expression) {
028            this.expression = expression;
029        }
030    
031        @Override
032        public void accept(JsVisitor v) {
033            v.visitReturn(this);
034        }
035    
036        @Override
037        public void acceptChildren(JsVisitor visitor) {
038            if (expression != null) {
039                visitor.accept(expression);
040            }
041        }
042    
043        @Override
044        public void traverse(JsVisitorWithContext v, JsContext ctx) {
045            if (v.visit(this, ctx)) {
046                if (expression != null) {
047                    expression = v.accept(expression);
048                }
049            }
050            v.endVisit(this, ctx);
051        }
052    
053        @NotNull
054        @Override
055        public JsReturn deepCopy() {
056            return new JsReturn(AstUtil.deepCopy(expression)).withMetadataFrom(this);
057        }
058    }