KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > js > ast > JsCatchScope


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.NoSuchElementException JavaDoc;
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 JavaDoc ident) {
30     super(parent, "Catch scope");
31     this.name = new JsName(ident, ident);
32   }
33
34   public JsName declareName(String JavaDoc ident) {
35     // Declare into parent scope!
36
return getParent().declareName(ident);
37   }
38
39   public JsName declareName(String JavaDoc ident, String JavaDoc shortIdent) {
40     // Declare into parent scope!
41
return getParent().declareName(ident, shortIdent);
42   }
43
44   public Iterator JavaDoc getAllNames() {
45     return new Iterator JavaDoc() {
46       private boolean didIterate = false;
47
48       public boolean hasNext() {
49         return !didIterate;
50       }
51
52       public Object JavaDoc next() {
53         if (didIterate) {
54           throw new NoSuchElementException JavaDoc();
55         }
56         didIterate = true;
57         return name;
58       }
59
60       public void remove() {
61         throw new UnsupportedOperationException JavaDoc();
62       }
63
64     };
65   }
66
67   protected JsName doCreateName(String JavaDoc ident, String JavaDoc shortIdent) {
68     throw new UnsupportedOperationException JavaDoc(
69         "Cannot create a name in a catch scope");
70   }
71
72   protected JsName findExistingNameNoRecurse(String JavaDoc ident) {
73     if (name.getIdent().equals(ident)) {
74       return name;
75     } else {
76       return null;
77     }
78   }
79
80 }
81
Popular Tags