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

Subobjects reference
 unsolved

Hello,

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:

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

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();
    }
    

Attachments

No attachments created.