[stringtemplate-interest] Ok, I'm stumped
Barnes, Jeff
JB0284 at att.com
Mon Aug 6 09:24:50 PDT 2007
True dat... This code better illuminates the problem. I guess I better go back and revise some unit tests... ;-)
import org.antlr.stringtemplate.StringTemplate;
public class Test
{
static class Form {
String[] names;
boolean[] values;
public String[] getNames() { return names; }
public boolean[] getValues() { return values; }
}
public static void main(String[] args)
{
Form f = new Form();
f.names = new String[] { "Terence", "Parr" };
f.values = new boolean[] { false, true };
StringTemplate st = new StringTemplate(
"$form.names,form.values:{ name, value |\n" +
"$name$\n" +
"$value$ " +
"$if(value)$I'm True$else$I'm False$endif$" +
"};separator=\"\n\"$");
st.setAttribute("form", f);
System.out.println(st.toString());
}
}
-----Original Message-----
From: Kay Roepke [mailto:kroepke at classdump.org]
Sent: Monday, August 06, 2007 12:08 PM
To: Barnes, Jeff
Cc: StringTemplate; Terence Parr
Subject: Re: [stringtemplate-interest] Ok, I'm stumped
Hi Jeff!
On Aug 6, 2007, at 5:35 PM, Barnes, Jeff wrote:
> Huh???
mh.
> Note: reversing the Boolean values gives the 'correct' output.
It only appears to do so...
> Huh???
Huh! :)
Using Boolean objects makes this work.
Don't ask my why, but adding $value$ to the $if$ clearly shows that
the boolean[] is passed
into ST wholesale and the first time evaluates to true (its pointer)
and the second time the
form.values is exhausted and evaluates to false.
I didn't expect it to do so, either. Ter, is this supposed to work?
cheers,
-k
--
Kay Röpke
http://classdump.org/
More information about the stringtemplate-interest
mailing list