Skip to main content


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 Friend
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 Friend
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 ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
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, EMF, Eclipse IDE?
Go to: http://devhub.karakun.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 Friend
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: Thu Apr 18 11:35:03 GMT 2024

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

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

Back to the top