01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.js.ast;
17:
18: import java.util.Iterator;
19: import java.util.NoSuchElementException;
20:
21: /**
22: * A special scope used only for catch blocks. It only holds a single symbol:
23: * the catch argument's name.
24: */
25: public class JsCatchScope extends JsScope {
26:
27: private final JsName name;
28:
29: public JsCatchScope(JsScope parent, String ident) {
30: super (parent, "Catch scope");
31: this .name = new JsName(this , ident, ident);
32: }
33:
34: @Override
35: public JsName declareName(String ident) {
36: // Declare into parent scope!
37: return getParent().declareName(ident);
38: }
39:
40: @Override
41: public JsName declareName(String ident, String shortIdent) {
42: // Declare into parent scope!
43: return getParent().declareName(ident, shortIdent);
44: }
45:
46: @Override
47: public Iterator<JsName> getAllNames() {
48: return new Iterator<JsName>() {
49: private boolean didIterate = false;
50:
51: public boolean hasNext() {
52: return !didIterate;
53: }
54:
55: public JsName next() {
56: if (didIterate) {
57: throw new NoSuchElementException();
58: }
59: didIterate = true;
60: return name;
61: }
62:
63: public void remove() {
64: throw new UnsupportedOperationException();
65: }
66:
67: };
68: }
69:
70: @Override
71: protected JsName doCreateName(String ident, String shortIdent) {
72: throw new UnsupportedOperationException(
73: "Cannot create a name in a catch scope");
74: }
75:
76: @Override
77: protected JsName findExistingNameNoRecurse(String ident) {
78: if (name.getIdent().equals(ident)) {
79: return name;
80: } else {
81: return null;
82: }
83: }
84:
85: }
|