diff -r 3e30c95da3c6 -r 8f0dcb9499db src/share/classes/com/sun/tools/javac/util/Context.java --- a/src/share/classes/com/sun/tools/javac/util/Context.java Thu Feb 24 08:40:49 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/util/Context.java Fri Feb 25 12:09:33 2011 -0800 @@ -108,7 +108,7 @@ * instance. */ public static interface Factory { - T make(); + T make(Context c); }; /** @@ -124,6 +124,8 @@ Object old = ht.put(key, fac); if (old != null) throw new AssertionError("duplicate context value"); + checkState(ft); + ft.put(key, fac); // cannot be duplicate if unique in ht } /** Set the value for the key in this context. */ @@ -142,7 +144,7 @@ Object o = ht.get(key); if (o instanceof Factory) { Factory fac = (Factory)o; - o = fac.make(); + o = fac.make(this); if (o instanceof Factory) throw new AssertionError("T extends Context.Factory"); Assert.check(ht.get(key) == o); @@ -158,6 +160,20 @@ public Context() {} + /** + * The table of preregistered factories. + */ + private Map,Factory> ft = new HashMap,Factory>(); + + public Context(Context prev) { + kt.putAll(prev.kt); // retain all implicit keys + ft.putAll(prev.ft); // retain all factory objects + ht.putAll(prev.ft); // init main table with factories + } + + /* + * The key table, providing a unique Key for each Class. + */ private Map, Key> kt = new HashMap, Key>(); private Key key(Class clss) { @@ -198,6 +214,7 @@ public void clear() { ht = null; kt = null; + ft = null; } private static void checkState(Map t) {