KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > types > CofferContext_c


1 package polyglot.ext.coffer.types;
2
3 import polyglot.ext.jl.types.*;
4 import polyglot.types.*;
5 import polyglot.util.*;
6 import java.util.*;
7
8 public class CofferContext_c extends Context_c implements CofferContext {
9     protected Map keys;
10
11     public CofferContext_c(TypeSystem ts) {
12         super(ts);
13     }
14
15     protected Context_c push() {
16         CofferContext_c c = (CofferContext_c) super.push();
17         c.keys = null;
18         return c;
19     }
20
21     public void addKey(Key key) {
22         if (keys == null) {
23             keys = new HashMap();
24         }
25
26         keys.put(key.name(), key);
27     }
28
29     public Key findKey(String JavaDoc name) throws SemanticException {
30         Key key = null;
31
32         if (keys != null) {
33             key = (Key) keys.get(name);
34         }
35
36         if (key != null) {
37             return key;
38         }
39
40         if (outer != null) {
41             return ((CofferContext) outer).findKey(name);
42         }
43
44         throw new SemanticException("Key \"" + name + "\" not found.");
45     }
46
47     protected String JavaDoc mapsToString() {
48         return super.mapsToString() + " keys=" + keys;
49     }
50 }
51
Popular Tags