[stringtemplate-interest] question about toString and maps
Jonathan Buhacoff
jonathan at buhacoff.net
Mon Oct 19 16:35:34 PDT 2009
Oops, "lines" :)
I tried overriding values() but it turns out that method is more
popular than I thought, and overriding it had unexpected side effects
for me. Plus, if I override values(), then I can't ever use it in my
templates for iteration, even if I want to.
The LabledMap type is fully compatible with Map and doesn't have any
side effects.
Here's the diff:
605a606
> if( a instanceof LabledMap ) { return true; }
953a955
> else if ( o instanceof LabledMap ) { return o; }
970a973,977
> else if ( o instanceof LabledMap ) {
> List singleton = new StringTemplate.STAttributeList(1);
> singleton.add(o);
> return singleton.iterator();
> }
And here's LabledMap, which I placed in the "language" package next to
ASTExpr:
public interface LabledMap {}
And here is the declaration of my adapter class:
public class PropertyTreeAdapter implements Map<String,Object>,
LabledMap { ... }
Jonathan
On Oct 19, 2009, at 3:41 PM, Barrie Treloar wrote:
> On Tue, Oct 20, 2009 at 7:31 AM, Jonathan Buhacoff
> <jonathan at buhacoff.net> wrote:
>> A little update - I added just a handful of lies to my copy of
>> ASTExpr
>> this morning and added the LabledMap interface, and it's working
>> great.
>
> "Lies"?
>
> p.s. Can't you subclass your Map and override values() to hack the
> output ST expects?
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list