0

In Eclipse, Using Papyrus neon and Acceleo 3.7 for SysML 1.4 diagram, the getAppliedStereotype()returns null. The modules are

[module generate('http://www.eclipse.org/uml2/5.0.0/UML', 
'http://www.eclipse.org/papyrus/sysml/1.4/SysML',
 'http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks',
'http://www.eclipse.org/papyrus/sysml/1.4/SysML/Activities',
'http://www.eclipse.org/papyrus/sysml/1.4/SysML/Requirements',
'http://www.eclipse.org/papyrus/sysml/1.4/SysML/ModelElements')]

I have added the following code in the generate.java but still cannot work

Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
        // 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.sysml14");
        uriMap.put(URI.createURI(SysMLResource.LIBRARIES_PATHMAP), uri.appendSegment("librairies").appendSegment(""));
        uriMap.put(URI.createURI("pathmap://SysML14_PROFILES/"), uri.appendSegment("model").appendSegment(""));  

The code like c.getAppliedStereotypes() returns null. I want to get the information of a requirement like the following code which returns nothing because of the getAppliedStereotype operation:

[for (re : uml::Class | uml::Class.allInstances()->select(cl : uml::Class | cl.getAppliedStereotype('SysML::Requirements::Requirement') <> null))] 
--[re.name/]
 Modellpfad : [re.qualifiedName/]
Id : [re.getValue(re.getAppliedStereotype('SysML::Requirements::Requirement'), 'id')/]
Text : [re.getValue(re.getAppliedStereotype('SysML::Requirements::Requirement'), 'text')/]
[/for]
lucia
  • 1
  • 2
  • If you want us to help you, you will have to give us information on what exactly you are trying to do, how, what your templates look like... As it stands we have absolutely no info with which to start on helping you. – Kellindil Jul 05 '17 at 08:26
  • I try to get the requirement table information like this: [for( cl:Requirement | c.getAppliedStereotypes()->filter(Requirements::Requirement)] [cl.id/] [/for] and tried some other sentences but still can not get the Requirement – lucia Jul 05 '17 at 13:06
  • Try and print [c.getAppliedStereotypes()/] and [c.getAppliedStereotypes()->filter(Requirements::Requirement/] separately. My guess is you're not registering the sysml profile properly for Acceleo to recognize it. You might want to look at Stéphane's old answer to https://www.eclipse.org/forums/index.php/t/1060450/ for more info, as well as the utility method that's been added since then, org.eclipse.uml2.uml.resources.util.UMLResourcesUtil.init(ResourceSet) that should do all the work for you. (call it from the "registerPackages" method of your main module's java launcher. – Kellindil Jul 05 '17 at 14:22
  • I have added this to the java file but the [c.getAppliedStereotypes()/] still return nothing, c is the model. I also tried Class instead of Requirement [c.allOwnedElements()->filter(Class)/] but the type of Class can only give its name but do not have the id and text which I supposed the allOwnedElements do not include the Requirement information. Are there any other methods to get the information of a Requirement? – lucia Jul 05 '17 at 16:23
  • And following are the modules: [module generate('http://www.eclipse.org/uml2/5.0.0/UML', 'http://www.eclipse.org/papyrus/sysml/1.4/SysML', 'http://www.eclipse.org/papyrus/sysml/1.4/SysML/Requirements')] – lucia Jul 05 '17 at 16:23
  • Please update your question with the module, as well as info on whether you tried to properly register the Sysml pathmap as explain on the forum link I posted in a previous comment, and the result of that – Kellindil Jul 06 '17 at 08:10
  • The question is updated, thank you for your replying but still have the problem – lucia Jul 13 '17 at 17:57

1 Answers1

0

Well, if none of your model elements have an applied stereotype, you will find no classes or objects. Thus, when you try to print the applied stereotype of all elements with an applied stereotype without first ensuring that the list is itself not null, you will fail.

tjborromeo
  • 156
  • 6