Skip to main content



      Home
Home » Modeling » TMF (Xtext) » global validation (how to validate)
global validation [message #1721426] Wed, 27 January 2016 07:34 Go to next message
Eclipse UserFriend
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 10:02 Go to previous message
Eclipse UserFriend
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.
Previous Topic:Splitting a model into several files? Scoping?
Next Topic:Xtext Web - Code generation
Goto Forum:
  


Current Time: Sun Jul 13 00:16:05 EDT 2025

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

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

Back to the top