Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend] Increase a postfix in a for loop
[Xtend] Increase a postfix in a for loop [message #686014] Tue, 21 June 2011 11:39 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

In my Xtend file, I have something like this:

«FOR variable : entity.variables»
   MyVar var;
«ENDFOR»


Now, I would like to add a unique postfix to all var variables (ideally an increasing number).

Is there a way to do this ? In Xpand, I think you could achieve that by using the ITERATOR keyword (never tried it, so I'm not sure).

Thanks,
Cédric

Re: [Xtend] Increase a postfix in a for loop [message #705863 is a reply to message #686014] Sat, 30 July 2011 13:46 Go to previous messageGo to next message
Carmela  is currently offline Carmela Friend
Messages: 10
Registered: July 2011
Junior Member
Hi,

I have a similar problem. Did you find a solution for that?

I actually wish something like this:

def callBla()'''
   «repeatBla»
   ...
   «otherstuff»
'''

def repeatBla(){
   var i = 0
   while (i <5){
      i.bla
      i=i+1
   }
}

def bla(Integer i)'''
   «i»bla 
'''



Thanks,
Carmela
Re: [Xtend] Increase a postfix in a for loop [message #705864 is a reply to message #686014] Sat, 30 July 2011 13:47 Go to previous messageGo to next message
Carmela  is currently offline Carmela Friend
Messages: 10
Registered: July 2011
Junior Member
Hi,

I have a similar problem. Did you find a solution for that?

I actually wish something like this:

def callBla()'''
   «repeatBla»
'''
def repeatBla(){
   var i = 0
   while (i <5){i.bla
      i=i+1
   }
}

def bla(Integer i)'''
   «i»bla 
'''



Thanks,
Carmela
Re: [Xtend] Increase a postfix in a for loop [message #705889 is a reply to message #705864] Sat, 30 July 2011 14:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi Carmela,

in your case the solution is easy

'''
«FOR i : 1..5»
«i»bla
«ENDFOR»			
'''


In Cédrics case its a bit more to do / work arround

'''
«FOR i : list.index»
«i.key» «i.value»
«ENDFOR»
'''


	def <T> index(Iterable<T> i) {
		val Map<Integer, T> map = <Integer, T>newHashMap()
		var counter = 0
		for (T e : i) {
			map.put(counter, e)
			counter = counter+1
		}
		val Set<Map$Entry<Integer, T>> res = map.entrySet
		res
	}


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtend] Increase a postfix in a for loop [message #706389 is a reply to message #705889] Sun, 31 July 2011 07:49 Go to previous message
Carmela  is currently offline Carmela Friend
Messages: 10
Registered: July 2011
Junior Member
Thansk a lot, Christian!
Previous Topic:generated EPackage's Literals not generated; why?
Next Topic:StackOverFlowError
Goto Forum:
  


Current Time: Sun Apr 18 22:32:14 GMT 2021

Powered by FUDForum. Page generated in 0.01376 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top