How to include subclasses in ecore models in the resulting matches of a query?

88 views
Skip to first unread message

Jan Reimann

unread,
Oct 14, 2012, 12:11:13 PM10/14/12
to incquer...@googlegroups.com
Hi,
I attached an ecore file and a query file for better understanding my problem. The pattern subClassesWantedInResult queries the ecore file and results in one match where each variable is bound to the equally named EClass or EReference from the ecore file. Then I added the EClass SubOrigContainer as a subclass from OrigContainer. I expected that the result would contain 2 matches now. One identical match as before but another one where OrigContainer is substituted with SubOrigContainer. My question is how to enable subclass querying in this pattern? Is this possible?

best regards,
Jan

Zoltán Ujhelyi

unread,
Oct 14, 2012, 2:20:59 PM10/14/12
to incquer...@googlegroups.com
Hi,

sadly it seems to me that somehow the attachments are missing. Can you either resend them, or at least insert the corresponding pattern textually?

Cheers,
Zoltán

Jan Reimann

unread,
Oct 16, 2012, 7:49:51 AM10/16/12
to incquer...@googlegroups.com
Hi Zoltán,
strange thing. I uploaded the files. Anyway, I upload it again and post the files' contents textually here.

ecore file:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="testextractxwrefclass"
    nsURI="http://testextractxwrefclass/1.0" nsPrefix="testextractxwrefclass">
  <eClassifiers xsi:type="ecore:EClass" name="OrigContainer">
    <eStructuralFeatures xsi:type="ecore:EReference" name="referer" eType="#//MovedReference"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="extracts" eType="#//Extract"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Extract"/>
  <eClassifiers xsi:type="ecore:EClass" name="NewContainer">
    <eStructuralFeatures xsi:type="ecore:EReference" name="moved" eType="#//Extract"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ContainerContainer">
    <eStructuralFeatures xsi:type="ecore:EReference" name="source" eType="#//OrigContainer"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="target" eType="#//NewContainer"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="MovedReference">
    <eStructuralFeatures xsi:type="ecore:EReference" name="containerRef" eType="#//NewContainer"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="SubOrigContainer" eSuperTypes="#//OrigContainer"/>
</ecore:EPackage>

pattern file:

import "http://www.eclipse.org/emf/2002/Ecore"

@QueryExplorer(display = false)
pattern isEcore(Element){
    EClassifier.ePackage(Element,EP);
    EPackage(EP);
    EPackage.nsURI(EP,"http://www.eclipse.org/emf/2002/Ecore");
}

@QueryExplorer(display = false)
pattern isAggregation(ref:EReference){
    EReference.containment(ref,true);
}

pattern ExtractXWithRefClass(OrigCont: EClass, ContCont: EClass, Extract:EClass, NewCont:EClass,
    MovedRef:EClass, extracts:EReference, source:EReference, target:EReference, referer:EReference,
    moved:EReference, containerRef:EReference){

    find eAllContainments(OrigCont,extracts);
    ETypedElement.eType(extracts,Extract);
   
    find eAllContainments(ContCont,source);
    ETypedElement.eType(source,OrigCont);
   
    find eAllContainments(ContCont,target);
    ETypedElement.eType(target,NewCont);
   
    find eAllContainments(OrigCont,referer);
    ETypedElement.eType(referer,MovedRef);
   
    find eAllContainments(NewCont,moved);
    ETypedElement.eType(moved,Extract);
   
    find eAllReferences(MovedRef,containerRef);
    ETypedElement.eType(containerRef,NewCont);
    neg find isAggregation(containerRef);

    neg find isEcore(OrigCont);
    neg find isEcore(ContCont);
    neg find isEcore(NewCont);
    neg find isEcore(MovedRef);
    neg find isEcore(Extract);
}

// well-behaving ecore patterns

