我正在 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(""));
任何形式的帮助表示赞赏。