2

I'm trying to navigate UML associations in OCL, using the eclipse OCL implementation. I know that UML Associations are treated as Attributes, and the getAttributes() function called on a Class will return a set containing the Attributes as well as a Property object for each Association. What I need however, is not the Property, but the Class on the other end of the Association.

For bidirectional Associations, the following code works, although it doesn't seem very elegant:

self.getAllAttributes().opposite.class

Not only is it not elegant, it also doesn't work on directed Associations (there is not opposite Property there). Is there a better way of navigating Associations in OCL?

2 Answers2

1

What about using property.type?

Christian
  • 13,285
  • 2
  • 32
  • 49
  • You're right: using `self.getAllAttributes().type.oclAsType(Class)` works (as long as all the attributes are associations, of course). Thanks a lot! –  Dec 07 '12 at 15:47
0

Why don't you try with the OCL console as explained in this post

http://lowcoupling.com/post/47845805110/ocl-and-the-eclipse-ocl-console

lowcoupling
  • 2,151
  • 6
  • 35
  • 53