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    import org.jetbrains.annotations.Nullable;
010    
011    public final class JsBinaryOperation extends JsExpressionImpl {
012        private JsExpression arg1;
013        private JsExpression arg2;
014    
015        @NotNull
016        private final JsBinaryOperator op;
017    
018        public JsBinaryOperation(@NotNull JsBinaryOperator op, @Nullable JsExpression arg1, @Nullable JsExpression arg2) {
019            this.op = op;
020            this.arg1 = arg1;
021            this.arg2 = arg2;
022        }
023    
024        public JsExpression getArg1() {
025            return arg1;
026        }
027    
028        public JsExpression getArg2() {
029            return arg2;
030        }
031    
032        public void setArg1(JsExpression arg1) {
033            this.arg1 = arg1;
034        }
035    
036        public void setArg2(JsExpression arg2) {
037            this.arg2 = arg2;
038        }
039    
040        @NotNull
041        public JsBinaryOperator getOperator() {
042            return op;
043        }
044    
045        @Override
046        public void accept(JsVisitor v) {
047            v.visitBinaryExpression(this);
048        }
049    
050        @Override
051        public void acceptChildren(JsVisitor visitor) {
052            if (op.isAssignment()) {
053                visitor.acceptLvalue(arg1);
054            }
055            else {
056                visitor.accept(arg1);
057            }
058            visitor.accept(arg2);
059        }
060    
061        @Override
062        public void traverse(JsVisitorWithContext v, JsContext ctx) {
063            if (v.visit(this, ctx)) {
064                if (op.isAssignment()) {
065                    arg1 = v.acceptLvalue(arg1);
066                } else {
067                    arg1 = v.accept(arg1);
068                }
069                arg2 = v.accept(arg2);
070            }
071            v.endVisit(this, ctx);
072        }
073    
074        @NotNull
075        @Override
076        public JsExpression deepCopy() {
077            return new JsBinaryOperation(op, AstUtil.deepCopy(arg1), AstUtil.deepCopy(arg2)).withMetadataFrom(this);
078        }
079    }