I'll review the rest separately, but I wanted to get this to you first.


http://gwt-code-reviews.appspot.com/826802/diff/3001/4001
File dev/core/src/com/google/gwt/core/ext/GeneratorContext.java (right):

http://gwt-code-reviews.appspot.com/826802/diff/3001/4001#newcode74
dev/core/src/com/google/gwt/core/ext/GeneratorContext.java:74: Object
getContextStorage(String key);
I think I would prefer to separate this out, and make it parameterized.
You also need to worry about collisions from different generators/etc,
so I would recommend something more like:

interface Cache<K,V> {
  boolean contains(K);
  V get(K key);
  void put(K key, V value);
}

in GeneratorContext:
  <K,V> Cache<K,V> getCache(Class<?> clazz);

So a generator would do something like:

   Cache<GwtLocale, AbstractResource> cache =
ctx.getCache(MyGenerator.class);
   AbstractReource res = cache.get(locale);
   if (res == null) {
     res = computeResource(locale);
     cache.put(locale, res);
   }

That way you get type safety and avoid collisions, rather than having to
have every caller follow some convention of constructing the string
keys.  You could even define getCache on an interface which
GeneratorContext implements, which would make it easier to mock uses of
the cache.

http://gwt-code-reviews.appspot.com/826802/show

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to