Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Customizing validator behavior
Customizing validator behavior [message #1807939] Wed, 12 June 2019 23:36 Go to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 72
Registered: July 2009
Member
I need a couple of changes to the behavior of the validator for my DSL.

Firstly, I would like to create different validators in different plugins that are run based on whether the plugin is installed/activated or not. On top of that the validators also need to differentiate based on file extensions. I have seen this post, and will be trying it out soon:
https://stackoverflow.com/questions/45934911/xtext-validation-split-over-multiple-plugins

But I just wanted to confirm, does the first proposal in the answer allow both validators to run or just one at any given time?

Secondly, I want to the validator(s) to ignore certain directories in a project. Like derived, or archived folders. Some of these folders I can't mark as derived in Eclipse IDE. how can I achieve that? Do I have to inspect the URI of the resource in every check* method in my validator, or is there a better way?
Re: Customizing validator behavior [message #1807947 is a reply to message #1807939] Thu, 13 June 2019 05:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13068
Registered: July 2009
Senior Member
You can write a own extension point to and read that from a customization in your validator .
Or you create activators like Xtext does for your ui plugins and do bindings
Like they are generated into the abstractmydslruntimemodule

(2) I don't understand.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customizing validator behavior [message #1807952 is a reply to message #1807947] Thu, 13 June 2019 07:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Hi

It seems like you need a common validator and a variety of derived validators to accommodate distinct use cases.

If you have a simple discrimination such as file extension you can register a different variation for each extension.

If you have control of the validation invocation, you can construct and use a derived Diagnostician to influence what gets invoked when. If not, you may need a flag in your common validator to ensure that the first pass through some validate method performs your special checks.

Regards

Ed Willink

Re: Customizing validator behavior [message #1808008 is a reply to message #1807952] Fri, 14 June 2019 05:35 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 72
Registered: July 2009
Member
Thanks guys for the replies.

Christian Dietrich, for my second question I want some directories in a project to be ignored by the validator. In IDE when a project has an xtext nature, my validator runs on all files with the file extension that matches my DSL. But there are some directories in the project that have unprocessed files, and hence incomplete syntax. I want the validator to skip these directories.

Ed,

How can I register different validator for different extensions?

Re: Customizing validator behavior [message #1808010 is a reply to message #1808008] Fri, 14 June 2019 05:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13068
Registered: July 2009
Senior Member
well but then

"i dont want to run the validator is false"
you dont want them to be processed at all (no builder, no generator etc)

that is what

org.eclipse.xtext.ui.resource.DefaultResourceUIServiceProvider.canHandle(URI)
org.eclipse.xtext.ui.resource.DefaultResourceUIServiceProvider.canHandle(URI, IStorage)

are for


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customizing validator behavior [message #1808024 is a reply to message #1808008] Fri, 14 June 2019 07:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Waqas Ilyas wrote on Fri, 14 June 2019 01:35

How can I register different validator for different extensions?


Hi

Oops, sorry you can't. Validators are registered for each distinct nsURI. You will need to override the following

	protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) {
		switch (classifierID) {


to check the extension of the URI of the eResource() of the first EObject value that comes along.

Regards

Ed Willink
Re: Customizing validator behavior [message #1808031 is a reply to message #1808024] Fri, 14 June 2019 08:10 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 72
Registered: July 2009
Member
Thanks guys for the suggestions. I will try them out and let you know soon.
Re: Customizing validator behavior [message #1809020 is a reply to message #1808031] Fri, 05 July 2019 23:57 Go to previous message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 72
Registered: July 2009
Member
Just wanted to confirm here that I was able to override IResourceUIServiceProvider in the UI module to filter out directories.

I haven't started to divide the validation into multiple plugins. Will report back once I start work on that.
Previous Topic:XText Workflow for Expensive Analysis
Next Topic:How i can remove empty keyword from xtext editor.
Goto Forum:
  


Current Time: Thu Aug 22 00:10:24 GMT 2019

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

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

Back to the top