How to get the eContainer of an EObject?

133 views
Skip to first unread message

Jan Reimann

unread,
Dec 4, 2012, 11:11:48 AM12/4/12
to incquer...@googlegroups.com
Hello again,
my recent problem is the following. I want to do some kind of traversing the containment tree of a given EObject up until the point a parent is of a specific type (EClass). So I thought it was possible with eContainer from EObject. But unfortunately it's an EOperation and no (derived) EReference. Here is the skeleton (which isn't correct) I had in mind:

private pattern findContainerOfSpecificType(eobject: EObject, container: EObject){
    find findContainer+(eobject, container);
    EObject.eClass(container, containerEClass);
    EClass.name(containerEClass, "MyEClassName");
}

private pattern findContainer(eobject: EObject, container: EObject){
    EObject.eContainer(eobject, parent);
}

Is it possible to simulate this?

best regards,
Jan

Ábel Hegedüs

unread,
Dec 4, 2012, 1:17:34 PM12/4/12
to EMF-IncQuery Users on behalf of Jan Reimann
Hello Jan,

unfortunately, the short answer is no.

I have also ran into the same issue at some point. The main thing to understand here is that EMF-Incquery has a query language for EMF models, not Java objects. Therefore, since eContainer is not a feature, you cannot put it into a pattern. The similar is true for eClass. Also, what you are trying to describe is something like what we call "metaquery" (https://github.com/ujhelyiz/EMF-IncQuery/issues/95), which is not yet supported.

What you can do is either query a metamodel or query an instance model, it is not really supported to combine the two at the moment.

For example, you can create (actually, you already did, as far as I remember) queries that look at features in the metamodel and select them if they are containment:

pattern containmentRef(Host: EClass, Ref : EReference, Target){...}

You can also create a query, that uses a given feature to traverse the model:

pattern someRef(From, To){
   FromClass.ref(From,To);
}

But you would need metaqueries to create a combination:

pattern traverse(From, To){
  <FromClass>(From);
  <ToClass>(To);
  find containmentRef(FromClass, Ref, ToClass);
  <FromClass>.<Ref>(From, To);
}

Two additional comments:
1. We had support for the containment hierarchy in the pattern language of VIATRA2, but it was quite inefficient.
2. If you only want to traverse a model upwards from a given element, then you're probably better of just writing it in Java. However, if you want to query all EObjects that are under the instances of the given EClass and want to get incremental updates when the list changes, that's more problematic.

We may be able to come up with a solution to this specific case before supporting metaqueries, but I can't give you an easy workaround at this point. Maybe someone else will propose a better solution, this is a mail group after all :)

Best regards,


--
You received this message because you are subscribed to the Google Groups "EMF-IncQuery Users" group.
To post to this group, send email to incquer...@googlegroups.com.
To unsubscribe from this group, send email to incquery-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/incquery-users/-/i1-Jt76xEacJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

berg...@mit.bme.hu

unread,
Dec 4, 2012, 5:45:29 PM12/4/12
to incquer...@googlegroups.com
Hello Jan,

I would like to add that the not-quite-as-short anwser would be 'not quite, but almost'.
See, while you cannot express the general case of eContainer-eContent relationship in EMF-IncQuery yet, in many particular metamodels it is likely that you only want to traverse along a fixed set of containment EReferences to do this computation. Then you can simply "or" these reference types together:

pattern containmentInMyDomain(parent: EObject, child: EObject) {
  School.teachers(parent, child);
} or {
  Window.widget(parent, child);
} or {
  EClass.eOperations(parent, child);
} or {
  EOperation.eParameters(parent, child);
} or {
  EModelElement.eAnnotations(parent, child);
} or {
  ... // whatever
}

Then you could express things like this to find e.g. any element contained _transitively_ within an arbitrary School:
  ...
  School(someSchool);
  find containmentInMyDomain+ (someSchool, containedElement)
  ...

Finally, in case you happen to know in advance what kind of path will lead from the ancestor element to the contained object, then you can use a simple path expression (or the 'or'-ed disjunction of several such expressions, if there aren't too many possibilities), like this:

  ....
  EClass.eOperations.eParameters.eAnnotations(someEClass, containedParameterAnnotation);
  ...

Hope that helps,
Gábor

-----EMF-IncQuery Users on behalf of Hegedüs Ábel <incquer...@googlegroups.com> ezt írta: -----
Címzett: EMF-IncQuery Users on behalf of Jan Reimann <incquer...@googlegroups.com>
Feladó: EMF-IncQuery Users on behalf of Hegedüs Ábel <incquer...@googlegroups.com>
Dátum: 2012/12/04 08:00du.
Tárgy: Re: [incquery-users] How to get the eContainer of an EObject?

Jan Reimann

unread,
Dec 5, 2012, 6:27:53 AM12/5/12
to incquer...@googlegroups.com
Thanks to both of you. I'm waiting for the meta-queries and until then I will do the "or"ing of the reference types together.

best regards Jan

Jan Reimann

unread,
Dec 5, 2012, 7:16:23 AM12/5/12
to incquer...@googlegroups.com

Hi Gábor,

pattern containmentInMyDomain(parent: EObject, child: EObject) {
  School.teachers(parent, child);
} or {
  Window.widget(parent, child);
} or {
  EClass.eOperations(parent, child);
} or {
  EOperation.eParameters(parent, child);
} or {
  EModelElement.eAnnotations(parent, child);
} or {
  ... // whatever
}


I tried this out but it cannot be queried because I get the following error:
Inconsistent variable type defintions: [School, EObject]


Jan Reimann

unread,
Dec 5, 2012, 7:32:31 AM12/5/12
to incquer...@googlegroups.com
...but it works if you obey the types EObject for the two parameters :)

Ábel Hegedüs

unread,
Dec 5, 2012, 7:34:20 AM12/5/12
to EMF-IncQuery Users on behalf of Jan Reimann
Hi Jan,

this is related to another issue: https://github.com/ujhelyiz/EMF-IncQuery/issues/309
It is rather lengthy, but the main information is, we feel that we now have an acceptable and sound way of overriding the types of variables that are ambiguous.

However, the implemented solution is not yet available in the released version of EMF-IncQuery, which I guess you're using.
I'm not sure if I should advise you to wait for 0.7 or 0.6.10 (if we decide to include this feature in a future maintenance release), or to try out the Continuous Integration build (https://viatra.inf.mit.bme.hu/incquery/getting_started).
Note, that if you try the latter, you should also read the following migration guide: https://viatra.inf.mit.bme.hu/incquery/documentation/newandnoteworthy/migrate-0.7

Best regards,

--
You received this message because you are subscribed to the Google Groups "EMF-IncQuery Users" group.
To post to this group, send email to incquer...@googlegroups.com.
To unsubscribe from this group, send email to incquery-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/incquery-users/-/WawnofkE0lsJ.

Ábel Hegedüs

unread,
Dec 7, 2012, 12:10:23 PM12/7/12
to EMF-IncQuery Users on behalf of Jan Reimann
Hi Jan,

we have released a new maintenance release that includes the type suppression stuff, you can update if you use the release update site.
Note, that you might have to remove the ": EObject" from the pattern parameter declaration.

Best regards,
--
You received this message because you are subscribed to the Google Groups "EMF-IncQuery Users" group.
To post to this group, send email to incquer...@googlegroups.com.
To unsubscribe from this group, send email to incquery-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/incquery-users/-/2sM44VPCXXYJ.
Reply all
Reply to author
Forward
0 new messages