[stringtemplate-interest] Ok, I'm stumped
Barnes, Jeff
JB0284 at att.com
Mon Aug 6 12:19:45 PDT 2007
My version src of
org.antlr.stringtemplate.language.ASTExpr.convertArrayToList(Object)
starts off like
if ( value==null ) {
return null;
}
/*
if ( !(value instanceof StringTemplate) ) {
System.out.println("convert "+value+" to
array?");
}
*/
/*
if ( !arraysConvertibleToList.contains(value.getClass())
&&
!(value instanceof Object[]) )
{
return value;
}
*/
if ( value instanceof Object[] ) {
Object[] list = (Object[])value;
List v = new
StringTemplate.STAttributeList(list.le
ngth);
for (int i = 0; i < list.length; i++) {
Object elem = list[i];
v.add(elem);
}
value = v;
}
else if ( value instanceof int[] ) {
int[] list = (int[])value;
List v = new
StringTemplate.STAttributeList(list.le
ngth);
for (int i = 0; i < list.length; i++) {
int elem = list[i];
v.add(new Integer(elem));
}
value = v;
}
else if ( value instanceof long[] ) {
long[] list = (long[])value;
List v = new
StringTemplate.STAttributeList(list.le
ngth);
for (int i = 0; i < list.length; i++) {
long elem = list[i];
v.add(new Long(elem));
}
value = v;
}
else if ( value instanceof float[] ) {
float[] list = (float[])value;
List v = new
StringTemplate.STAttributeList(list.le
ngth);
for (int i = 0; i < list.length; i++) {
float elem = list[i];
v.add(new Float(elem));
...
There is no check for Boolean array.
The latest and greatest is a much shorter method:
public static Object convertArrayToList(Object value) {
if ( value==null ) {
return null;
}
if ( value.getClass().isArray() ) {
if (
value.getClass().getComponentType().isPrimitive() ) {
return new ArrayWrappedInList(value);
}
return Arrays.asList((Object[])value);
}
return value;
}
Hope this helps.
Jeff
-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Barnes,
Jeff
Sent: Monday, August 06, 2007 3:02 PM
To: StringTemplate
Subject: Re: [stringtemplate-interest] Ok, I'm stumped
I just downloaded from stringtemplate.org and get the same results. When
did you push last?
Jeff
-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Barnes,
Jeff
Sent: Monday, August 06, 2007 2:52 PM
To: StringTemplate
Subject: Re: [stringtemplate-interest] Ok, I'm stumped
My distro is about a month old...
Terence
[Z at 1ffbd68 I'm True
Parr
I'm False
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: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence
Parr
Sent: Monday, August 06, 2007 2:47 PM
To: StringTemplate
Subject: Re: [stringtemplate-interest] Ok, I'm stumped
On Aug 6, 2007, at 11:37 AM, Barnes, Jeff wrote:
> No it doesn't work either.
wow!
Hmm...maybe I fixed something. I get
/tmp $ java Test
Terence
false I'm False
Parr
true I'm True
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());
}
which seems right given false followed by true.
Ter
_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org
http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org
http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
_______________________________________________
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