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    import java.util.ArrayList;
010    import java.util.Arrays;
011    import java.util.Collections;
012    import java.util.List;
013    
014    /**
015     * Represents a JavaScript block statement.
016     */
017    public class JsBlock extends SourceInfoAwareJsNode implements JsStatement {
018        @NotNull
019        private final List<JsStatement> statements;
020    
021        public JsBlock() {
022            this(new ArrayList<JsStatement>());
023        }
024    
025        public JsBlock(JsStatement statement) {
026            this(Collections.singletonList(statement));
027        }
028    
029        public JsBlock(JsStatement... statements) {
030            this(Arrays.asList(statements));
031        }
032    
033        public JsBlock(@NotNull List<JsStatement> statements) {
034            this.statements = statements;
035        }
036    
037        @NotNull
038        public List<JsStatement> getStatements() {
039            return statements;
040        }
041    
042        public boolean isEmpty() {
043            return statements.isEmpty();
044        }
045    
046        public boolean isGlobalBlock() {
047            return false;
048        }
049    
050        @Override
051        public void accept(JsVisitor v) {
052            v.visitBlock(this);
053        }
054    
055        @Override
056        public void acceptChildren(JsVisitor visitor) {
057            visitor.acceptWithInsertRemove(statements);
058        }
059    }