Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » <Xtend> How to delete a UseCase from a list
<Xtend> How to delete a UseCase from a list [message #533387] Thu, 13 May 2010 15:58 Go to next message
Akhtar  is currently offline Akhtar
Messages: 13
Registered: April 2010
Junior Member
Hi,

I am trying to delete actor from the list with following xtend code,
import uml;


uml::Model root(uml::Model model):
	let actorList = model.eAllContents.typeSelect(Actor).collect(e|e):
	actorList.forAll(e|deleteActor(findActor(actorList, "User")))->
		model; 

// find Actor
List[uml::Actor] findActor(List[uml::Actor] ac, String name):
	ac.select(e|e.name == name);
	
// delete Actor 	
Boolean deleteActor(List[uml::Actor] ac1):
	ac1.remove(ac1)->true;


workflow executed but actor remains there.
Any one can point where I am wrong or I m missing some thing.

Regards,
Akhtar
Re: <Xtend> How to delete a UseCase from a list [message #533388 is a reply to message #533387] Thu, 13 May 2010 16:00 Go to previous messageGo to next message
Akhtar  is currently offline Akhtar
Messages: 13
Registered: April 2010
Junior Member
sorry for the title, it should be how to delete actor from the list.
Re: <Xtend> How to delete a UseCase from a list [message #533470 is a reply to message #533387] Fri, 14 May 2010 07:32 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

Hi Akhtar,

there are several misconceptions in your code here:

1) .collect(e|e) does not do anything
2) I think you use forAll(), but indeed should use collect(). Although forAll does loop through the collection as well as collect(), forAll will return a boolean when checking that all elements in the collection meet the condition inside. That's not what you are intending here.
3) actorList is a new collection, it is no reference to the set of actors in the model, it just contains them. Calling the deleteActor function will actually remove the actor from actorList, but not from the model.

I think what you really want to achieve is to delete the actor "User" really from the model. To do so you would have to use org.eclipse.emf.ecore.util.EcoreUtil#delete(), which must be called through a Java extension.

Void delete (emf::EObject): org.eclipse.emf.ecore.util.EcoreUtil.delete(org.eclipse.emf.ecore.EObject);


Call this fuction by searching the model for your actor:

model.eAllContents.typeSelect(Actor).selectFirst(e|e.name=="User").delete();


HTH,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: <Xtend> How to delete a UseCase from a list [message #533505 is a reply to message #533470] Fri, 14 May 2010 10:21 Go to previous message
Akhtar  is currently offline Akhtar
Messages: 13
Registered: April 2010
Junior Member
Hi Karsten,

Thanks for correcting me. I use Java extension and it works fine.

regards,
Akhtar
Previous Topic:[Xpand] Cannot access eAnnotations of EEnumLiteral
Next Topic:Extend file
Goto Forum:
  


Current Time: Wed Oct 01 06:01:57 GMT 2014

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

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