Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Create Model Element/Object on Validation
Create Model Element/Object on Validation [message #1731394] Wed, 04 May 2016 18:59 Go to next message
Eclipse UserFriend
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 #1731402 is a reply to message #1731394] Wed, 04 May 2016 20:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

This seems like a mandatory constraint regarding some element in your DSL. Why you don't show the error (instead of a warning) and offer a quick fix? the quick fix would add a line in the specification, in order to correct the problem.

Miguel.
Re: Create Model Element/Object on Validation [message #1731404 is a reply to message #1731402] Wed, 04 May 2016 20:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi Miguel,

The problem with quick fix is that, the user is not really working with the (textual DSL) editor. I am providing a graphical tool for the user so he/she might have a very limited knowledge of the syntax and might not even be aware that they can manipulate textual file !!! I can manage it in my graphical tool and satisfy this constraint, how ever I just wanted to let XText do it for me as it is safer !

Thanks,
Parsa
Re: Create Model Element/Object on Validation [message #1731417 is a reply to message #1731404] Thu, 05 May 2016 00:55 Go to previous messageGo to next message
Eclipse UserFriend
What is the business Vase for this.What do you mean By create. Physically create Or logically create. The First one is a Bad idea - it is more a usecase for a QuickFx.. The Second one can be achieved Not by using a validator but using a derivedstatecomputer
Re: Create Model Element/Object on Validation [message #1731456 is a reply to message #1731417] Thu, 05 May 2016 08:57 Go to previous message
Eclipse UserFriend
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
Previous Topic:Problem with inferred type and super type declaration
Next Topic:[Delete]
Goto Forum:
  


Current Time: Thu Jul 24 00:08:08 EDT 2025

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

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

Back to the top