I've only been using StringTemplate 4 for a week, so it's probably something I'm doing, but I don't seem to be able to make the <if>
work.
I'm using 4.02 (since that's the latest in Maven repository). I have a class called Variable
. This is a snippet:
class Variable
{
...
public boolean isArray()
{
return _bIsArray;
}
}
I have a template that has a line(delimiter is $
, $
):
$if(x.isArray)$ $ArrayAdd(x, className)$ $endif$
If I remove the if
and simply let it execute $ArrayAdd(...)$
for everything, the ArrayAdd
is clearly executed. I then put the $if$
back in. I also put a print statement in isArray()
and isArray()
is getting executed and returns false
most of the time, but does return true
once in a while (for exactly the cases I expected). However, $ArrayAdd
never gets executed from within the $if$
.
I looked at the trace (which I'm not good at reading) and got:
declareSetGet:0227: load_local 0 stack=[ ], calls=ObjectClass _sub1
declareSetGet, sp=-1, nw=0
declareSetGet:0230: load_prop #25:"isArray" stack=[
altLocation<CUSTOM>::Array<1>::Custom<altLocationObj> ], calls=ObjectClass _sub1
declareSetGet, sp=0, nw=0
declareSetGet:0233: brf 254 stack=[ null ], calls=ObjectClass _sub1
declareSetGet, sp=0, nw=0
ObjectClass:0121: newline stack=[ ], calls=ObjectClass, sp=-1, nw=959
ObjectClass:0122: write_str #15:"}" stack=[ ], calls=ObjectClass, sp=-1, nw=0
This is one of the cases where I would expect the ArrayAdd
template to be executed. Obviously, it doesn't.
Can anyone tell me what I'm missing?