Create Model Element/Object on Validation [message #1731394] |
Wed, 04 May 2016 18:59  |
Eclipse User |
|
|
|
Hi,
I need to make sure that the model always has one instance of an Object in the model. Thus, I decided to add the following code in the validation xtend class to see if the object is not there, then create one!
So, in the following code, if wm does not have an instance of constraints , it should create one !
@Check
def checkConstraintsElementExist(WorldModel wm) {
if (wm.constraints == null) {
wm.constraints = FormlFactory::eINSTANCE.createConstraint
warning('World Model Must have at least one Constraint Element(even if empty)',
FormlPackage.Literals.WORLD_MODEL__CONSTRAINTS);
}
}
I tried to debug it, when the validator reaches to the line : wm.constraints = FormlFactory::eINSTANCE.createConstraint , it adds to wm , however it doesnot apply to the original model/resource. And if I run it next time it is still null !
Sorry, I'm not expert in XTend ! Is it the way it should be or I'm doing sth wrong ?
Thanks,
Bests,
Parsa
|
|
|
|
|
|
Re: Create Model Element/Object on Validation [message #1731456 is a reply to message #1731417] |
Thu, 05 May 2016 08:57  |
Eclipse User |
|
|
|
Hi Christian,
Let me explain mygrammar:
System:
wm=[WorldModel]
bm=[BehaviouralModel]
;
WorldModel:
concepts=[Concept] & cons=[Constraint] ;
Constraint: ....
...
So, I want to make sure at any time and at any state my model contains an instance of Constraint in WorldModel.
I know it can be done by quickfix, but I'd rather like to do it automatically, so that the user does not need to open the textual file or leave the graphical editor in order to add this object in the model.
I'll take a look at derivedstatecomputer and see how it works.
Thank you,
Bests,
Parsa
|
|
|
Powered by
FUDForum. Page generated in 0.10298 seconds