Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Index of element in the whole tree
Index of element in the whole tree [message #1730235] Fri, 22 April 2016 13:20 Go to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Hello,

Um, I want to get the index of an element relative to all the other elements of its type.

I have used something like this before in java code, but now I am using Xtend.

EcoreUtil2.indexOf((List)container.eContainer().eGet(container.eContainingFeature()), container, 0);


How can I achieve a similar behavior using Xtend.

Thanks
Re: Index of element in the whole tree [message #1730238 is a reply to message #1730235] Fri, 22 April 2016 13:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The same code should work with xtend

You cast with

Xxxx as List


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Index of element in the whole tree [message #1730239 is a reply to message #1730238] Fri, 22 April 2016 13:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
e.g.

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		fsa.generateFile('greetings.txt', '''
		«FOR g : resource.allContents.filter(Greeting).toIterable»
		«g.indexOf» «g.name»
		«ENDFOR»
		''')
	}
	
	def int indexOf(EObject o) {
		ECollections.indexOf(o.eContainer.eGet(o.eContainingFeature) as List<Greeting>, o, 0)
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Providing text through JavaScript
Next Topic:Include Xtext document formating as model elements
Goto Forum:
  


Current Time: Thu Apr 25 15:30:22 GMT 2024

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

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

Back to the top