Skip to content

Commit

Permalink
Fixed pacman indentation issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Jan 31, 2024
1 parent ab2d4c8 commit afea280
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public class AcceleoEvaluator extends AcceleoSwitch<Object> {
*/
private String lastLineOfLastStatement;

/**
* Tells if we should keep the current indentation regardless of the {@link #lastLineOfLastStatement}.
*/
private boolean keepIndentation;

/**
* The {@link IQualifiedNameLookupEngine}.
*/
Expand Down Expand Up @@ -199,6 +204,8 @@ public Object generate(AcceleoASTNode node, Map<String, Object> variables,

final String savedLastLineOfLastStatement = lastLineOfLastStatement;
lastLineOfLastStatement = "";
final boolean keepIndentationSave = keepIndentation;
keepIndentation = false;
if (generationResult == null) {
generationResult = new GenerationResult();
}
Expand All @@ -211,6 +218,7 @@ public Object generate(AcceleoASTNode node, Map<String, Object> variables,
popVariables();
inlinedBlock.removeLast();
lastLineOfLastStatement = savedLastLineOfLastStatement;
keepIndentation = keepIndentationSave;
}

return res;
Expand Down Expand Up @@ -276,7 +284,17 @@ protected void pushIndentation(Block block, String indentation) {
indentationStack.addLast("");
} else {
inlinedBlock.addLast(false);
indentationStack.addLast(indentation);
if (keepIndentation && indentation.isEmpty()) {
final String currentIndentation = peekIndentation();
if (currentIndentation != null) {
indentationStack.addLast(currentIndentation);
} else {
indentationStack.addLast(indentation);
}
keepIndentation = false;
} else {
indentationStack.addLast(indentation);
}
}
}

Expand Down Expand Up @@ -519,6 +537,7 @@ public String caseNewLineStatement(NewLineStatement newLineStatement) {
res = newLine;
}
lastLineOfLastStatement = "";
keepIndentation = true;

return res;
}
Expand Down Expand Up @@ -942,25 +961,27 @@ private String getProtectedAreaContent(ProtectedArea protectedArea, String id) {
} else {
pushIndentation(protectedArea.getBody(), lastLineOfLastStatement);
try {
res.append(IAcceleoGenerationStrategy.USER_CODE_START + " " + id + newLine
+ peekIndentation());
res.append(IAcceleoGenerationStrategy.USER_CODE_START + " " + id + newLine);
lastLineOfLastStatement = "";
keepIndentation = true;

final String text = (String)doSwitch(protectedArea.getBody());
res.append(text);

if (!text.isEmpty() && lastLineOfLastStatement.isEmpty()) {
if (lastLineOfLastStatement.isEmpty()) {
res.append(peekIndentation());
}
if (protectedArea.getEndTagPrefix() != null) {
Object endTagPrefixObject = doSwitch(protectedArea.getEndTagPrefix());
res.append(toString(endTagPrefixObject));
}
res.append(IAcceleoGenerationStrategy.USER_CODE_END + newLine);
} finally {
popIndentation();
}
if (protectedArea.getEndTagPrefix() != null) {
Object endTagPrefixObject = doSwitch(protectedArea.getEndTagPrefix());
res.append(toString(endTagPrefixObject));
}
res.append(IAcceleoGenerationStrategy.USER_CODE_END + newLine);
}
lastLineOfLastStatement = "";
keepIndentation = true;

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

***anydsl


***anydsl

***anydsl

***anydsl


***anydsl

***End of user code
anydsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

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
[.aqlFeatureAccess(myParam, 'name') (189..201)/] (newLineNeeded (188..205)
[if true (214..218)
*** (228..231)
[protected .aqlFeatureAccess(myParam, 'name') (243..255)
NEW_LINE (newLineNeeded) (259..261)
[.aqlFeatureAccess(myParam, 'name') (273..285)/] (newLineNeeded (272..289)
NEW_LINE (newLineNeeded) (289..291)
[if true (307..311)
NEW_LINE (newLineNeeded) (315..317)
[.aqlFeatureAccess(myParam, 'name') (331..343)/] (newLineNeeded (330..347)
NEW_LINE (newLineNeeded) (347..349)
[.aqlFeatureAccess(myParam, 'name') (363..375)/] (newLineNeeded (362..379)
NEW_LINE (newLineNeeded) (379..381)
[.aqlFeatureAccess(myParam, 'name') (395..407)/] (newLineNeeded (394..411)
NEW_LINE (newLineNeeded) (411..413) (313..424)
[/if] (302..429)
(newLineNeeded) (429..431)
NEW_LINE (newLineNeeded) (431..433)
[.aqlFeatureAccess(myParam, 'name') (445..457)/] (newLineNeeded (444..461)
NEW_LINE (newLineNeeded) (461..463) (257..472)
[/protected] (231..484)
(newLineNeeded) (484..486) (220..490)
[/if] (209..495)
(newLineNeeded) (495..497)
[.aqlFeatureAccess(myParam, 'name') (502..514)/] (newLineNeeded (501..518) (182..520)
[/file] (141..527)
(newLineNeeded) (527..529) (137..529)
[/template] (82..540) (0..540)
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,37 @@

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
[.aqlFeatureAccess(myParam, 'name') (184..196)/] (newLineNeeded (183..199)
[if true (208..212)
*** (221..224)
[protected .aqlFeatureAccess(myParam, 'name') (236..248)
NEW_LINE (newLineNeeded) (251..252)
[.aqlFeatureAccess(myParam, 'name') (264..276)/] (newLineNeeded (263..279)
NEW_LINE (newLineNeeded) (279..280)
[if true (296..300)
NEW_LINE (newLineNeeded) (303..304)
[.aqlFeatureAccess(myParam, 'name') (318..330)/] (newLineNeeded (317..333)
NEW_LINE (newLineNeeded) (333..334)
[.aqlFeatureAccess(myParam, 'name') (348..360)/] (newLineNeeded (347..363)
NEW_LINE (newLineNeeded) (363..364)
[.aqlFeatureAccess(myParam, 'name') (378..390)/] (newLineNeeded (377..393)
NEW_LINE (newLineNeeded) (393..394) (302..405)
[/if] (291..410)
(newLineNeeded) (410..411)
NEW_LINE (newLineNeeded) (411..412)
[.aqlFeatureAccess(myParam, 'name') (424..436)/] (newLineNeeded (423..439)
NEW_LINE (newLineNeeded) (439..440) (250..449)
[/protected] (224..461)
(newLineNeeded) (461..462) (214..466)
[/if] (203..471)
(newLineNeeded) (471..472)
[.aqlFeatureAccess(myParam, 'name') (477..489)/] (newLineNeeded (476..492) (178..494)
[/file] (137..501)
(newLineNeeded) (501..502) (134..502)
[/template] (79..513) (0..513)
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,28 @@
[module myModule('http://www.eclipse.org/emf/2002/Ecore')/]

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

[myParam.name/]

[if (true)]

[myParam.name/]

[myParam.name/]

[myParam.name/]

[/if]

[myParam.name/]

[/protected]
[/if]
[myParam.name/]
[/file]
[/template]
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>
Loading

0 comments on commit afea280

Please sign in to comment.