Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » global validation (how to validate)
global validation [message #1721426] Wed, 27 January 2016 12:34 Go to next message
Paul Harrison is currently offline Paul HarrisonFriend
Messages: 2
Registered: January 2016
Junior Member
I have a grammar that allows elements to reference other elements using the linking capabilities of Xtext. I want to validate my model to check that each of the referred-to elements is only referred-to once.

I am fairly new to Xtext and cannot see how to achieve this aim, if I use the typical Custom validator for my model, as even if I was to do something like

def checkOneReferrer(ReferredToType t){}


because the links are all on there ReferringType

and I cannot do something like

def checkUnique(ModelRoot t) {}


and navigate the whole model, as I believe that I can only return one error from this function.

It seems that I need to use a higher level API? Any guidance on this would be appreciated.
Re: global validation [message #1721453 is a reply to message #1721426] Wed, 27 January 2016 15:02 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Actually you can produce multiple errors from a check for type ModelRoot. Collect all references to an refered-to element and produce an error for each if you find more than once. Basically you could create a multimap while traversing the model instance.

Things become more complicated when the referred-to elements are split over several resources, which I guess is what you have. In this case you have to know from a referred-to element if there is only one referrer. Since there is only a unidirectional dependency from referrer to referred-to, you will have to somehow collect the cross-references.

I could imagine that you would be able to install an org.eclipse.emf.ecore.util.ECrossReferenceAdapter on a referred-to element during the linking phase when a referrer to its referred-to is linked. This might be done by subclassing the DefaultLinkingService

Validation happens after linking. Thus your validation could get the ECrossReferenceAdapter from the referred-to element and check if there are more than one cross references.


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Previous Topic:Splitting a model into several files? Scoping?
Next Topic:Xtext Web - Code generation
Goto Forum:
  


Current Time: Sat Apr 27 02:22:29 GMT 2024

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

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

Back to the top