Check stereotype applications via static profile [message #1852920] |
Fri, 10 June 2022 11:24  |
Eclipse User |
|
|
|
In order to check stereotype applications in a UML context, I've successfully defined the following query that take the name of a stereotype as parameter
context Element
-- check, whether a stereotype is applied by providing its name
def: hasStereo(stName : String) : Boolean =
getAppliedStereotypes()->select(name = stName)->notEmpty()
As the name of a stereotype could be spelled wrongly, I'd rather like to use a static profile instead, i.e. import the generated ecore of that profile (the Papyrus SW Designer C/C++ profile). The following query works for a specific stereotype by using its qualified name.
-- check, if the <<Ptr>> stereotype from the C/C++ profile is applied
def: hasPtrStereo(): Boolean =
getStereotypeApplications()->select(oclIsKindOf(C_Cpp::Ptr))->notEmpty()
Now, I'd like to make the query more generic by adding the Stereotype to check as a parameter. However, I could not determine the type to use for the parameter (it's apparently not "Type") and/or a suitable condition in the select clause. Any hints on this?
def: hasStereo(stType : Type): Boolean =
getStereotypeApplications()->select(oclIsKindOf(stType))->notEmpty()
|
|
|
|
|
|
|
|
Re: Check stereotype applications via static profile [message #1853109 is a reply to message #1852966] |
Sat, 18 June 2022 06:28  |
Eclipse User |
|
|
|
Hi
In my workspace I can now do:
def: hasStereo(stType : Stereotype): Boolean = oclExtensions(stType)->notEmpty()
but testing your earlier usage as:
def: hasStereo(): Boolean = oclExtensions(StandardProfile::Create)->notEmpty()
reveals https://bugs.eclipse.org/bugs/show_bug.cgi?id=580202 whereby you need to accommodate an Eclipse UML2 typo and use "Standard" rather than "StandardProfile"
and that your original example was crazy.
Stereotypes are a UML facility for which OCL can provide some useful evaluation capabilities. When you import
import 'platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore'
import 'platform:/plugin/org.eclipse.uml2.uml.profile.standard/model/Standard.ecore'
you use Ecore without any reference to UML, consequently you can only use what is present in the Ecore models. Your Ecore models have no extension_Create EReference so of course it is not found.
If you want to use OCL for UML you must import UML models.
import 'http://www.eclipse.org/uml2/5.0.0/UML'
import 'http://www.eclipse.org/uml2/5.0.0/UML/Profile/Standard'
This works. It should also be possible to do
import 'http://www.omg.org/spec/UML/20131001'
import 'http://www.omg.org/spec/UML/20131001/StandardProfile'
but that doesn't work. I need to find out why.
I'm not well motivated to search Ecore models to reverse the base_XXX/extension_YYY idiom to discover which EClasses are Stereotypes. It wouldn't work well since unless extension_Create occurs somewhere it couldn't be exploited elsewhere.
More likely a warning if base_XXX/extension_YYY is discovered in a UML-detached Ecore model. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=580203
Regards
Ed
|
|
|
Powered by
FUDForum. Page generated in 0.04389 seconds