Skip to main content



      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 07:39 Go to next message
Eclipse UserFriend
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 09:46 Go to previous messageGo to next message
Eclipse UserFriend
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 09:47 Go to previous messageGo to next message
Eclipse UserFriend
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 10:20 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [Xtend] Increase a postfix in a for loop [message #706389 is a reply to message #705889] Sun, 31 July 2011 03:49 Go to previous message
Eclipse UserFriend
Thansk a lot, Christian!
Previous Topic:generated EPackage's Literals not generated; why?
Next Topic:StackOverFlowError
Goto Forum:
  


Current Time: Fri Nov 07 17:23:26 EST 2025

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

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

Back to the top