Skip to content

Commit

Permalink
Fixed migration for collection query/template call.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Jan 25, 2024
1 parent 9fce58f commit e6b1fb4
Show file tree
Hide file tree
Showing 21 changed files with 1,134 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.eclipse.ocl.ecore.OrderedSetType;
import org.eclipse.ocl.ecore.PropertyCallExp;
import org.eclipse.ocl.ecore.RealLiteralExp;
import org.eclipse.ocl.ecore.SequenceType;
import org.eclipse.ocl.ecore.SetType;
import org.eclipse.ocl.ecore.StringLiteralExp;
import org.eclipse.ocl.ecore.TypeExp;
Expand Down Expand Up @@ -702,9 +703,13 @@ private Expression convertIterator(IteratorExp input, Expression source) {

private Expression caseTemplateInvocation(TemplateInvocation input) {
Call output = AstFactory.eINSTANCE.createCall();
output.setType(CallType.CALLORAPPLY);
output.setServiceName(input.getDefinition().getName());
map(input.getArgument(), output.getArguments());

final EClassifier queryReceiverType = input.getDefinition().getParameter().get(0).getEGenericType()
.getEClassifier();
wrapToCollectionCall(queryReceiverType, output);

return output;
}

Expand All @@ -713,9 +718,51 @@ private Expression caseQueryInvocation(QueryInvocation input) {
output.setType(CallType.CALLORAPPLY);
output.setServiceName(input.getDefinition().getName());
map(input.getArgument(), output.getArguments());

final EClassifier queryReceiverType = input.getDefinition().getParameter().get(0).getEGenericType()
.getEClassifier();
wrapToCollectionCall(queryReceiverType, output);

return output;
}

/**
* Wraps The given converted {@link Call} to a {@link CallType#COLLECTIONCALL collection call} if the
* given receiver type is a {@link CollectionType}.
*
* @param receiverType
* the revceiver {@link EClassifier}
* @param call
* the converted {@link Call}
*/
private void wrapToCollectionCall(final EClassifier receiverType, Call call) {
if (receiverType instanceof OrderedSetType) {
call.setType(CallType.COLLECTIONCALL);
final Expression receiver = call.getArguments().remove(0);
if (receiver instanceof Call && "asOrderedSet".equals(((Call)receiver).getServiceName())) {
call.getArguments().add(0, receiver);
} else {
final Call asOrderedSetCall = AstFactory.eINSTANCE.createCall();
asOrderedSetCall.setServiceName("asOrderedSet");
asOrderedSetCall.setType(CallType.COLLECTIONCALL);
asOrderedSetCall.getArguments().add(receiver);
call.getArguments().add(0, asOrderedSetCall);
}
} else if (receiverType instanceof SequenceType) {
call.setType(CallType.COLLECTIONCALL);
final Expression receiver = call.getArguments().remove(0);
if (receiver instanceof Call && "asSequence".equals(((Call)receiver).getServiceName())) {
call.getArguments().add(0, receiver);
} else {
final Call asOrderedSetCall = AstFactory.eINSTANCE.createCall();
asOrderedSetCall.setServiceName("asSequence");
asOrderedSetCall.setType(CallType.COLLECTIONCALL);
asOrderedSetCall.getArguments().add(receiver);
call.getArguments().add(0, asOrderedSetCall);
}
}
}

private Expression convertCollectionLiteralExp(CollectionLiteralExp input) {
Expression output = null;
EClassifier type = input.getEType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[module collectionQueryCallOrderedSet('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->calledQuery()/]
[/template]


[query public calledQuery(myParam : OrderedSet(ecore::EClassifier)) : Sequence(OclAny) = myParam.name->sep(', ')/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[module collectionQueryCallSequence('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->asSequence()->calledQuery()/]
[/template]


[query public calledQuery(myParam : Sequence(ecore::EClassifier)) : Sequence(OclAny) = myParam.name->sep(', ')/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[module collectionTemplateCallOrderedSet('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->calledTemplate()/]
[/template]


[template public calledTemplate(myParam : OrderedSet(ecore::EClassifier))]
[myParam.name->sep(', ')/]
[/template]

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[module collectionTemplateCallSequence('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->asSequence()->calledTemplate()/]
[/template]


[template public calledTemplate(myParam : Sequence(ecore::EClassifier))]
[myParam.name->sep(', ')/]
[/template]

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[module collectionQueryCallOrderedSet('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->asOrderedSet()->calledQuery()/][/template]

[query public calledQuery(myParam : OrderedSet(ecore::EClassifier)) : Sequence(ecore::EObject) = myParam->asSequence()->collect(temp1 | temp1.name)->sep(', ')/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[module collectionQueryCallOrderedSet('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->calledQuery()/]
[/template]


[query public calledQuery(myParam : OrderedSet(ecore::EClassifier)) : Sequence(OclAny) = myParam.name->sep(', ')/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI 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" xmlns:mtl="http://www.eclipse.org/acceleo/mtl/3.0" xmlns:ocl.ecore="http://www.eclipse.org/ocl/1.1.0/Ecore">
<mtl:Module name="collectionQueryCallOrderedSet" nsURI="resources::acceleoAqlTests::language::expressionStatement::collectionQueryCallOrderedSet::collectionQueryCallOrderedSet" endHeaderPosition="78">
<input>
<takesTypesFrom href="http://www.eclipse.org/emf/2002/Ecore#/"/>
</input>
<ownedModuleElement xsi:type="mtl:Template" name="myTemplate" visibility="Public">
<body xsi:type="ocl.ecore:StringLiteralExp" stringSymbol=" "/>
<body xsi:type="mtl:QueryInvocation" eType="/3/Sequence(OclAny)" definition="/0/calledQuery">
<argument xsi:type="ocl.ecore:PropertyCallExp" eType="/3/OrderedSet(EClassifier)">
<source xsi:type="ocl.ecore:VariableExp" name="myParam" referredVariable="/0/myTemplate/myParam">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</source>
<referredProperty xsi:type="ecore:EReference" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage/eClassifiers"/>
</argument>
</body>
<parameter name="myParam">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</parameter>
</ownedModuleElement>
<ownedModuleElement xsi:type="mtl:Query" name="calledQuery" visibility="Public" type="/3/Sequence(OclAny)">
<parameter name="myParam" eType="/3/OrderedSet(EClassifier)"/>
<expression xsi:type="ocl.ecore:OperationCallExp" eType="/3/Sequence(OclAny)" referredOperation="/1/oclstdlib_Collection(T)_Class/sep">
<source xsi:type="ocl.ecore:IteratorExp" name="collect" eType="/3/Sequence(String)">
<source xsi:type="ocl.ecore:VariableExp" name="myParam" eType="/3/OrderedSet(EClassifier)" referredVariable="/0/calledQuery/myParam"/>
<body xsi:type="ocl.ecore:PropertyCallExp">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
<source xsi:type="ocl.ecore:VariableExp" name="temp1" referredVariable="/0/calledQuery/%/collect/temp1">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EClassifier"/>
</source>
<referredProperty xsi:type="ecore:EAttribute" href="http://www.eclipse.org/emf/2002/Ecore#//ENamedElement/name"/>
</body>
<iterator xsi:type="ocl.ecore:Variable" name="temp1">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EClassifier"/>
</iterator>
</source>
<argument xsi:type="ocl.ecore:StringLiteralExp" stringSymbol=", ">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</argument>
</expression>
</ownedModuleElement>
</mtl:Module>
<ecore:EPackage name="additions">
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_String_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Integer_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Integer"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Real_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Real"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ecore_EObject_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</eAnnotations>
<eOperations name="myTemplate">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<contents xsi:type="ocl.ecore:Constraint"/>
</eAnnotations>
<eAnnotations source="MTL" references="/0/myTemplate"/>
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
<eParameters name="myParam">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</eParameters>
</eOperations>
<eOperations name="calledQuery" eType="/3/Sequence(OclAny)">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<contents xsi:type="ocl.ecore:Constraint"/>
</eAnnotations>
<eAnnotations source="MTL" references="/0/calledQuery"/>
<eParameters name="myParam" eType="/3/OrderedSet(EClassifier)"/>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_OclAny_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OclAny"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Collection(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Collection(T)"/>
</eAnnotations>
<eOperations name="sep">
<eAnnotations source="MTL non-standard"/>
<eType xsi:type="ocl.ecore:SequenceType" href="http://www.eclipse.org/acceleo/mtl/3.0/mtlnonstdlib.ecore#//Sequence(OclAny)"/>
<eParameters name="separatorString">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</eParameters>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Sequence(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Sequence(T)"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_OrderedSet(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OrderedSet(T)"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ecore_EPackage_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="collections_OrderedSet(EClassifier)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL" references="/3/OrderedSet(EClassifier)"/>
</eClassifiers>
</ecore:EPackage>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</ocl.ecore:Variable>
<ecore:EPackage name="collections">
<eClassifiers xsi:type="ocl.ecore:SequenceType" name="Sequence(OclAny)" instanceClassName="java.util.List">
<elementType xsi:type="ocl.ecore:AnyType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OclAny"/>
</eClassifiers>
<eClassifiers xsi:type="ocl.ecore:OrderedSetType" name="OrderedSet(EClassifier)" instanceClassName="java.util.LinkedHashSet">
<elementType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EClassifier"/>
</eClassifiers>
<eClassifiers xsi:type="ocl.ecore:SequenceType" name="Sequence(String)" instanceClassName="java.util.List">
<elementType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</eClassifiers>
</ecore:EPackage>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</ocl.ecore:Variable>
<ocl.ecore:Variable name="self">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</ocl.ecore:Variable>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</ocl.ecore:Variable>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</ocl.ecore:Variable>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</ocl.ecore:Variable>
<ocl.ecore:Variable name="self" eType="/3/OrderedSet(EClassifier)"/>
<ocl.ecore:Variable name="self" eType="/3/OrderedSet(EClassifier)"/>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</ocl.ecore:Variable>
<ecore:EAnnotation source="positions">
<eAnnotations source="positions.0" references="/0/myTemplate">
<details key="start" value="82"/>
<details key="end" value="190"/>
<details key="line" value="3"/>
</eAnnotations>
<eAnnotations source="positions.1" references="/0/myTemplate/%">
<details key="start" value="138"/>
<details key="end" value="140"/>
<details key="line" value="4"/>
</eAnnotations>
<eAnnotations source="positions.2" references="/0/myTemplate/%.1">
<details key="start" value="141"/>
<details key="end" value="176"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.3" references="/0/myTemplate/%.1/%">
<details key="start" value="141"/>
<details key="end" value="161"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.4" references="/0/myTemplate/%.1/%/myParam">
<details key="start" value="141"/>
<details key="end" value="148"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.5" references="/0/myTemplate/myParam">
<details key="start" value="110"/>
<details key="end" value="135"/>
<details key="line" value="3"/>
</eAnnotations>
<eAnnotations source="positions.6" references="/0/calledQuery">
<details key="start" value="193"/>
<details key="end" value="307"/>
<details key="line" value="8"/>
</eAnnotations>
<eAnnotations source="positions.7" references="/0/calledQuery/myParam">
<details key="start" value="219"/>
<details key="end" value="259"/>
<details key="line" value="8"/>
</eAnnotations>
<eAnnotations source="positions.8" references="/0/calledQuery/%">
<details key="start" value="282"/>
<details key="end" value="305"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.9" references="/0/calledQuery/%/collect">
<details key="start" value="282"/>
<details key="end" value="294"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.10" references="/0/calledQuery/%/collect/myParam">
<details key="start" value="282"/>
<details key="end" value="289"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.11" references="/0/calledQuery/%/collect/%">
<details key="start" value="290"/>
<details key="end" value="294"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.12" references="/0/calledQuery/%/collect/%/temp1">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.13" references="/0/calledQuery/%/collect/temp1">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.14" references="/0/calledQuery/%/%">
<details key="start" value="300"/>
<details key="end" value="304"/>
<details key="line" value="0"/>
</eAnnotations>
</ecore:EAnnotation>
</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[module collectionQueryCallOrderedSet('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->asOrderedSet()->calledQuery()/][/template]

[query public calledQuery(myParam : OrderedSet(ecore::EClassifier)) : Sequence(ecore::EObject) = myParam->asSequence()->collect(temp1 | temp1.name)->sep(', ')/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[module collectionQueryCallSequence('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->asSequence()->calledQuery()/][/template]

[query public calledQuery(myParam : Sequence(ecore::EClassifier)) : Sequence(ecore::EObject) = myParam->collect(temp1 | temp1.name)->sep(', ')/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[module collectionQueryCallSequence('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[myParam.eClassifiers->asSequence()->calledQuery()/]
[/template]


[query public calledQuery(myParam : Sequence(ecore::EClassifier)) : Sequence(OclAny) = myParam.name->sep(', ')/]
Loading

0 comments on commit e6b1fb4

Please sign in to comment.