0

我正在 Acceleo(在 Eclipse 中)开发一个 M2T 生成器。该模型基本上是一个 UML 模型,其中包含在 Papyrus 中创建的 SysML 配置文件。它包括块和流端口。我必须访问这些刻板印象,但似乎我无法检索任何 SysML 对象,即使它们出现在列表中(代码建议)。实际上我必须访问与端口关联的 FlowPort 的“方向”属性。我已经尝试过各种论坛(包括https://www.eclipse.org/forums/index.php/t/452587/)的建议和答案,但徒劳无功。

代码如下。我已经按照https://www.eclipse.org/forums/index.php?t=msg&th=1060450&goto=1693765&的建议创建了 java 服务,但是 port.hasStereotype('FlowPort') 总是返回 false。我也尝试过“SysML::PortAndFlows::FlowPort”而不是“FlowPort”。我在 Eclipse Mars 上使用 Acceleo 3.6.2。

...
[template public generateElement(model : Model)]
[comment @main/]

[file ('created.txt', false, 'UTF-8')]
[for(port: Port | model.eAllContents(Port))]
    [if(port.hasStereotype('FlowPort'))]
        OK
    [else]
        NOT OK
    [/if]
[/for]
[/file]
[/template]

在创建模块时,我在模块中包含以下元模型:

http://www.eclipse.org/uml2/5.0.0/UML
http://www.eclipse.org/papyrus/0.7.0/SysML
http://www.eclipse.org/papyrus/0.7.0/SysML/Blocks
http://www.eclipse.org/papyrus/0.7.0/SysML/Constraints
http://www.eclipse.org/papyrus/0.7.0/SysML/PortAndFlows
http://www.eclipse.org/emf/2002/Ecore

此外,我确实按照上面提到的链接的建议,在 Generate.java 的 registerPackages() 中注册了所需的包,包括以下内容。

    // UML2 profiles
    URI uri = URI.createURI("platform:/plugin/org.eclipse.uml2.uml.resources");
    uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));  

    // SysML profiles
    uri = URI.createURI("platform:/plugin/org.eclipse.papyrus.sysml");
    uriMap.put(URI.createURI(SysmlResource.LIBRARIES_PATHMAP), uri.appendSegment("librairies").appendSegment(""));
    uriMap.put(URI.createURI("pathmap://SysML_PROFILES/"), uri.appendSegment("SysML.profile.uml").appendSegment("")); 
    uriMap.put(URI.createURI("pathmap://SysML_PROFILES/"), uri.appendSegment("model").appendSegment(""));

任何形式的帮助表示赞赏。

4

1 回答 1

0

我遇到了同样的问题,但使用的是 UML/MARTE 而不是 SysML。

我敢打赌port.getAppliedStereotypes(),无论如何都会返回空列表(当然,端口定型的)。@generated NOT我还尝试了您所做的一切,但均未成功,包括仔细检查该方法的 javadoc 中是否有 a registerPackages(每次都重新生成它)。

我通过一些解决方法解决了这个问题。我假设您(像我一样)使用 Papyrus 生成的 model.uml 文件作为转换的输入。这实际上可能是问题的原因,即使我没有看到替代方案。如果您使用文本编辑器打开该文件,您会发现<FlowPort>标签位于标签之外<uml:Model>。这意味着,由于我仍然无法理解的原因,这些stereotype()方法无法“看到”原型并且总是返回 null 或空列表。这可能是因为它们无法将构造型base_NamedElement与标签xmi:id内部匹配。<uml:Model>

另一方面,如果您定义一个将 FlowPort(而不是模型)作为输入的模板,您将能够获得您的原型元素及其所有属性。

[template public generateElement(aFlowPort: FlowPort)]
[comment @main /]
[comment here you can access to the aFlowPort fields]
[/template]

除此之外,您还可以访问构造型的base_NamedElement属性(即模型Port中的构造FlowPort型),并且可以使用qualifiedName基本元素的属性将构造型映射回Port您的Model. 在实践中,这意味着您必须手动将原型链接到它们的原型实体。

笨重且烦人,但在有人提出不那么“变通”的解决方案之前仍然可以完成工作。

于 2016-02-11T10:56:26.273 回答