1

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Saran
  • 167
  • 2
  • 3
  • 11
  • Can you specify your problem a little biit more precise, please. It would also be very helpful if you provide the corresponding grammar. – Joko Jan 19 '15 at 14:39
  • For example A Product :sample.aentity public class sample{ element e = 10;} if the element doesn't have any assignment(element e) then should show warning like 'initization is missing' . The samething in B.product i am using entity class there as well B Product: sample.bentity entity bentity{ sample.aentity}. So when i run Bproduct, i should n't show any warning like initization is missing. – Saran Jan 19 '15 at 14:49
  • Please provide the following source codes (edit your question and add it): 1.) your dsl code-file; 2.) the grammar rules which define the syntax and 3.) the validation method. Maybe I can help you. But currently its not enough information. – Joko Jan 19 '15 at 14:52
  • Did you have at the addIssue Methods? the take a code that can be translated to a issue with a severity configured through ConfigurableIssueCodesProvider (that uses preferences to store the severities) – Christian Dietrich Jan 20 '15 at 15:24

2 Answers2

1

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Hi Aaron, Thanks for your response. I would like to follow second approach. I am overriding AValidator class check in BValidator class but i am not getting the expected output. Sorry i didn't understand what i need to change in plugin.xml file. – Saran Jan 20 '15 at 04:57
  • Validation is configured in the `plugin.xml` file. Search for `AValidator` to see how it's done. Now for product B, you need a plugin which is a copy of the plugin in A but with a `plugin.xml` where `AValidator` is replaced with `BValidator`. If you don't want to copy the code after every change, then you need to create three plugins: One which contains the shared code and one per product which just contains the validator. If you have trouble splitting the plugins, please post new questions. – Aaron Digulla Jan 20 '15 at 08:39
  • Actually cofigured validation by binding the class. Now i have tried the below one @ComposedChecks(validators=BValidator) class AValidator extends AJavaValidator { @Check def void validateInitialization(Element element) { warning('''Invalid dependency''', element,Package.Literals.NAMED__NAME) } } class BValidator extends AValidator { override validateInitialization(Element element) { error('''Invalid dependency in B''', element,Package.Literals.NAMED__NAME) } } so it's adding error marker and warning..It's not overriding. – Saran Jan 20 '15 at 08:55
  • @Saran: In this case, you need a different module config which replaces the binding for `AValidator`. For this to work, you really need three plugins, I think. – Aaron Digulla Jan 20 '15 at 08:55
  • What exactly do you mean by adding a system property? How does this work? – Raven May 31 '15 at 17:30
  • @Krzmbrzl Write a validation rule which is enabled by a boolean flag. Initialitze the flag with [`Boolean.getBoolean()`](https://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html#getBoolean-java.lang.String-) – Aaron Digulla Jun 01 '15 at 07:33
0

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.

Saran
  • 167
  • 2
  • 3
  • 11