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 /**
008 * Represents a JavaScript catch clause.
009 */
010 public class JsCatch extends SourceInfoAwareJsNode implements HasCondition {
011
012 protected final JsCatchScope scope;
013 private JsBlock body;
014 private JsExpression condition;
015 private JsParameter param;
016
017 public JsCatch(JsScope parent, String ident) {
018 super();
019 assert (parent != null);
020 scope = new JsCatchScope(parent, ident);
021 param = new JsParameter(scope.findName(ident));
022 }
023
024 public JsBlock getBody() {
025 return body;
026 }
027
028 @Override
029 public JsExpression getCondition() {
030 return condition;
031 }
032
033 public JsParameter getParameter() {
034 return param;
035 }
036
037 public JsScope getScope() {
038 return scope;
039 }
040
041 public void setBody(JsBlock body) {
042 this.body = body;
043 }
044
045 @Override
046 public void setCondition(JsExpression condition) {
047 this.condition = condition;
048 }
049
050 @Override
051 public void accept(JsVisitor v) {
052 v.visitCatch(this);
053 }
054
055 @Override
056 public void acceptChildren(JsVisitor visitor) {
057 visitor.accept(param);
058 if (condition != null) {
059 visitor.accept(condition);
060 }
061 visitor.accept(body);
062 }
063 }