如果您處於subvertex
關係中,您必須位於Region
。 xmi:type
是XMI處理多態引用的方式。由於subvertex
定義爲Vertex [*]
,因此XMI必須指定集合中每個元素的類型。要檢查該字段,你只需要測試的元素的類型(使用oclIsTypeOf
或oclIsKindOf
)
所以,從Region
:
[template public test(r : Region)]
[r.subvertex->filter(State)/] --> filter all States from the subvertex collection
which is equ. to
[r.subvertex->select(oclIsKindOf(State))/]
and if you want only the State elements (no subclasses)
[r.subvertex->select(oclIsTypeOf(State))/]
[/template]
此外,您還可以在不同的模板處理它們通過添加模板後衛:
[template public test(r : Region)]
[r.subvertex.test2()/]
[/template]
[template public test2(s : Vertex) ? (oclIsKindOf(State))]
[s/] is a state for sure
[/template]
您也可避免後衛通過重寫上面的模板,因爲這:
[template public test(r : Region)]
[r.subvertex.test2()/]
[/template]
[template public test2(v : Vertex)/]
[template public test2(s : State)]
[s/] is a state for sure
[/template]
編輯
如果你絕對要以字符串格式類型值,你必須去檢查元素元類,並要求它的名字:
...
[s.eClass().name/] -> result as String, s.eClass() gets the EClass
...
https://stackoverflow.com/問題/ 48024563/how-to-get-xmiid-from-xmi-files-in-acceleo – kincki