General (#1) - Subobjects reference (#4) - Message List

Subobjects reference


Is there any OCL construct or QVT relational construct that can access sub-objects of one element no matter what is the type of that sub-object?

For example, if I have next instance of a model:

        <clrelem xsi:type="clr:Add">
        <clrelem xsi:type="clr:Stloc" index="1">
        <clrelem xsi:type="clr:Add">

is it possible to iterate through <code>, lets say using

code1.subobjects->iterate(e : Clrelem | if(e.oclIsKind(Stloc))
                                        then ...
                                        else if(e.oclIsKind(Add))
                                             then ...
                                             else if(e.oclIsKind(Return)...)

Thanx in advance

  • Message #6

    If I have understood your question right, I reformulate it:

    Is it possible to access all EMF-contained elements of an owner element by a QVT/OCL construct?

    The answer is: No

    The reason is, because you can only use associations to navigate from one element to another element, but there is no generic association in OCL that allows you to retrieve all contained elements of one element.

    A workaround can be, that you define a metamodel operation, which returns all contained elements of an element. The java implementation can look like (not tested):

    EList<EObject> getContainedElements(EObject ownerElement) {
     return ownerElements.eContents();


No attachments created.