stringtemplate - StringTemplate4 if conditional with length -
i need generate following kinds of code stringtemplate4:
methodfoo0(connection conn); methodfoo1(connection conn, int arg1); methodfoo2(connection conn, int arg1, int arg2); etc. the "connection conn" part present passing method name , rest of arguments st template. template looks follows:
<methodname>(connection conn, <args; separator=", ">); this works produces comma when there no arguments @ (except conn):
methodfoo0(connection conn,); to eliminate comma tried using if conditional , length st4 function couldn't work although tried various combos following:
<methodname>(connection conn <if (length(fieldsinfind) \> 0)>,<else><endif><fieldsinfind; separator=", ">) ... , others failed parsing-related error (mismatched input).
in end, gave , resorted passing comma parameter template either "," or empty string "" based on pre-rendering logic.
you check presence of second parameter using <if (fieldsinfind)> , pass template if size greater 0.
Comments
Post a Comment