Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom validation of constraints from existing metamodel
Custom validation of constraints from existing metamodel [message #1776346] Wed, 15 November 2017 14:03 Go to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 40
Registered: May 2012
Member
Hello,
I have a legacy Ecore metamodel that I cannot modify where a EClass "Foo" has an attribute "bar" with multiplicity 1 -- i.e., it is a required attribute. The EMF tree model editor I have generates a default value for "bar", which is generally ok, except when the user must use specific (custom) logics to derive a value for it. In that case the user will overwrite the generated default to insert the desired value.

Now, I want to define a grammar for this Ecore metamodel, and I want to emulate the behavior of the model editor above.

In other words, I want the xtext editor does not force the user to insert a value for "bar" each time, and that some Java code is called behind the scenes when "bar" is not specified to comply with the multiplity-1 constraint.

In yet other words, I want the editor does not raise any error when the user does:

Foo fobj;

because some Java code will be called behind the scenes to properly fill the "bar" attribute with some defaults.
On the other hand, this one of course is also valid:

Foo fobj with bar abc123;

Any hints on how do I do it?

Thanks.
Best,
--
Matteo

[Updated on: Wed, 15 November 2017 14:07]

Report message to a moderator

Re: Custom validation of constraints from existing metamodel [message #1776347 is a reply to message #1776346] Wed, 15 November 2017 14:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I'd have a look at org.eclipse.xtext.parser.DefaultEcoreElementFactory.create(EClassifier)
maybe you can set the default value after creation


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom validation of constraints from existing metamodel [message #1776350 is a reply to message #1776347] Wed, 15 November 2017 14:27 Go to previous messageGo to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 40
Registered: May 2012
Member
Hi Christian, thanks for the immediate reply!
I've just looked around (e.g., here: http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.3/org/eclipse/xtext/parser/DefaultEcoreElementFactory.html#create(org.eclipse.emf.ecore.EClassifier)). Can you elaborate just a bit how am I supposed to "customize" the call to method "create" or force a call to method "set" (which "Assigns a given value to a feature of the element _this.")?
Re: Custom validation of constraints from existing metamodel [message #1776357 is a reply to message #1776350] Wed, 15 November 2017 16:23 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
subclass.
have a look if your class is created.
set the default value


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:IllegalStateException when formatting
Next Topic:Sharing how to override the lexer
Goto Forum:
  


Current Time: Sat Apr 20 03:32:52 GMT 2024

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

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

Back to the top