Skip to content

Commit

Permalink
Added let expression migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Jan 4, 2024
1 parent 01d3f84 commit c202fca
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2023 Obeo.
* Copyright (c) 2017, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -33,6 +33,7 @@
import org.eclipse.acceleo.model.mtl.TemplateInvocation;
import org.eclipse.acceleo.query.ast.AstFactory;
import org.eclipse.acceleo.query.ast.AstPackage;
import org.eclipse.acceleo.query.ast.Binding;
import org.eclipse.acceleo.query.ast.BooleanLiteral;
import org.eclipse.acceleo.query.ast.Call;
import org.eclipse.acceleo.query.ast.CallType;
Expand All @@ -41,6 +42,7 @@
import org.eclipse.acceleo.query.ast.Expression;
import org.eclipse.acceleo.query.ast.IntegerLiteral;
import org.eclipse.acceleo.query.ast.Lambda;
import org.eclipse.acceleo.query.ast.Let;
import org.eclipse.acceleo.query.ast.RealLiteral;
import org.eclipse.acceleo.query.ast.SequenceInExtensionLiteral;
import org.eclipse.acceleo.query.ast.SetInExtensionLiteral;
Expand Down Expand Up @@ -70,6 +72,7 @@
import org.eclipse.ocl.ecore.IfExp;
import org.eclipse.ocl.ecore.IntegerLiteralExp;
import org.eclipse.ocl.ecore.IteratorExp;
import org.eclipse.ocl.ecore.LetExp;
import org.eclipse.ocl.ecore.OCLExpression;
import org.eclipse.ocl.ecore.OperationCallExp;
import org.eclipse.ocl.ecore.OrderedSetType;
Expand Down Expand Up @@ -243,6 +246,9 @@ protected Object convert(EObject input) {
case EcorePackage.COLLECTION_ITEM:
output = convert(((CollectionItem)input).getItem());
break;
case EcorePackage.LET_EXP:
output = caseLetExp((LetExp)input);
break;
// case EcorePackage.COLLECTION_RANGE:
// output = convert(((CollectionItem)input).getItem());
// break;
Expand All @@ -252,6 +258,22 @@ protected Object convert(EObject input) {
return output;
}

private Object caseLetExp(LetExp input) {
final Let output = AstFactory.eINSTANCE.createLet();

output.setBody((Expression)convert(input.getIn()));

if (input.getVariable() != null) {
final Binding binding = AstFactory.eINSTANCE.createBinding();
binding.setName(input.getVariable().getName());
binding.setType(TypeUtils.createTypeLiteral(input.getVariable().getType()));
binding.setValue((Expression)convert(input.getVariable().getInitExpression()));
output.getBindings().add(binding);
}

return output;
}

private Object caseIfExp(IfExp input) {
Conditional output = AstFactory.eINSTANCE.createConditional();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Obeo.
* Copyright (c) 2020, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -151,7 +151,7 @@ public Object caseBinding(Binding binding) {
builder.append(bindingName);
if (binding.getType() != null) {
builder.append(SPACE).append(':').append(SPACE);
builder.append(doSwitch(binding.getType()));
doSwitch(binding.getType());
}
builder.append(SPACE).append('=').append(SPACE);
doSwitch(binding.getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[module letExpression('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[file (myParam.name + '.txt', false)]
['The name is: ' + myParam.myQuery()/]
[/file]
[/template]

[query public myQuery(myParam : ecore::EPackage) : String =
let s : ecore::EPackage = myParam in s.name/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[module letExpression('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[file (myParam.name + '.txt', overwrite)]
['The name is: ' + myParam.myQuery()/]
[/file]
[/template]

[query public myQuery(myParam : ecore::EPackage) : String = let s : ecore::EPackage = myParam in s.name/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[module letExpression('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[file (myParam.name + '.txt', false)]
['The name is: ' + myParam.myQuery()/]
[/file]
[/template]

[query public myQuery(myParam : ecore::EPackage) : String =
let s : ecore::EPackage = myParam in s.name/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
<?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="letExpression" nsURI="resources::acceleoAqlTests::evaluation::expressionStatement::letExpression::letExpression" endHeaderPosition="62">
<input>
<takesTypesFrom href="http://www.eclipse.org/emf/2002/Ecore#/"/>
</input>
<ownedModuleElement xsi:type="mtl:Template" name="myTemplate" visibility="Public">
<body xsi:type="mtl:FileBlock" openMode="OverWrite">
<body xsi:type="ocl.ecore:StringLiteralExp" stringSymbol=" "/>
<body xsi:type="ocl.ecore:OperationCallExp" referredOperation="/1/oclstdlib_String_Class/+">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
<source xsi:type="ocl.ecore:StringLiteralExp" stringSymbol="The name is: ">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</source>
<argument xsi:type="mtl:QueryInvocation" definition="/0/myQuery">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
<argument 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"/>
</argument>
</argument>
</body>
<body xsi:type="ocl.ecore:StringLiteralExp" stringSymbol="&#xA;"/>
<fileUrl xsi:type="ocl.ecore:OperationCallExp" referredOperation="/1/oclstdlib_String_Class/+">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
<source 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="myParam" referredVariable="/0/myTemplate/myParam">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</source>
<referredProperty xsi:type="ecore:EAttribute" href="http://www.eclipse.org/emf/2002/Ecore#//ENamedElement/name"/>
</source>
<argument xsi:type="ocl.ecore:StringLiteralExp" stringSymbol=".txt">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</argument>
</fileUrl>
</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="myQuery" visibility="Public">
<parameter name="myParam">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</parameter>
<expression xsi:type="ocl.ecore:LetExp">
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
<in 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="s" referredVariable="/0/myQuery/%/s">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</source>
<referredProperty xsi:type="ecore:EAttribute" href="http://www.eclipse.org/emf/2002/Ecore#//ENamedElement/name"/>
</in>
<variable xsi:type="ocl.ecore:Variable" name="s">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
<initExpression xsi:type="ocl.ecore:VariableExp" name="myParam" referredVariable="/0/myQuery/myParam">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
</initExpression>
</variable>
</expression>
<type xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</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>
<eOperations name="+">
<eAnnotations source="MTL non-standard"/>
<eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
<eParameters name="other">
<eType xsi:type="ocl.ecore:AnyType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OclAny"/>
</eParameters>
</eOperations>
</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="myQuery">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<contents xsi:type="ocl.ecore:Constraint"/>
</eAnnotations>
<eAnnotations source="MTL" references="/0/myQuery"/>
<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>
</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>
</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>
</ecore:EPackage>
<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 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#//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 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>
<ecore:EAnnotation source="positions">
<eAnnotations source="positions.0" references="/0/myTemplate">
<details key="start" value="66"/>
<details key="end" value="226"/>
<details key="line" value="3"/>
</eAnnotations>
<eAnnotations source="positions.1" references="/0/myTemplate/%">
<details key="start" value="124"/>
<details key="end" value="214"/>
<details key="line" value="4"/>
</eAnnotations>
<eAnnotations source="positions.2" references="/0/myTemplate/%/%">
<details key="start" value="162"/>
<details key="end" value="166"/>
<details key="line" value="5"/>
</eAnnotations>
<eAnnotations source="positions.3" references="/0/myTemplate/%/%.1">
<details key="start" value="167"/>
<details key="end" value="202"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.4" references="/0/myTemplate/%/%.1/%">
<details key="start" value="167"/>
<details key="end" value="182"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.5" references="/0/myTemplate/%/%.1/%.1">
<details key="start" value="185"/>
<details key="end" value="202"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.6" references="/0/myTemplate/%/%.1/%.1/myParam">
<details key="start" value="185"/>
<details key="end" value="192"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.7" references="/0/myTemplate/%/%.2">
<details key="start" value="204"/>
<details key="end" value="205"/>
<details key="line" value="6"/>
</eAnnotations>
<eAnnotations source="positions.8" references="/0/myTemplate/%/%.3">
<details key="start" value="131"/>
<details key="end" value="152"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.9" references="/0/myTemplate/%/%.3/%">
<details key="start" value="131"/>
<details key="end" value="143"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.10" references="/0/myTemplate/%/%.3/%/myParam">
<details key="start" value="131"/>
<details key="end" value="138"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.11" references="/0/myTemplate/%/%.3/%.1">
<details key="start" value="146"/>
<details key="end" value="152"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.12" references="/0/myTemplate/myParam">
<details key="start" value="94"/>
<details key="end" value="119"/>
<details key="line" value="3"/>
</eAnnotations>
<eAnnotations source="positions.13" references="/0/myQuery">
<details key="start" value="228"/>
<details key="end" value="335"/>
<details key="line" value="9"/>
</eAnnotations>
<eAnnotations source="positions.14" references="/0/myQuery/myParam">
<details key="start" value="250"/>
<details key="end" value="275"/>
<details key="line" value="9"/>
</eAnnotations>
<eAnnotations source="positions.15" references="/0/myQuery/%">
<details key="start" value="290"/>
<details key="end" value="333"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.16" references="/0/myQuery/%/%">
<details key="start" value="327"/>
<details key="end" value="333"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.17" references="/0/myQuery/%/%/s">
<details key="start" value="327"/>
<details key="end" value="328"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.18" references="/0/myQuery/%/s">
<details key="start" value="294"/>
<details key="end" value="323"/>
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.19" references="/0/myQuery/%/s/myParam">
<details key="start" value="316"/>
<details key="end" value="323"/>
<details key="line" value="0"/>
</eAnnotations>
</ecore:EAnnotation>
</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[module letExpression('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[file (myParam.name + '.txt', overwrite)]
['The name is: ' + myParam.myQuery()/]
[/file]
[/template]

[query public myQuery(myParam : ecore::EPackage) : String = let s : ecore::EPackage = myParam in s.name/]

0 comments on commit c202fca

Please sign in to comment.