[stringtemplate-interest] Support or interface Iterable

John Snyders jjsnyders at rcn.com
Wed Oct 18 09:31:30 PDT 2006


Is there a reason why string template does not allow the iteration syntax
<attribute:{template}> for things that are Iterable but not a collection?

The methods convertAnythingToIterator and
convertAnythingIteratableToIterator in ASTExpr.java do allow Collection but
do not allow Iterable. Collection extends Iterable and since the only
functionality of a collection that is available (rightly so) to a template
is iteration it seems to me that Collection should be changed to Iterable in
these methods.

In the methods convertAnythingToIterator and
convertAnythingIteratableToIterator I changed

    if ( o instanceof Collection ) {
        iter = ((Collection)o).iterator();
    }
    ...
to

    if ( o instanceof Iterable) {
        iter = ((Iterable)o).iterator();
    }
    ...

So far I have not seen any problems related to this change but I did not do
extensive testing.

Most things iterable are also collections but if you are trying to wrap
something that is not a collection for ST and want it to to be iterable it
is much easer to create a wrapper that implements Iterable rather than
Collection.

-John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061018/78539f67/attachment.html 


More information about the stringtemplate-interest mailing list