1

我有两种产品。例如 A 和 B。在 A 产品中,我需要启用 AValidator.xtend 文件中存在的一个验证,而 B 产品取决于 A,因此当我运行 B 产品时,需要禁用警告。

AValidator.xtend

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

BProduct 不应该进行相同的检查。

有没有可以为这些做的覆盖功能?

提前谢谢了。

4

2 回答 2

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.

于 2015-01-19T15:13:14.373 回答
0

此问题的解决方案是创建扩展点。

我在 AProduct 验证器插件中创建了一个扩展点,其名称为 IProdcutEnabled 接口,使用一种方法。

并在 BProduct 验证器插件中添加了该扩展点。

然后AProduct验证器类,验证我检查扩展点是否被任何产品使用。如果已使用,则不显示警告。

于 2015-01-24T07:30:25.807 回答