Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Number of Total Model Elements Before and After Deletion
Number of Total Model Elements Before and After Deletion [message #1746511] Mon, 31 October 2016 13:23 Go to next message
Bugra M. Yildiz is currently offline Bugra M. YildizFriend
Messages: 105
Registered: July 2014
Senior Member
Hello,

I have the following model transformation:

pre pre_deleteSomeElements
{
	"\n\nBefore the operation: ".println();
	printStatistics();
	
	deleteExceptionalElements();
}

post post_deleteSomeElements
{
	"\n\nAfter the operation: ".println();
	printStatistics();	
}

//Prints the statistics of the 
operation printStatistics()
{
	("Number of exceptional elements: " + InModel!ExceptionalElements.allInstances().size() + "").println();
}


Even though, I run it two times on the same model. The outputs are:

===== Run 1 =====
Before the operation: 
Number of exceptional edges: 35

After the operation: 
Number of exceptional edges: 35

===== Run 2 =====
Before the operation: 
Number of exceptional edges: 0

After the operation: 
Number of exceptional edges: 0


It seems that the transformation actually deletes the elements, however the InModel!ExceptionalElements.allInstances() call still refers to the state of the input model at the beginning instead of its current state.

Is it an implementation mistake of the engine or is it an intentional choice?
Re: Number of Total Model Elements Before and After Deletion [message #1746516 is a reply to message #1746511] Mon, 31 October 2016 14:01 Go to previous messageGo to next message
Ran Wei is currently offline Ran WeiFriend
Messages: 75
Registered: September 2012
Location: York, UK
Member
Hi,

Could you provide your implementation of deleteExceptionalElements()?

Cheers,
Will


Research Associate
Department of Computer Science
University of York
Re: Number of Total Model Elements Before and After Deletion [message #1746519 is a reply to message #1746516] Mon, 31 October 2016 14:36 Go to previous messageGo to next message
Bugra M. Yildiz is currently offline Bugra M. YildizFriend
Messages: 105
Registered: July 2014
Senior Member
A partial view from the metamodel:

abstract class OwnerElement
{
		property outEdges#start : Element[*] { ordered composes };
		property inEdges#end : Element[*] { ordered };
		
		//... some properties and attributes		
}

abstract class Element
{
	property start#outEdges : OwnerElement[1];
	property end#inEdges : OwnerElement[1];
}

class ExceptionalElement extends Element
{
	property details : ExceptionalElementDetails[1];
}

class ExceptionalElementDetails
{
	//... some properties and attributes
}


The implementation of the deletion:,

//Delete ExceptionalElements instances
operation deleteExceptionalElements()
{
	//Getting all the exceptional elements as a list
	var exceptionalElementsList = InModel!ExceptionalElement.allInstances();
	
	//Setting the start reference to null to remove the containment reference
	for(ee:InModel!ExceptionalElement in exceptionalElementsList)
	{
		ee.start = null;		
	}
	
	//Deleting the exceptional elements one by one
	while(not eexceptionalElementsList.isEmpty())
	{
		var ee = exceptionalElementsList.removeAt(exceptionalElementsList.size()-1);
		delete ee;
	}	
}
Re: Number of Total Model Elements Before and After Deletion [message #1746613 is a reply to message #1746519] Tue, 01 November 2016 19:31 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1498
Registered: July 2009
Location: York, UK
Senior Member

Hi Bugra,

Does replacing the body of deleteExceptionalElements() with the following statement do the trick?

delete InModel!ExceptionalElement.allInstances();


Cheers,
Dimitris
Re: Number of Total Model Elements Before and After Deletion [message #1746617 is a reply to message #1746613] Tue, 01 November 2016 22:25 Go to previous messageGo to next message
Bugra M. Yildiz is currently offline Bugra M. YildizFriend
Messages: 105
Registered: July 2014
Senior Member
Yes, it works!

Do you know what is the reason why the previous version was not working?
Re: Number of Total Model Elements Before and After Deletion [message #1746947 is a reply to message #1746617] Tue, 08 November 2016 00:24 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1498
Registered: July 2009
Location: York, UK
Senior Member

Hi Bugra,

Off the top of my head, "ee.start = null;" detaches ee from the model containment tree and as such the model does not consider it as one of its elements any more. As a result "delete ee" has no effect and the allInstances() cache is not updated.

Cheers,
Dimitris
Previous Topic:Label attribute do not exist in class
Next Topic:Visualize the generated model as UML diagram no as ecore
Goto Forum:
  


Current Time: Mon Jan 22 22:35:44 GMT 2018

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

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