Xtext disable validation check for specfic product

1.1k views Asked by At

I have two products. For example A and B. In A product i need to enable to one validation which is present in AValidator.xtend file and B product is depends on A so when i run B product that check needs to be disable the warning.

AValidator.xtend:

@Check
def validateElement(Element e)
{
    warning('''Element «e.name» missing in files.''', e,         package.Literals.NAMED__NAME)
}

The same check should not be work for BProduct.

Is there any override function can do for these?

Many thanks in advance.

2

There are 2 answers

6
Aaron Digulla On BEST ANSWER

There are two ways to solve this:

  • You can add a system property (probably a boolean flag) which enables this feature. In the ini file of A, you enable the option. In B, you omit it.

  • You can split the plugin into a library and then two plugins which you use in the products.

Splitting the plugin works like this:

You need to create a new plugin and copy all the shared code into it. It can also contain the code from the validation which is the same for both products. Give the validation code the name SharedValidator

In this plugin, you need to rename DslRuntimeModule (Dsl is the name of your grammer, it extends AbstractDslRuntimeModule which contains the binding for the validation). Rename it to SharedDslRuntimeModule.

Then you create a plugin for product A. It contains the specific validation. This class needs to extend SharedValidator.

You also need to create a binding which extends SharedDslRuntimeModule and so you can bind the new validator class.

That's the rough outline. You will have to copy/change several other files (like the DslStandaloneSetup and the plugin.xml), too, but those changes should become obvious when you fix the compile errors.

... Maybe a flag is more simple.

0
Saran On

Solution for this problem is Creating extension point.

I have created one extension point in AProduct validator plugin with the name of interface IProdcutEnabled with one method.

And Added that extension point in BProduct validator plugin.

Then AProduct validator class,Validation i checked whether extension point is used by any product or not. If it's used don't show warning.