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 /**
010 * A special scope used only for catch blocks. It only holds a single symbol:
011 * the catch argument's name.
012 */
013 public class JsCatchScope extends JsScope {
014 private final JsName name;
015
016 public JsCatchScope(JsScope parent, String ident) {
017 super(parent, "Catch scope");
018 name = new JsName(this, ident);
019 }
020
021 @Override
022 public JsName declareName(String identifier) {
023 // Declare into parent scope!
024 return getParent().declareName(identifier);
025 }
026
027 @Override
028 public boolean hasOwnName(@NotNull String name) {
029 return findOwnName(name) != null;
030 }
031
032 @Override
033 protected JsName findOwnName(String ident) {
034 return name.getIdent().equals(ident) ? name : null;
035 }
036 }