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, @NotNull String ident) {
017 super(parent, "Catch scope", null);
018 name = new JsName(this, ident);
019 }
020
021 @Override
022 @NotNull
023 public JsName declareName(@NotNull String identifier) {
024 // Declare into parent scope!
025 return getParent().declareName(identifier);
026 }
027
028 @Override
029 public boolean hasOwnName(@NotNull String name) {
030 return findOwnName(name) != null;
031 }
032
033 @NotNull
034 public JsCatchScope copy() {
035 return new JsCatchScope(getParent(), name.getIdent());
036 }
037
038 @Override
039 protected JsName findOwnName(@NotNull String ident) {
040 return name.getIdent().equals(ident) ? name : null;
041 }
042 }