[stringtemplate-interest] inconsistency with length function

John Snyders jjsnyders at rcn.com
Tue Jan 16 21:51:46 PST 2007


The length function knows how to get the length of List, Map, arrays, and
Iterator. However convertAnythingIteratableToIterator and
convertAnythingToIterator are more general and get iterators for Collection
rather than List.

I think that the length method in ASTExpr.java should be changed as follows:

From:

} else if (attribute instanceof List) {
  i = ((List)attribute).size();
}

To:

} else if (attribute instanceof Collection) {
  i = ((List)attribute).size();
}

In addition I don't think Iterator should be handled like it is. Getting the
length of an iterator will use it up so that it can't be used again.
Some rethinking of how iterators are dealt with is needed. Until then it
would be good practice to never pass an iterator in as a ST attribute.

The issue is the same as what lead to Iterable being added to Java 5 in
order to support the new foreach syntax. Because an iterator is single use
only there needed to be a way to get the iterator again and again.

Thanks,
-John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20070117/cfd7cd13/attachment.html 


More information about the stringtemplate-interest mailing list