Check stereotype applications via static profile [message #1852920] |
Fri, 10 June 2022 15: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 #1852928 is a reply to message #1852920] |
Fri, 10 June 2022 21:23   |
Eclipse User |
|
|
|
Hi Ansgar
My first reaction is that you shouldn't be using the non-OCL getAppliedStereotypes() which is part of the Eclipse UML2 Java API. The Pivot OCL provides consistent type-safe base_XXX/extension_XXX functionality. So:
def: hasPtrStereo(): Boolean = self.extension_Ptr->notEmpty()
or if you are confident that the multiplicity is [?]
def: hasPtrStereo(): Boolean = self.extension_Ptr- <> null
I thought I had introduced an extensions() to avoid the reflective getAppliedStereotypes(), but can't find it.
Using the console I see that getAppliedStereotypes() returns instances of Stereotype, but it appears that oclIsKindOf/selectByKind only works with a literal type argument.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=578010 for progress on these issues.
Not even name selection seems to offer a workaround.
Regards
Ed
|
|
|
|
Re: Check stereotype applications via static profile [message #1852932 is a reply to message #1852930] |
Sat, 11 June 2022 10:49   |
Eclipse User |
|
|
|
Hi
def: hasStereo(stType : Type): Boolean =
getStereotypeApplications()->select(oclIsKindOf(stType))->notEmpty()
This fails because you / the tooling has confused metalevels.
getStereotypeApplications() returns a Set of Stereotype instances with interesting user-defined names. They conform to Stereotype and its supertypes. To respect user-defined names you must do name not type comparison.
In contrast extension_XXX [and extensions() once impemented] return a [Set of] stereotype application reified in the Pivot by the StereotypeExtender class. StereotypeExtender instances are at the sensible metalevel and so can have user inheritance.
The lack of a class for stereotype application in the UML metamodel is a source of considerable difficulties that explain why few implementations work. Using the Eclipse UML2 API and the old Classic OCL, the absence is patched up unsatisfactorily by a DynamicEObjectImpl.
Regards
Ed Willink
|
|
|
Re: Check stereotype applications via static profile [message #1852956 is a reply to message #1852932] |
Mon, 13 June 2022 07:51   |
Eclipse User |
|
|
|
Hi Ed,
thanks for your responses. I get an error if I use the extension_Ptr (or extension_Create) when opening it with the OCL xtext editor in an Eclipse 2022-03. Maybe I'm missing some declaration in the header, therefore I list the whole beginning of my .ocl file. In the code below, I use the similar example of the <<Create>> stereotype, as it is part of the standard profile, i.e. does not need additional plugins:
import 'platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore'
import 'platform:/plugin/org.eclipse.uml2.uml.profile.standard/model/Standard.ecore'
package UML
context Operation
def: hasCreateStereo(): Boolean = self.extension_Create->notEmpty()
|
|
|
|
Re: Check stereotype applications via static profile [message #1853109 is a reply to message #1852966] |
Sat, 18 June 2022 10: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.04399 seconds