我已经使用 Papyrus 工具定义了一个 UML 配置文件并将该文件保存为“my_profile.di”。如何在 QVTo 转换中使用此配置文件?
是否可以做这样的事情(我不确定应该如何指定文件的路径)?
modeltype UMLProfile uses 'platform:/resource/QVT_project_test/my_profile.di';
如果这是一个愚蠢的问题,我很抱歉,但我对 QVT 完全陌生。希望有大神指教,先谢谢了!
我已经使用 Papyrus 工具定义了一个 UML 配置文件并将该文件保存为“my_profile.di”。如何在 QVTo 转换中使用此配置文件?
是否可以做这样的事情(我不确定应该如何指定文件的路径)?
modeltype UMLProfile uses 'platform:/resource/QVT_project_test/my_profile.di';
如果这是一个愚蠢的问题,我很抱歉,但我对 QVT 完全陌生。希望有大神指教,先谢谢了!
将 UML Profile 与 QVTo(或任何基于 EMF 的转换语言)一起使用有点棘手。简短的回答,您必须只处理 UML 元模型,但是根据情况,处理配置文件的方式有点不同。基本上,有两种情况:
第一个场景
您只需注册 UML 元模型,并且您需要使用 UML 提供的操作(getAppliedStereotypes()
,...)。实际上,应用了构造型的元素不会被识别为构造型的实例。例如,假设您有一个Property prop
带有构造型的 a EAttribute
,QVTo 将prop
视为一个Property
具有您可以恢复的额外信息的实例,而不是一个EAttribute
实例。
这是一个考虑一种ecore
Profile 的小例子。我考虑了一个inout
转换,这意味着定义为的模型inout
将被修改。
modeltype UML "strict" uses uml('http://www.eclipse.org/uml2/5.0.0/UML');
transformation testProfile(inout model : UML);
main() {
model.objects()[Property]->map copyme();
}
mapping Property::copyme() : Property
when {
-- You need to use the fully qualified name
not self.getAppliedStereotype('ecore::EAttribute').oclIsUndefined()
}
{
-- repr() is used at the end to get a String value from the tagged value
name := self.name + self.getValue(self.getApplicableStereotype('ecore::EAttribute'), 'attributeName').repr(); -- toString() also works
}
还有一个小请求,列出了由特定刻板印象刻板印象的所有元素:
model.objects()[Element]->select(e | not e.getAppliedStereotype('ecore::EAttribute').oclIsUndefined());
Also, stereotypedBy(...)
operation seems nice, but it is not yet implemented (on my QVTo version).
Second Scenario
This time, you will need to pass the profile as new parameter of your transformation (if your profile is defined in another file). Your profile is a UML model as well, your transformation signature becomes:
transformation testProfile(inout model : UML, in profile : UML);
First you need to apply your profile to your model:
model.objects()[Model].applyProfile(profile.objects()![Profile]);
and when you want to apply a Stereotype to an element:
-- in context of an element
self.applyStereotype(profile.objects()[Stereotype]![name = 'EAttribute']);
If the double filter does not works (I think it will be removed in future QVTo versions), just use a select:
self.applyStereotype(profile.objects()[Stereotype]->selectOne(name = 'EAttribute'));
Also take a look at the setValue()
operation ;).
Final Note
As you saw, it can be a little bit cumbersome to deal with profile all along your transformation. A smart move could be to derive a metamodel from your profile et code a first transformation that takes your profiled model and translate it as a instance of your derived metamodel. This way, you will be able to deal with metamodel instance instead of "UML instances with extra-information".
EDIT>
In order to ease the stereotype handling, you can also define global properties with your most use stereotype:
property mystereotype : Stereotype = profile.objects()[Stereotype]![name = 'EAttribute'];