1.1 --- a/src/share/classes/com/sun/tools/javac/util/Context.java Thu Feb 24 08:40:49 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/util/Context.java Fri Feb 25 12:09:33 2011 -0800 1.3 @@ -108,7 +108,7 @@ 1.4 * instance. 1.5 */ 1.6 public static interface Factory<T> { 1.7 - T make(); 1.8 + T make(Context c); 1.9 }; 1.10 1.11 /** 1.12 @@ -124,6 +124,8 @@ 1.13 Object old = ht.put(key, fac); 1.14 if (old != null) 1.15 throw new AssertionError("duplicate context value"); 1.16 + checkState(ft); 1.17 + ft.put(key, fac); // cannot be duplicate if unique in ht 1.18 } 1.19 1.20 /** Set the value for the key in this context. */ 1.21 @@ -142,7 +144,7 @@ 1.22 Object o = ht.get(key); 1.23 if (o instanceof Factory<?>) { 1.24 Factory<?> fac = (Factory<?>)o; 1.25 - o = fac.make(); 1.26 + o = fac.make(this); 1.27 if (o instanceof Factory<?>) 1.28 throw new AssertionError("T extends Context.Factory"); 1.29 Assert.check(ht.get(key) == o); 1.30 @@ -158,6 +160,20 @@ 1.31 1.32 public Context() {} 1.33 1.34 + /** 1.35 + * The table of preregistered factories. 1.36 + */ 1.37 + private Map<Key<?>,Factory<?>> ft = new HashMap<Key<?>,Factory<?>>(); 1.38 + 1.39 + public Context(Context prev) { 1.40 + kt.putAll(prev.kt); // retain all implicit keys 1.41 + ft.putAll(prev.ft); // retain all factory objects 1.42 + ht.putAll(prev.ft); // init main table with factories 1.43 + } 1.44 + 1.45 + /* 1.46 + * The key table, providing a unique Key<T> for each Class<T>. 1.47 + */ 1.48 private Map<Class<?>, Key<?>> kt = new HashMap<Class<?>, Key<?>>(); 1.49 1.50 private <T> Key<T> key(Class<T> clss) { 1.51 @@ -198,6 +214,7 @@ 1.52 public void clear() { 1.53 ht = null; 1.54 kt = null; 1.55 + ft = null; 1.56 } 1.57 1.58 private static void checkState(Map<?,?> t) {