@QueryExplorer(display = false)
private pattern eStructuralFeatures(This : EClass, Target : EStructuralFeature){
    EClass.eStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eAttributes(This : EClass, Target : EAttribute){
    find eStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eReferences(This : EClass, Target : EReference){
    find eStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
private pattern eGenericSuperTypes(This : EClass, Target : EGenericType){
    EClass.eGenericSuperTypes(This, Target);
}

@QueryExplorer(display = false)
pattern eAllGenericSuperTypes(This : EClass, Target : EGenericType){
    find eSuperTypes+(This, Type);
    find eGenericSuperTypes(Type, Target);
} or {
    find eGenericSuperTypes(This, Target);
}

@QueryExplorer(display = false)
private pattern eRawType(This : EGenericType, Target : EClass){
    EGenericType.eRawType(This, Target);
}

@QueryExplorer(display = false)
pattern eSuperTypes(This : EClass, Target : EClass){
    find eGenericSuperTypes(This, GenericType);
    find eRawType(GenericType, Target);
}

@QueryExplorer(display = false)
pattern eAllSuperTypes(This : EClass, Target : EClass){
    find eAllGenericSuperTypes(This, GenericType);
    find eRawType(GenericType, Target);
}

@QueryExplorer(display = false)
private pattern thisAndAllSuperTypes(This : EClass, Target : EClass){
    find eAllSuperTypes(This, Target);
} or {
    This == Target;
}

@QueryExplorer(display = false)
pattern eAllStructuralFeatures(This : EClass, Target : EStructuralFeature){
    find thisAndAllSuperTypes(This, Type);
    find eStructuralFeatures(Type, Target);
}

@QueryExplorer(display = false)
pattern eAllAttributes(This : EClass, Target : EAttribute){
    find eAllStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eAllReferences(This : EClass, Target : EReference){
    find eAllStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eAllContainments(This : EClass, Target : EReference){
    find eAllReferences(This, Target);
    EReference.containment(Target, true);
}

@QueryExplorer(display = false)
private pattern eOperations(This : EClass, Target : EOperation){
    EClass.eOperations(This, Target);
}

@QueryExplorer(display = false)
pattern eAllOperations(This : EClass, Target : EOperation){
    find thisAndAllSuperTypes(This, Type);
    find eOperations(Type, Target);
}

// NOTE: EMF uses the first attribute with id = true from all supertypes...
@QueryExplorer(display = false)
pattern eIDAttribute(This : EClass, Target : EAttribute){
    find eAllAttributes(This, Target);
    EAttribute.iD(Target, true);

Jan Reimann

unread,
Oct 16, 2012, 7:51:32 AM10/16/12
to incquer...@googlegroups.com
Ok, it seems that it's prohibited to attach files in this group because I always get a 340 error saying that something went wron with communicating to the server when a file is attached.

István Ráth

unread,
Oct 16, 2012, 8:54:48 AM10/16/12
to incquer...@googlegroups.com
I have changed settings so that anyone can post attachments.

Ábel Hegedüs

unread,
Oct 16, 2012, 9:36:53 AM10/16/12
to EMF-IncQuery Users
Dear Jan,

I have managed to make your pattern work in the way you wanted. The problem is in the following part:

 find eAllContainments(OrigCont,extracts);
 ETypedElement.eType(extracts,Extract);
    
 find eAllContainments(ContCont,source);
 ETypedElement.eType(source,OrigCont);

You want the OrigCont to match to a subclass as well, but the type of the "source" reference must still be exactly the OrigCont.
If you modify your pattern like this:

find eAllContainments(ContCont,source);
ETypedElement.eType(source,SourceType);
    
find thisAndAllSuperTypes(OrigCont, SourceType);
    
Then the type of "source" can be the supertype of the class matched to OrigCont, so the whole pattern will match to SubOrigContainer as well.

It was a nice puzzle!

Best regards,
   Ábel Hegedüs

Fault Tolerant Systems Research Group
Department of Measurement and Information Systems
Budapest University of Technology and Economics



--
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/-/4tUggCDMeoEJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jan Reimann

unread,
Oct 17, 2012, 10:11:16 AM10/17/12
to incquer...@googlegroups.com
Ábel, thank you a lot! It works now and does exactly what I expected :)

best regards,
Jan
Reply all
Reply to author
Forward
0 new messages