Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Check stereotype applications via static profile(Write a query that checks stereotype applications)
Check stereotype applications via static profile [message #1852920] Fri, 10 June 2022 15:24 Go to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 461
Registered: March 2011
Location: Paris Saclay, France
Senior Member
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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 #1852930 is a reply to message #1852928] Sat, 11 June 2022 10:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

http://www.eclipse.org/modeling/download.php?file=/modeling/mdt/ocl/downloads/drops/6.17.2/N202206110946/mdt-ocl-Update-N202206110946.zip

fixes

https://bugs.eclipse.org/bugs/show_bug.cgi?id=580139

which should allow variables/parameters to be referenced by the oclIsKindOf argument. Still working on

https://bugs.eclipse.org/bugs/show_bug.cgi?id=580136

Regards

Ed Willink
Re: Check stereotype applications via static profile [message #1852932 is a reply to message #1852930] Sat, 11 June 2022 10:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 461
Registered: March 2011
Location: Paris Saclay, France
Senior Member
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 #1852966 is a reply to message #1852956] Mon, 13 June 2022 09:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Ansgar

Thank you very much. You understand how much easier bugs are to fix with a simple repro. (You omitted the endpackage.)

https://bugs.eclipse.org/bugs/show_bug.cgi?id=580143 raised.

Hopefully it's a duplicate of your earlier problem. But superficially it's impossible given that JUnit tests are passing. Perhaps there is just a missing diagnostic that explains why the source is idiotic.

Regards

Ed
Re: Check stereotype applications via static profile [message #1853109 is a reply to message #1852966] Sat, 18 June 2022 10:28 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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
Previous Topic:How could I add org.eclipse.ocl as a dependency
Next Topic:OCLinEcore. How the set a attribute of type java.lang.Locale
Goto Forum:
  


Current Time: Thu Apr 25 05:53:08 GMT 2024

Powered by FUDForum. Page generated in 0.04137 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top