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 com.intellij.util.SmartList;
009 import org.jetbrains.annotations.NotNull;
010
011 import java.util.List;
012
013 /**
014 * Represents a JavaScript expression for array literals.
015 */
016 public final class JsArrayLiteral extends JsLiteral {
017 private final List<JsExpression> expressions;
018
019 public JsArrayLiteral() {
020 expressions = new SmartList<JsExpression>();
021 }
022
023 public JsArrayLiteral(List<JsExpression> expressions) {
024 this.expressions = expressions;
025 }
026
027 public List<JsExpression> getExpressions() {
028 return expressions;
029 }
030
031 @Override
032 public void accept(JsVisitor v) {
033 v.visitArray(this);
034 }
035
036 @Override
037 public void acceptChildren(JsVisitor visitor) {
038 visitor.acceptWithInsertRemove(expressions);
039 }
040
041 @Override
042 public void traverse(JsVisitorWithContext v, JsContext ctx) {
043 if (v.visit(this, ctx)) {
044 v.acceptList(expressions);
045 }
046 v.endVisit(this, ctx);
047 }
048
049 @NotNull
050 @Override
051 public JsArrayLiteral deepCopy() {
052 return new JsArrayLiteral(AstUtil.deepCopy(expressions)).withMetadataFrom(this);
053 }
054 }