[stringtemplate-interest] added v4 model adaptor

Terence Parr parrt at cs.usfca.edu
Thu Dec 23 17:22:06 PST 2010


Implemented draft model adaptor mech. for v4.  You call group.registerModelAdaptor in least to most specific order. ST registers ObjectModelAdaptor first, for example, for Object.class.  Then you can add one for, say, Users:

		group.registerModelAdaptor(User.class, new UserAdaptor());
		ST st = group.getInstanceOf("foo");
		st.add("x", new User(100, "parrt"));

It does most-specific and last match so it uses UserAdaptor not ObjectModelAdaptor here.  If two adaptors fit User, it chooses that last one added.

I do *not* allow per ST model adaptors.  Can't really think of use case and don't want to pollute ST with a field.

I do *not* look to import groups for adaptors.  They aren't really supergroups anymore and it rquires that I do a best-fit which is not simple enough. I like the most-specific, ordered lookup.  I can't really see a use case for importing adaptors.  

I *do* see that renderers are different and we should be able to decorate different templates with different renderers.

As this is mutually-orthogonal, should be easy to backpatch into v3. should I?

Ter


More information about the stringtemplate-interest mailing list