Number of Total Model Elements Before and After Deletion [message #1746511] |
Mon, 31 October 2016 13:23 |
Eclipse User |
|
|
|
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 #1746519 is a reply to message #1746516] |
Mon, 31 October 2016 14:36 |
Eclipse User |
|
|
|
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;
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03335 seconds