Skip to content

Commit

Permalink
Fixed ExpressionStatement AQL if and let serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Jan 25, 2024
1 parent 230befb commit cdb7b31
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 19 deletions.
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 @@ -39,6 +39,8 @@
import org.eclipse.acceleo.Template;
import org.eclipse.acceleo.TextStatement;
import org.eclipse.acceleo.Variable;
import org.eclipse.acceleo.query.ast.Conditional;
import org.eclipse.acceleo.query.ast.Let;
import org.eclipse.acceleo.query.parser.AstBuilder;
import org.eclipse.acceleo.query.parser.AstSerializer;
import org.eclipse.acceleo.util.AcceleoSwitch;
Expand Down Expand Up @@ -206,6 +208,11 @@ public Object caseExpression(Expression expression) {
@Override
public Object caseExpressionStatement(ExpressionStatement expressionStatement) {
builder.append(AcceleoParser.EXPRESSION_STATEMENT_START);
if (expressionStatement.getExpression() != null && (expressionStatement.getExpression()
.getAql() instanceof Conditional || expressionStatement.getExpression()
.getAql() instanceof Let)) {
builder.append(SPACE);
}
doSwitch(expressionStatement.getExpression());
builder.append(AcceleoParser.EXPRESSION_STATEMENT_END);
if (expressionStatement.isNewLineNeeded()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2023 Obeo.
* Copyright (c) 2015, 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 @@ -704,10 +704,10 @@ public Set<EClass> getContainedEClasses(EClass eCls) {

@Override
public Set<EClass> getAllContainedEClasses(EClass eCls) {
final Set<EClass> direcltyContainedEClasses = getContainedEClasses(eCls);
final Set<EClass> result = new LinkedHashSet<EClass>(direcltyContainedEClasses);
final Set<EClass> directlyContainedEClasses = getContainedEClasses(eCls);
final Set<EClass> result = new LinkedHashSet<EClass>(directlyContainedEClasses);

Set<EClass> added = new LinkedHashSet<EClass>(direcltyContainedEClasses);
Set<EClass> added = new LinkedHashSet<EClass>(directlyContainedEClasses);
while (!added.isEmpty()) {
final Set<EClass> toDig = new LinkedHashSet<EClass>();
for (EClass a : added) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 Obeo.
* Copyright (c) 2015, 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 @@ -147,7 +147,7 @@ private Set<IType> getTypeForSpecificType(ValidationServices services,
}
if (result.isEmpty()) {
result.add(new SequenceType(queryEnvironment, services.nothing(
"%s can't contain %s direclty or indirectly", argTypes.get(0), argTypes.get(1))));
"%s can't contain %s directly or indirectly", argTypes.get(0), argTypes.get(1))));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 Obeo.
* Copyright (c) 2015, 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 @@ -624,7 +624,7 @@ private Set<IType> getTypeForSpecificType(ValidationServices services,
}
if (result.isEmpty()) {
result.add(new SequenceType(queryEnvironment, services.nothing(
"%s can't contain %s direclty", argTypes.get(0), argTypes.get(1))));
"%s can't contain %s directly", argTypes.get(0), argTypes.get(1))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<expectations xsi:type="qmodel:QueryValidationResultExpectation">
<expectedResult interpreter="manual">
<possibleTypes>java.lang.Boolean</possibleTypes>
<validationMessages severity="INFO" message="Empty collection: Nothing will be left after calling eAllContents:&#xA;EClassifier=Company can't contain EClassifierLiteral=Food direclty or indirectly" startPosition="31" endPosition="58"/>
<validationMessages severity="INFO" message="Empty collection: Nothing will be left after calling eAllContents:&#xA;EClassifier=Company can't contain EClassifierLiteral=Food directly or indirectly" startPosition="31" endPosition="58"/>
<validationMessages message="Always false:&#xA;Nothing inferred when i (EClassifier=Producer) is kind of EClassifierLiteral=Food&#xA;Nothing inferred when i (EClassifier=EAnnotation) is kind of EClassifierLiteral=Food" startPosition="131" endPosition="158"/>
</expectedResult>
</expectations>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 Obeo.
* Copyright (c) 2015, 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 @@ -243,9 +243,9 @@ public void testEAllContentsFilteredNoContainingEClass() {
final IType[] parameterTypes = new IType[] {eClassifierType(eCls1), eClassifierLiteralType(
eCls2) };
final IType[] expectedReturnTypes = new IType[] {sequenceType(nothingType(
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty or indirectly")) };
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly or indirectly")) };
final IType[] expectedAllReturnTypes = new IType[] {sequenceType(nothingType(
"Nothing will be left after calling eAllContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty or indirectly")) };
"Nothing will be left after calling eAllContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly or indirectly")) };

assertValidation(expectedReturnTypes, expectedAllReturnTypes, "eAllContents", parameterTypes);
} finally {
Expand Down Expand Up @@ -480,9 +480,9 @@ public void testEAllContentsFilteredNoType() {
final IType[] parameterTypes = new IType[] {eClassifierType(eCls1), eClassifierLiteralType(
eCls2) };
final IType[] expectedReturnTypes = new IType[] {sequenceType(nothingType(
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty or indirectly")) };
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly or indirectly")) };
final IType[] expectedAllReturnTypes = new IType[] {sequenceType(nothingType(
"Nothing will be left after calling eAllContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty or indirectly")) };
"Nothing will be left after calling eAllContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly or indirectly")) };

assertValidation(expectedReturnTypes, expectedAllReturnTypes, "eAllContents", parameterTypes);
} finally {
Expand Down Expand Up @@ -1188,9 +1188,9 @@ public void testEContentsFilteredNoContainingEClass() {
final IType[] parameterTypes = new IType[] {eClassifierType(eCls1), eClassifierLiteralType(
eCls2) };
final IType[] expectedReturnTypes = new IType[] {sequenceType(nothingType(
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty")) };
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly")) };
final IType[] expectedAllReturnTypes = new IType[] {sequenceType(nothingType(
"Nothing will be left after calling eContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty")) };
"Nothing will be left after calling eContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly")) };

assertValidation(expectedReturnTypes, expectedAllReturnTypes, "eContents", parameterTypes);
} finally {
Expand Down Expand Up @@ -1495,9 +1495,9 @@ public void testEContentsFilteredNoType() {
final IType[] parameterTypes = new IType[] {eClassifierType(eCls1), eClassifierLiteralType(
eCls2) };
final IType[] expectedReturnTypes = new IType[] {sequenceType(nothingType(
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty")) };
"EClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly")) };
final IType[] expectedAllReturnTypes = new IType[] {sequenceType(nothingType(
"Nothing will be left after calling eContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 direclty")) };
"Nothing will be left after calling eContents:\nEClassifier=eCls1 can't contain EClassifierLiteral=eCls2 directly")) };

assertValidation(expectedReturnTypes, expectedAllReturnTypes, "eContents", parameterTypes);
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

header position 0..59
module myModule
metamodel http://www.eclipse.org/emf/2002/Ecore (18..56)

public template myTemplate(myParam : EPackage (89..114))
[if (.equals(.aqlFeatureAccess(myParam, 'name'), '')) then 'No name' else .aqlFeatureAccess(myParam, 'name') endif (121..180)/] (newLineNeeded (119..183) (116..183)
[/template] (61..194) (0..194)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[module myModule('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[ if myParam.name = '' then 'No name' else myParam.name endif/]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

header position 0..59
module myModule
metamodel http://www.eclipse.org/emf/2002/Ecore (18..56)

public template myTemplate(myParam : EPackage (89..114))
[p = myParamnull, in .aqlFeatureAccess(p, 'name') (121..146)/] (newLineNeeded (119..149) (116..149)
[/template] (61..160) (0..160)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[module myModule('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[ let p = myParam in p.name/]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[module myModule('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[ if myParam.name = '' then 'No name' else myParam.name endif/]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[module myModule('http://www.eclipse.org/emf/2002/Ecore')/]

[template public myTemplate(myParam : ecore::EPackage)]
[ let p = myParam in p.name/]
[/template]

0 comments on commit cdb7b31

Please sign in to comment.