0

i have a Problem with the Xtend Template Notation.

I want to do «i=i+1» in a template method

def generateSomething() '''
...
«i=i+1»
... 
'''

The «i=i+1» is obviously only to count i higher but it also shows the value of i in the generated file too. But i dont want that. Is there a way to solve this problem without changing the method?

Jon
  • 398
  • 1
  • 11

3 Answers3

3

You could use a block expression :

def generateSomething() '''
...
«{i=i+1 ''}»
... 
'''
Sven Efftinge
  • 3,065
  • 17
  • 17
1

If it is possible to used AtomicInteger instead of an int for your code then this should work.

val i = new AtomicInteger
val generated = '''
        ...
        «i.andIncrement»
        ... 
        '''
Delaney
  • 1,039
  • 1
  • 9
  • 15
0

«FOR i : 0..iMaxInclusive» some text «somelist.get(i)» more text «ENDFOR»

Jon
  • 398
  • 1
  • 11