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.intellij.util.SmartList; 008 import org.jetbrains.annotations.Nullable; 009 010 import java.util.List; 011 012 /** 013 * A JavaScript <code>try</code> statement. 014 */ 015 public class JsTry extends SourceInfoAwareJsNode implements JsStatement { 016 private final List<JsCatch> catches; 017 private JsBlock finallyBlock; 018 private JsBlock tryBlock; 019 020 public JsTry() { 021 catches = new SmartList<JsCatch>(); 022 } 023 024 public JsTry(JsBlock tryBlock, List<JsCatch> catches, @Nullable JsBlock finallyBlock) { 025 this.tryBlock = tryBlock; 026 this.catches = catches; 027 this.finallyBlock = finallyBlock; 028 } 029 030 public List<JsCatch> getCatches() { 031 return catches; 032 } 033 034 public JsBlock getFinallyBlock() { 035 return finallyBlock; 036 } 037 038 public JsBlock getTryBlock() { 039 return tryBlock; 040 } 041 042 public void setFinallyBlock(JsBlock block) { 043 finallyBlock = block; 044 } 045 046 public void setTryBlock(JsBlock block) { 047 tryBlock = block; 048 } 049 050 @Override 051 public void accept(JsVisitor v) { 052 v.visitTry(this); 053 } 054 055 @Override 056 public void acceptChildren(JsVisitor visitor) { 057 visitor.accept(tryBlock); 058 visitor.acceptWithInsertRemove(catches); 059 if (finallyBlock != null) { 060 visitor.accept(finallyBlock); 061 } 062 } 063 }