Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Customizing validator behavior
Customizing validator behavior [message #1807939] Wed, 12 June 2019 19:36 Go to next message
Eclipse UserFriend
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 01:04 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Customizing validator behavior [message #1807952 is a reply to message #1807947] Thu, 13 June 2019 03:07 Go to previous messageGo to next message
Eclipse UserFriend
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 01:35 Go to previous messageGo to next message
Eclipse UserFriend
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 01:38 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Customizing validator behavior [message #1808024 is a reply to message #1808008] Fri, 14 June 2019 03:04 Go to previous messageGo to next message
Eclipse UserFriend
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 04:10 Go to previous messageGo to next message
Eclipse UserFriend
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 19:57 Go to previous message
Eclipse UserFriend
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: Wed Mar 19 01:42:12 EDT 2025

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

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

Back to the top