[stringtemplate-interest] [ST4] How to avoid map key iteration?

Udo Borkowski ub at abego-software.de
Fri Feb 11 05:45:55 PST 2011


Hi,

is there any way to prevent the "iteration" over map keys when using a template like <m:{t|…}> (m may be a map or a simple object)?

Details:

I am using a template like this:

writeAddress(adr) ::= <<
...
<adr:{t|<t.zip> <t.city>}>
...
>>

adr represents an "Address" with properties "street", "zip", "city" etc.

Initially this was implemented by a bean-style model class Address. Everything worked as expected.

Now I changed the model class to a more "dynamic" implementation by using a Map. I.e. "zip", "city", etc. are now keys in the map, mapping to their resp. values.

Expressions like this:

<a.zip>

still work fine, but 

<adr:{t|<t.zip> <t.city>}>

runs into an error: 

no such property or can't access: java.lang.String.zip

This is because the new model instance "accidentally" is a Map and the expression now iterates over the keys of the map ("zip" being the first).

How can this iteration be avoided?


Udo


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110211/e4611c21/attachment.html 


More information about the stringtemplate-interest mailing list