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