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 org.jetbrains.annotations.NotNull;
008    
009    /**
010     * Used in object literals to specify property values by name.
011     */
012    public class JsPropertyInitializer extends SourceInfoAwareJsNode {
013        @NotNull
014        private JsExpression labelExpr;
015        @NotNull
016        private JsExpression valueExpr;
017    
018        public JsPropertyInitializer(@NotNull JsExpression labelExpr, @NotNull JsExpression valueExpr) {
019            this.labelExpr = labelExpr;
020            this.valueExpr = valueExpr;
021        }
022    
023        @NotNull
024        public JsExpression getLabelExpr() {
025            return labelExpr;
026        }
027    
028        @NotNull
029        public JsExpression getValueExpr() {
030            return valueExpr;
031        }
032    
033        @Override
034        public void accept(JsVisitor v) {
035            v.visitPropertyInitializer(this);
036        }
037    
038        @Override
039        public void acceptChildren(JsVisitor visitor) {
040            visitor.accept(labelExpr);
041            visitor.accept(valueExpr);
042        }
043    
044        @Override
045        public void traverse(JsVisitorWithContext v, JsContext ctx) {
046            if (v.visit(this, ctx)) {
047                JsExpression newLabel = v.accept(labelExpr);
048                JsExpression newValue = v.accept(valueExpr);
049                assert newLabel != null: "Label cannot be replaced with null";
050                assert newValue != null: "Value cannot be replaced with null";
051                labelExpr = newLabel;
052                valueExpr = newValue;
053            }
054            v.endVisit(this, ctx);
055        }
056    
057        @NotNull
058        @Override
059        public JsPropertyInitializer deepCopy() {
060            return new JsPropertyInitializer(labelExpr.deepCopy(), valueExpr.deepCopy()).withMetadataFrom(this);
061        }
062    }