Skip to content

Commit

Permalink
Fixed NewLineStatement indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Jan 29, 2024
1 parent 513bb23 commit a02f7ca
Show file tree
Hide file tree
Showing 39 changed files with 493 additions and 18 deletions.
19 changes: 19 additions & 0 deletions plugins/org.eclipse.acceleo.aql.doc/pages/Acceleo/language.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,25 @@ Type of the variable. Four different kind of types are accepted
* eclassifier : in the form <epackage_name>::<classifier_name> such as ecore::EClass.
* union type : in the form {<epackage_name>::<classifier_name> | <epackage_name>::<classifier_name> | ...}. This kind of typing describes a variable that can be either one of the _n_ specified classifiers. e.g. {ecore::EAttribute | ecore::EReference }.

=== White spaces

When generating text, and especially code, white spaces and indentation is an important point.
In order to keep template code indentation from interfering with the generated output, a few rules applies:

- each block has a *mandatory indentation* of *two characters* that will not be generated in the output (in yellow below)
- when generating a block if the last generated line is not empty, it is repeated at the beginning of each line generated by the block (in red below)

image::images/Indentation.png[Indentation]

[WARNING]
====
In a template you have to *let 2 whitespaces at the beginning of each line*, else the generated content will be truncated by 2 characters.
====

image::images/IndentationIssue.png[Truncated generation due to indentation]

Their is one exception to this rule, an empty line in the module will generate an empty line in the output. This allows to either generate an empty line that use indentation or an empty line regardless of current indentation:

=== Query

A query is a re-useable AQL expression that can return any type of Object. They are commonly used to extract information from the input models. A query is enclosed in a `[query ...]` tag.
Expand Down
17 changes: 0 additions & 17 deletions plugins/org.eclipse.acceleo.aql.doc/pages/Acceleo/tool.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,6 @@ This is supported for all kinds of elements: templates, queries, metamodels, met

image::images/OpenDeclaration.png[Open Declaration]

==== White spaces

When generating text, and especially code, white spaces and indentation is an important point.
In order to keep template code indentation from interfering with the generated output, a few rules applies:

- each block has a *mandatory indentation* of *two characters* than will not be generated in the output (in yellow below)
- when generating a block if the last generated line is not empty, it is repeated at the beginning of each line generated by the block (in red below)

image::images/Indentation.png[Indentation]

[WARNING]
====
In a template you have to *let 2 whitespaces at the beginning of each line*, else the generated content will be truncated by 2 characters.
====

image::images/IndentationIssue.png[Truncated generation due to indentation]

=== The Acceleo Debugger

==== Breakpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,12 @@ public String caseTextStatement(TextStatement textStatement) {
public String caseNewLineStatement(NewLineStatement newLineStatement) {
final String res;

if (newLineStatement.isIndentationNeeded()) {
if (newLineStatement.isIndentationNeeded() && lastLineOfLastStatement.isEmpty()) {
res = peekIndentation() + newLine;
} else {
res = newLine;
}
lastLineOfLastStatement = "";

return res;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
***Start of user code anydsl
***
***End of user code
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

header position 0..59
module myModule
metamodel http://www.eclipse.org/emf/2002/Ecore (18..56)
[comment @main (72..78) /] (63..80)

public template myTemplate(myParam : EPackage (110..135))
@main
[file url .add(.aqlFeatureAccess(myParam, 'name'), '.txt') (148..169) mode overwrite
*** (188..191)
[protected .aqlFeatureAccess(myParam, 'name') (203..215)
NEW_LINE (indentationNeeded) (newLineNeeded) (228..230) (217..237)
[/protected] (191..249)
(newLineNeeded) (249..251) (182..253)
[/file] (141..260)
(newLineNeeded) (260..262) (137..262)
[/template] (82..273) (0..273)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

header position 0..59
module myModule
metamodel http://www.eclipse.org/emf/2002/Ecore (18..56)
[comment @main (70..76) /] (61..78)

public template myTemplate(myParam : EPackage (107..132))
@main
[file url .add(.aqlFeatureAccess(myParam, 'name'), '.txt') (144..165) mode overwrite
*** (183..186)
[protected .aqlFeatureAccess(myParam, 'name') (198..210)
NEW_LINE (indentationNeeded) (newLineNeeded) (222..223) (212..230)
[/protected] (186..242)
(newLineNeeded) (242..243) (178..245)
[/file] (137..252)
(newLineNeeded) (252..253) (134..253)
[/template] (79..264) (0..264)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[module myModule('http://www.eclipse.org/emf/2002/Ecore')/]

[comment @main /]
[template public myTemplate(myParam : ecore::EPackage)]
[file (myParam.name + '.txt', overwrite)]
***[protected (myParam.name)]

[/protected]
[/file]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(null 0 0) null[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(null 0 0) null[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?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="anydsl" nsURI="http://www.eclipse.org/acceleo/anydsl" nsPrefix="anydsl">
<eClassifiers xsi:type="ecore:EClass" name="World">
<eAnnotations source="http://www.obeo.fr/dsl/dnc/archetype">
<details key="archetype" value="MomentInterval"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="companies" upperBound="-1"
eType="#//Company" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="foods" upperBound="-1"
eType="#//Food" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="sources" upperBound="-1"
eType="#//Source" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="MultiNamedElement" abstract="true" interface="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" upperBound="-1" eType="#//SingleString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="NamedElement" abstract="true" interface="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="#//SingleString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Producer" eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="adress" eType="#//Adress"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="company" eType="#//Company"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="foods" upperBound="-1"
eType="#//Food" eOpposite="#//Food/producers"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Adress">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="zipCode" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="city" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="country" eType="#//CountryData"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Company" abstract="true" interface="true"
eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="adress" eType="#//Adress"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="world" eType="#//World"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ProductionCompany" eSuperTypes="#//Company">
<eStructuralFeatures xsi:type="ecore:EReference" name="producers" upperBound="-1"
eType="#//Producer" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Restaurant" eSuperTypes="#//Company">
<eStructuralFeatures xsi:type="ecore:EReference" name="chefs" upperBound="-1"
eType="#//Chef" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="menu" upperBound="-1" eType="#//EStringToRecipeMap"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Chef" eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="adress" eType="#//Adress"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="recipes" upperBound="-1"
eType="#//Recipe" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Recipe" eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="ingredients" upperBound="-1"
eType="#//Food"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Food" eSuperTypes="#//NamedElement">
<eOperations name="ripen" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eParameters name="color" eType="#//Color"/>
</eOperations>
<eOperations name="preferredColor" eType="#//Color"/>
<eOperations name="newFood" eType="#//Food"/>
<eOperations name="setColor">
<eParameters name="food" eType="#//Food"/>
<eParameters name="newColor" eType="#//Color"/>
</eOperations>
<eOperations name="setCaliber">
<eParameters name="food" eType="#//Food"/>
<eParameters name="newCaliber" upperBound="-1" eType="#//Caliber"/>
</eOperations>
<eOperations name="acceptedCaliber" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eParameters name="caliber" eType="#//Caliber"/>
</eOperations>
<eOperations name="label">
<eParameters name="text" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eOperations>
<eOperations name="preferredLabel" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eParameters name="text" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="color" upperBound="-1"
eType="#//Color"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="caliber" eType="#//Caliber"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="relatedFoods" upperBound="-1"
eType="#//Food"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="group" eType="#//Group"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="source" eType="#//Source"
eOpposite="#//Source/foods"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="producers" upperBound="-1"
eType="#//Producer" eOpposite="#//Producer/foods"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Source" abstract="true" interface="true"
eSuperTypes="#//MultiNamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="foods" upperBound="-1"
eType="#//Food" eOpposite="#//Food/source"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="origin" upperBound="-1"
eType="#//CountryData"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Plant" eSuperTypes="#//Source">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="kind" eType="#//Kind"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Animal" eSuperTypes="#//Source">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="part" upperBound="-1" eType="#//Part"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Color">
<eLiterals name="black"/>
<eLiterals name="red" value="1"/>
<eLiterals name="green" value="2"/>
<eLiterals name="yellow" value="3"/>
<eLiterals name="orange" value="4"/>
<eLiterals name="brown" value="5"/>
<eLiterals name="pink" value="6"/>
<eLiterals name="palPink" value="7" literal="palPink"/>
<eLiterals name="veryYellow" value="8"/>
<eLiterals name="white" value="9"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Caliber">
<eLiterals name="S"/>
<eLiterals name="M" value="1"/>
<eLiterals name="L" value="2"/>
<eLiterals name="XL" value="3"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Group">
<eLiterals name="Water"/>
<eLiterals name="Dairy" value="1"/>
<eLiterals name="Fruit" value="2"/>
<eLiterals name="Grain" value="3"/>
<eLiterals name="Protein" value="4"/>
<eLiterals name="Sweet" value="5"/>
<eLiterals name="Vegetable" value="6"/>
<eLiterals name="Alcohol" value="7"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Continent">
<eLiterals name="Europe"/>
<eLiterals name="Asia" value="1"/>
<eLiterals name="Africa" value="2"/>
<eLiterals name="America" value="3"/>
<eLiterals name="Australia" value="4"/>
<eLiterals name="Antarctica" value="5"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Kind">
<eLiterals name="Other"/>
<eLiterals name="Seed" value="1"/>
<eLiterals name="Oilseed" value="2"/>
<eLiterals name="Tree" value="3"/>
<eLiterals name="Root" value="4"/>
<eLiterals name="Bulb" value="5"/>
<eLiterals name="Leaf" value="6"/>
<eLiterals name="Stem" value="7"/>
<eLiterals name="Flower" value="8"/>
<eLiterals name="Inflorescence" value="9"/>
<eLiterals name="Spice" value="10"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Part">
<eLiterals name="Other"/>
<eLiterals name="Muscle" value="1"/>
<eLiterals name="Organ" value="2"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="CountryData" instanceClassName="anydsl.Country"/>
<eClassifiers xsi:type="ecore:EDataType" name="SingleString" instanceClassName="java.lang.String"/>
<eClassifiers xsi:type="ecore:EClass" name="EStringToRecipeMap" instanceClassName="java.util.Map$Entry">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="value" eType="#//Recipe"/>
</eClassifiers>
</ecore:EPackage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

header position 0..59
module myModule
metamodel http://www.eclipse.org/emf/2002/Ecore (18..56)
[comment @main (72..78) /] (63..80)

public template myTemplate(myParam : EPackage (110..135))
@main
[file url .add(.aqlFeatureAccess(myParam, 'name'), '.txt') (148..169) mode overwrite
*** (188..191)
[if true (196..200)
before empty line (newLineNeeded) (213..232)
NEW_LINE (newLineNeeded) (232..234)
after empty line (newLineNeeded) (243..261) (202..268)
[/if] (191..273)
(newLineNeeded) (273..275) (182..277)
[/file] (141..284)
(newLineNeeded) (284..286) (137..286)
[/template] (82..297) (0..297)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(null 0 0) null[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

header position 0..59
module myModule
metamodel http://www.eclipse.org/emf/2002/Ecore (18..56)
[comment @main (70..76) /] (61..78)

public template myTemplate(myParam : EPackage (107..132))
@main
[file url .add(.aqlFeatureAccess(myParam, 'name'), '.txt') (144..165) mode overwrite
*** (183..186)
[if true (191..195)
before empty line (newLineNeeded) (207..225)
NEW_LINE (newLineNeeded) (225..226)
after empty line (newLineNeeded) (235..252) (197..259)
[/if] (186..264)
(newLineNeeded) (264..265) (178..267)
[/file] (137..274)
(newLineNeeded) (274..275) (134..275)
[/template] (79..286) (0..286)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(null 0 0) null[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[module myModule('http://www.eclipse.org/emf/2002/Ecore')/]

[comment @main /]
[template public myTemplate(myParam : ecore::EPackage)]
[file (myParam.name + '.txt', overwrite)]
***[if (true)]
before empty line

after empty line
[/if]
[/file]
[/template]
Loading

0 comments on commit a02f7ca

Please sign in to comment.