xtend - Count value in template expression -


i want count value inside template expression, in xtend, without printing out.

this code:

def generatetower(tower in) {     var counter = 0.0; ''' 1         2             3           4 «for line : in.mytable» «counter»   «line.val1»     «line.val2»     «line.val3» «counter = counter + 1» «endfor» '''     } 

so generate table 4 columns, whereas first column incremented starting @ 0.0. problem is, «counter = counter + 1» printed well. want expression above count up, without printing out.

what best solution solve problem?

you use simple , readable solution:

«for line : in.mytable» «counter++»   «line.val1»     «line.val2»     «line.val3» «endfor» 

if insist on separate increment expression, use block null value. works because null value converted empty string in template expressions (of course use "" well):

«for line : in.mytable» «counter»   «line.val1»     «line.val2»     «line.val3» «{counter = counter + 1; null}» «endfor» 

although first solution better. if require complex logic in template expression recommend implementing methods not inline code...

and finally, here more oo solution problem:

class towergenerator {     static val tab = "\t"      def generatetower(tower in) {         var counter = 0          '''             one«tab»two«tab»three«tab»four             «for line : in.mytable»                 «generateline(line, counter++)»             «endfor»         '''     }      def private generateline(line line, int linenumber) '''         «linenumber»«tab»«line.val1»«tab»«line.val2»«tab»«line.val3»     ''' } 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -