Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 194245

Summary: Navigation of unnamed association ends.
Product: [Modeling] OCL Reporter: Nicolas Rouquette <nicolas.f.rouquette>
Component: CoreAssignee: Christian Damus <give.a.damus>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 Keywords: plan
Version: 1.1.0   
Target Milestone: M3   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Nicolas Rouquette CLA 2007-06-25 11:52:14 EDT
According to Mr. OCL, MDT OCL supports navigation of non-navigable, explicitly-named association ends 
http://www.eclipse.org/newsportal/article.php?id=840&group=eclipse.modeling.mdt.uml2#840

The Eclipse UML2 metamodel has, among other things, three metaclasses:
- Profile which owns an association: ownedStereotype:Stereotype[0..*]
- ProfileApplication which owns a property: appliedProfile: Profile[1]
- Stereotype which owns an operation: getProfile() : Profile[0..1]

Whenever a Stereotype constraint is evaluated, there must be a ProfileApplication instance for the Profile that owns the Stereotype.
Retrieving the ProfileApplication instance corresponding to a Stereotype instance is not straightforward; currently, it requires writing:

let pa:Collection(ProfileApplication) = 
(let p:Profile=self.getNearestPackage().oclAsType(uml::Profile) in self.getModel().getAllProfileApplications()->select(pa:ProfileApplication|pa.appliedProfile=p))

According to Mr. OCL, support for navigation of unnamed association ends
(i.e., A_profileApplication_appliedProfile) would simplify this to:

let pa:Collection(ProfileApplication) = 
(let p:Profile=self.getNearestPackage().oclAsType(uml::Profile) in 
p.profileApplication

I am not sure why some tools don't accept using
Stereotype:getProfile():Profile[0..1] in OCL constraints
which, as Mr. OCL suggests, might simplify the problem to:

let pa:Collection(ProfileApplication) = self.getProfile().profileApplication

Regards,
-- Nicolas.
Comment 1 Christian Damus CLA 2007-06-25 13:47:59 EDT
Assigning to 1.2 release for consideration in the 1.2 feature planning.
Comment 2 Christian Damus CLA 2007-10-15 18:17:50 EDT
The fix is committed to cvs HEAD (1.2 branch.)

In reply to some comments in the original description:

"self.getProfile()" in the context of a stereotype would not work because "getProfile()" is the Java getter method for the "profile" attribute.  An OCL expression would have "self.profile" but this, also, would not work in the MDT OCL implementation because to navigate the Stereotype::profile profile, we look for inverse references on its navigable opposite which is Profile::ownedStereotype.  Unfortunately, this property is derived (as a subset of ownedType or packagedElement) so that the CacheAdapter (ECrossReferenceAdapter) doesn't see it and UML2Util::getNonNavigableInverseReferences() utility doesn't work.

Moreover, navigating from a profile to its applications via "p.profileApplication" also won't have the desired result, but for a different reason.  Profiles are Packages, so this actually resolves to the Package::profileApplication attribute which is a named and navigable association end.  OCL actually specifies no means by which to navigate backwards on the ProfileApplication --> Profile association.
Comment 3 Christian Damus CLA 2007-10-17 16:18:03 EDT
Fixed in the MDT OCL 1.2.0 I200710171533 build.
Comment 4 Nicolas Rouquette CLA 2007-10-17 16:57:53 EDT
Could you please indicate what is the OCL 1.2 syntax that would simplify the original issue in this bug? i.e.:

currently, I write:

let pa:Collection(ProfileApplication) = 
(let p:Profile=self.getNearestPackage().oclAsType(uml::Profile) in
self.getModel().getAllProfileApplications()->select(pa:ProfileApplication|pa.appliedProfile=p))

with OCL 1.2, I am not sure what I should/could write.
Comment 5 Christian Damus CLA 2007-10-17 17:24:56 EDT
(In reply to comment #4)

It turns out that there really isn't any simpler way, given that the language specification provides no way to navigate the Profile-->ProfileApplication association in the reverse direction.  There is no way to indicate that p.profileApplication should navigate from the profile to the application that references it, rather than to profile applications owned by the profile.

The simplest expression that I can think of that will get an application of the profile, in the context of the Stereotype metaclass, is

  ProfileApplication.allInstances()->any(
     appliedProfile = self.owner.oclAsType(Profile))

Of course, there is also the problem of the possibility of the same profile being applied multiple times in a model (in the UML2 implementation, possibly different versions of the same profile definition).  In this case, you would have to find the profile definition that is applied in the context of the element to which the stereotype is applied.  This is something that you can't do in OCL, because it has no reflection capability:  from a stereotype application (i.e., instance of a stereotype), you can get the element that it is applied to, but you cannot get the Stereotype that is its class.
Comment 6 Nicolas Rouquette CLA 2007-10-17 18:37:26 EDT
Your last comment is a concise summary and explanation of an issue that has bothered me for a while. I even thought of defining a profile to apply to a profile to provide the missing stereotype instance / definition traceability information you described. If this issue hasn't been filed yet with the OMG, it should and we should add the OMG issue # for tracking purposes to this bug for future reference.
Comment 7 Nick Boldt CLA 2008-01-28 16:38:54 EST
Move to verified as per bug 206558.
Comment 8 Ed Willink CLA 2011-05-27 02:39:49 EDT
Closing after over a year in verified state.
Comment 9 Ed Willink CLA 2011-05-27 02:41:38 EDT
Closing after over a year in verified state.