[stringtemplate-interest] Maps with object keys
Terence Parr
parrt at cs.usfca.edu
Mon Nov 26 11:06:03 PST 2007
Hi Caleb! :)
Heh, yeah, you're right...this is weird, though consistent with what
(x) means..(x) means "take the value of" or "immediately eval" rather
than lazy eval. Sometimes you need to render an expression such as
for keys with maps. It's an indirection and immediate eval.
m.x gives m.get("x")
m.(x) gives m.get(x.toString())
m.(x+"foo") gives m.get(x + "foo")
hmm...we do need a map look up with an object...i wonder what to do...
Ter
On Nov 23, 2007, at 3:34 AM, Caleb Lyness wrote:
> Hi all,
>
> I have not been keeping up to date with my string template mails...
> perhaps this has been covered before, just point me at the thread
> if already covered...
> This is also being tested against ST-3.0.
>
> Here is a segment of a test template:
>
> $products: {product |
> <tr>
> <td>$product$</td>
> <td>$report.productReadStats.(product);null="0"$</td>
> <td>$report.productActivationsStats.(product);null="0"$</td>
> <td>$report.productIssuedStats.(product);null="0"$</td>
> </tr>}$
>
> On the model side I had:
>
> public HashMap<Product, Integer> productReadStats = new
> HashMap<Product, Integer>();
> public HashMap<Product, Integer> productIssuedStats = new
> HashMap<Product, Integer>();
> public HashMap<Product, Integer> productActivationsStats = new
> HashMap<Product, Integer>();
>
> String template would always report the stats as 0 (via the null
> setting). My guess from what I am seeing
> is that ST-3.0 is dereferencing (product) to a string and not an
> object. When looking up the value in the
> map the string does not result in the correct map reference.
>
> Changing my map to a string based key:
>
> public HashMap<String, Integer> productReadStats = new
> HashMap<String, Integer>();
> ... etc ...
>
> resulted in the correct values.
>
> Is this a known problem/limitation? Or is this considered the
> correct behaviour. Surely an attempt should be
> made to lookup the object directly and then use the object.toString
> () as the key as a 2nd attempt?
>
> Cheers
> Caleb.
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list