我正在Acceleo(在Eclipse中)中開發M2T生成器。該模型基本上是一個在Papyrus中創建SysML概要文件的UML模型。它包含Blocks和FlowPorts。我必須訪問這些構造型,但似乎我無法檢索任何SysML對象,即使它們出現在列表中(代碼建議)。實際上,我必須訪問與Port關聯的FlowPort的'Direction'屬性。我已經嘗試過各種論壇(包括https://www.eclipse.org/forums/index.php/t/452587/)的建議和答案,但徒勞無功。無法在Acceleo中訪問SysML構造型及其屬性
代碼如下。我按照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(""));
任何形式的幫助表示讚賞。
嗨st1led,是的,我正在使用紙莎草生成的uml模型。我已經發現了你的建議工作,但我不確定我們是否可以訪問該模板中的所有UML對象(使用FlowPort)。例如,我可以訪問包含Class或Package對象嗎? – Yasir
訪問FlowPort的'base_namedElement',即'Port'後,就可以使用UML對象的API(例如'owner','ownedElements'等)從'Port'導航。這是你想要的? – st1led