问题
I'm using Eclipse 4.6.3 (Neon.3) with Acceleo 3.6.6, Paprus 2.0.3 and Papyrus SysML 1.4 0.10.1. How can I check from an Acceleo MTL script, whether a class of my model has the SysML Block stereotype applied? The method getAppliedStereotypes() only works for my own defined stereotypes but not for SysML 1.4 ones.
In my UML model (Papyrus project) I have created
"Class1" to which I have applied my own stereotype "MyProfile::MyStereotype" created in the "Model Explorer" via "Profile"/"Update Profile" and
"Class2" to which I have applied "SysML::Blocks::Block" under "Properties"/"Profile"/"Applied stereotypes"
In the Acceleo project in generate.mtl, if I'm calling getAppliedStereotypes() on each of these 2 classes, I only get the stereotype of "Class1", but none for "Class2".
model.uml:
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Blocks="http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks" xmlns:MyProfile="http:///schemas/MyProfile/__okhIEO5EeezquIZgVUJBA/0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks http://www.eclipse.org/papyrus/sysml/1.4/SysML#//blocks http:///schemas/MyProfile/__okhIEO5EeezquIZgVUJBA/0 MyProfile.profile.uml#__olvQUO5EeezquIZgVUJBA">
<uml:Model xmi:id="_Jl27kEO4EeezquIZgVUJBA" name="RootElement">
<packagedElement xmi:type="uml:Class" xmi:id="_LpXEYEO4EeezquIZgVUJBA" name="Class1"/>
<packagedElement xmi:type="uml:Class" xmi:id="_ZFGQwEO4EeezquIZgVUJBA" name="Class2"/>
<profileApplication xmi:type="uml:ProfileApplication" xmi:id="_SLhJ0EO4EeezquIZgVUJBA">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_SLi_AEO4EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href="http://www.eclipse.org/papyrus/sysml/1.4/SysML#//blocks"/>
</eAnnotations>
<appliedProfile xmi:type="uml:Profile" href="pathmap://SysML14_PROFILES/SysML.profile.uml#SysML.package_packagedElement_Blocks"/>
</profileApplication>
<profileApplication xmi:type="uml:ProfileApplication" xmi:id="__om9ZkO5EeezquIZgVUJBA">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__om9Z0O5EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href="MyProfile.profile.uml#__olvQUO5EeezquIZgVUJBA"/>
</eAnnotations>
<appliedProfile xmi:type="uml:Profile" href="MyProfile.profile.uml#__og2wEO5EeezquIZgVUJBA"/>
</profileApplication>
</uml:Model>
<Blocks:Block xmi:id="_bBkkgEO4EeezquIZgVUJBA" base_Class="_ZFGQwEO4EeezquIZgVUJBA"/>
<MyProfile:MyStereotype xmi:id="__ooykEO5EeezquIZgVUJBA" base_Class="_LpXEYEO4EeezquIZgVUJBA"/>
</xmi:XMI>
MyProfile.profile.uml:
<?xml version="1.0" encoding="UTF-8"?>
<uml:Profile xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="__og2wEO5EeezquIZgVUJBA" name="MyProfile" metaclassReference="__oiE4EO5EeezquIZgVUJBA">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__olvQEO5EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML">
<contents xmi:type="ecore:EPackage" xmi:id="__olvQUO5EeezquIZgVUJBA" name="MyProfile" nsURI="http:///schemas/MyProfile/__okhIEO5EeezquIZgVUJBA/0" nsPrefix="MyProfile">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__om9YEO5EeezquIZgVUJBA" source="PapyrusVersion">
<details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9YUO5EeezquIZgVUJBA" key="Version" value="0.0.1"/>
<details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9YkO5EeezquIZgVUJBA" key="Comment" value=""/>
<details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9Y0O5EeezquIZgVUJBA" key="Copyright" value=""/>
<details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9ZEO5EeezquIZgVUJBA" key="Date" value="28.05.17 17:26"/>
<details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9ZUO5EeezquIZgVUJBA" key="Author" value=""/>
</eAnnotations>
<eClassifiers xmi:type="ecore:EClass" xmi:id="__olvQkO5EeezquIZgVUJBA" name="MyStereotype">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__olvQ0O5EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML" references="__og2wUO5EeezquIZgVUJBA"/>
<eStructuralFeatures xmi:type="ecore:EReference" xmi:id="__olvREO5EeezquIZgVUJBA" name="base_Class" ordered="false" lowerBound="1">
<eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
</eStructuralFeatures>
</eClassifiers>
</contents>
</eAnnotations>
<elementImport xmi:type="uml:ElementImport" xmi:id="__oiE4EO5EeezquIZgVUJBA">
<importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
</elementImport>
<packagedElement xmi:type="uml:Stereotype" xmi:id="__og2wUO5EeezquIZgVUJBA" name="MyStereotype">
<ownedAttribute xmi:type="uml:Property" xmi:id="__oir8kO5EeezquIZgVUJBA" name="base_Class" association="__oir8EO5EeezquIZgVUJBA">
<type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
</ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:Extension" xmi:id="__oir8EO5EeezquIZgVUJBA" name="Class_MyStereotype" memberEnd="__oir8UO5EeezquIZgVUJBA __oir8kO5EeezquIZgVUJBA">
<ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="__oir8UO5EeezquIZgVUJBA" name="extension_MyStereotype" type="__og2wUO5EeezquIZgVUJBA" aggregation="composite" association="__oir8EO5EeezquIZgVUJBA"/>
</packagedElement>
</uml:Profile>
generate.mtl:
[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks', 'http://www.eclipse.org/uml2/5.0.0/UML')]
[template public generateModel(model : Model)]
[comment @main/]
[file (model.name, false, 'UTF-8')]
[for (c : Class | model.eContents(Class))]
[c.name/]
[for (s : Stereotype | c.getAppliedStereotypes())]
[s/]
[/for]
[/for]
[/file]
[/template]
output:
Class1
org.eclipse.uml2.uml.internal.impl.StereotypeImpl@485a3466 (name: MyStereotype, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Class2
papyrus_project:
papyrus_project
papyrus_project/model.uml
papyrus_project/MyProfile.profile.di
papyrus_project/MyProfile.profile.notation
papyrus_project/model.di
papyrus_project/.project
papyrus_project/MyProfile.profile.uml
papyrus_project/model.notation
acceleo_project:
acceleo_project
acceleo_project/src
acceleo_project/src/acceleo_project
acceleo_project/src/acceleo_project/main
acceleo_project/src/acceleo_project/main/generate.mtl
acceleo_project/src/acceleo_project/main/Generate.java
acceleo_project/src/acceleo_project/Activator.java
acceleo_project/dst
acceleo_project/dst/RootElement
acceleo_project/build.properties
acceleo_project/tasks
acceleo_project/tasks/generate.xml
acceleo_project/tasks/generateTarget.xml
acceleo_project/.project
acceleo_project/bin
acceleo_project/bin/acceleo_project
acceleo_project/bin/acceleo_project/Activator.class
acceleo_project/bin/acceleo_project/main
acceleo_project/bin/acceleo_project/main/Generate.class
acceleo_project/bin/acceleo_project/main/generate.mtl
acceleo_project/bin/acceleo_project/main/generate.emtl
acceleo_project/.classpath
acceleo_project/META-INF
acceleo_project/META-INF/MANIFEST.MF
回答1:
I'm not really sure what's happening in there but I'll take a wild guess and say Acceleo cannot resolve the SysML profile here.
If you look at your generated launcher (the java file beside your "@main" mtl template), you will see a "registerPackages" method. You will need to find the proper URI to register the SysML profile for use in your application; you can see an example of how it was done for previous versions of papyrus on the Acceleo FAQ.
来源:https://stackoverflow.com/questions/44229639/how-to-check-sysml-stereotypes-with-acceleo