Skip to content

Commit

Permalink
Fixed #131 Fix the quick fix adding a template/query for collection c…
Browse files Browse the repository at this point in the history
…alls.
  • Loading branch information
ylussaud committed Feb 14, 2024
1 parent 569510f commit 27a6022
Show file tree
Hide file tree
Showing 29 changed files with 250 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.StringJoiner;
Expand Down Expand Up @@ -46,6 +48,7 @@
import org.eclipse.acceleo.query.AQLUtils;
import org.eclipse.acceleo.query.ast.ASTNode;
import org.eclipse.acceleo.query.ast.Call;
import org.eclipse.acceleo.query.ast.CallType;
import org.eclipse.acceleo.query.ast.EClassifierTypeLiteral;
import org.eclipse.acceleo.query.ast.EnumLiteral;
import org.eclipse.acceleo.query.ast.ErrorCall;
Expand All @@ -66,6 +69,7 @@
import org.eclipse.acceleo.query.validation.type.EClassifierType;
import org.eclipse.acceleo.query.validation.type.ICollectionType;
import org.eclipse.acceleo.query.validation.type.IType;
import org.eclipse.acceleo.query.validation.type.SetType;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;

Expand Down Expand Up @@ -312,13 +316,52 @@ public List<IAstQuickFix> caseCall(Call call) {
final List<IAstQuickFix> res = new ArrayList<>();

final IType returnType = new ClassType(queryEnvironment, String.class);
final List<Set<IType>> argumentTypes = new ArrayList<>();
for (Expression argument : call.getArguments()) {
argumentTypes.add(validationResult.getPossibleTypes(argument));
final List<Set<IType>> argumentTypes = getArgumentPossibleTypes(call);
final CombineIterator<IType> combineIt = new CombineIterator<>(argumentTypes);
while (combineIt.hasNext()) {
res.addAll(getAddServiceQuickFixes(call.getServiceName(), returnType, combineIt.next()));
}

return res;
}

/**
* Gets the argument possible {@link IType} for the given {@link Call}.
*
* @param call
* the {@link Call}
* @return the argument possible {@link IType} for the given {@link Call}
*/
private List<Set<IType>> getArgumentPossibleTypes(Call call) {
final List<Set<IType>> res = new ArrayList<>();

final Iterator<Expression> it = call.getArguments().iterator();
final Expression receiver = it.next();
final Set<IType> receiverPossibleTypes = validationResult.getPossibleTypes(receiver);
if (call.getType() == CallType.COLLECTIONCALL) {
final Set<IType> receiverCollectionTypes = new LinkedHashSet<>();
for (IType receiverPossibleType : receiverPossibleTypes) {
if (receiverPossibleType instanceof ICollectionType) {
receiverCollectionTypes.add(receiverPossibleType);
} else {
receiverCollectionTypes.add(new SetType(queryEnvironment, receiverPossibleType));
}
}
res.add(receiverCollectionTypes);
} else {
final Set<IType> receiverRawTypes = new LinkedHashSet<>();
for (IType receiverPossibleType : receiverPossibleTypes) {
if (receiverPossibleType instanceof ICollectionType) {
receiverRawTypes.add(((ICollectionType)receiverPossibleType).getCollectionType());
} else {
receiverRawTypes.add(receiverPossibleType);
}
}
res.add(receiverRawTypes);
}
final CombineIterator<IType> it = new CombineIterator<>(argumentTypes);
while (it.hasNext()) {
res.addAll(getAddServiceQuickFixes(call.getServiceName(), returnType, it.next()));
final Expression argument = it.next();
res.add(validationResult.getPossibleTypes(argument));
}

return res;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated from import.t11(EClass)

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

[query private t41(param1 : OrederedSet(ecore::EObject)) : String = 'generated from imported.t41(EClass)'/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

header position 0..75
module importmoduleQueryPrivate
metamodel http://www.eclipse.org/emf/2002/Ecore (34..72)
imports resolution::importmoduleQueryCollectionReceiverPrivate::imported (87..151) (79..153)
[comment @main (166..172) /] (157..174)

public template t11(param1 : EClass (197..219))
@main
[file url .add(.aqlFeatureAccess(param1, 'name'), '.txt') (232..252) mode overwrite
generated from import.t11(EClass) (newLineNeeded) (271..306)
[->t41(param1) (311..324)/] (newLineNeeded (310..328) (265..330)
[/file] (225..337)
(newLineNeeded) (337..339) (221..339)
[/template] (176..350) (0..352)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@moduleElements.1/@body/@statements.0/@body/@statements.1/@expression/@aql
Add template t41(Set(EClassifier=EClass)) to this module
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionCallPrivate/importmoduleQueryCollectionCallPrivate.mtl [352, 11, 0, 352, 11, 0]
[template public t41(parameter0 : OrderedSet(ecore::EClass))]
[/template]
Add template t41(Set(EClassifier=EClass)) to resolution::importmoduleQueryCollectionReceiverPrivate::imported
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionReceiverPrivate/imported.mtl [155, 2, 94, 155, 2, 94]

[template public t41(parameter0 : OrderedSet(ecore::EClass))]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(null 0 2) null[]
(org.eclipse.acceleo.aql 0 2) AQL evaluation issue[org.eclipse.acceleo.impl.ExpressionImpl@00000000 (ast: org.eclipse.acceleo.query.parser.AstResult@00000000 [(param1, org.eclipse.emf.ecore.impl.EClassImpl@00000000 (name: World) (instanceClassName: null) (abstract: false, interface: false)), ]]
(org.eclipse.acceleo.query 0 2) Couldn't find the 't41(java.util.LinkedHashSet)' service[null]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR Couldn't find the 't41(Set(EClassifier=EClass))' service - 317 324
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

header position 0..75
module importmoduleQueryPrivate
metamodel http://www.eclipse.org/emf/2002/Ecore (34..72)
imports resolution::importmoduleQueryCollectionReceiverPrivate::imported (85..149) (77..151)
[comment @main (162..168) /] (153..170)

public template t11(param1 : EClass (192..214))
@main
[file url .add(.aqlFeatureAccess(param1, 'name'), '.txt') (226..246) mode overwrite
generated from import.t11(EClass) (newLineNeeded) (264..298)
[->t41(param1) (303..316)/] (newLineNeeded (302..319) (259..321)
[/file] (219..328)
(newLineNeeded) (328..329) (216..329)
[/template] (171..340) (0..341)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@moduleElements.1/@body/@statements.0/@body/@statements.1/@expression/@aql
Add template t41(Set(EClassifier=EClass)) to this module
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionCallPrivate/importmoduleQueryCollectionCallPrivate.mtl [341, 11, 0, 341, 11, 0]
[template public t41(parameter0 : OrderedSet(ecore::EClass))]
[/template]
Add template t41(Set(EClassifier=EClass)) to resolution::importmoduleQueryCollectionReceiverPrivate::imported
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionReceiverPrivate/imported.mtl [155, 2, 94, 155, 2, 94]

[template public t41(parameter0 : OrderedSet(ecore::EClass))]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(null 0 2) null[]
(org.eclipse.acceleo.aql 0 2) AQL evaluation issue[org.eclipse.acceleo.impl.ExpressionImpl@00000000 (ast: org.eclipse.acceleo.query.parser.AstResult@00000000 [(param1, org.eclipse.emf.ecore.impl.EClassImpl@00000000 (name: World) (instanceClassName: null) (abstract: false, interface: false)), ]]
(org.eclipse.acceleo.query 0 2) Couldn't find the 't41(java.util.LinkedHashSet)' service[null]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR Couldn't find the 't41(Set(EClassifier=EClass))' service - 309 316
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[module importmoduleQueryPrivate('http://www.eclipse.org/emf/2002/Ecore')/]

[import resolution::importmoduleQueryCollectionReceiverPrivate::imported/]

[comment @main /]
[template public t11(param1 : ecore::EClass)]
[file (param1.name + '.txt', overwrite)]
generated from import.t11(EClass)
[param1->t41()/]
[/file]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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"/>
</ecore:EPackage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated from import.t11(EClass)

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

[query private t41(param1 : ecore::EObject) : String = 'generated from imported.t41(EClass)'/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

header position 0..75
module importmoduleQueryPrivate
metamodel http://www.eclipse.org/emf/2002/Ecore (34..72)
imports resolution::importmoduleQueryCollectionReceiverPrivate::imported (87..151) (79..153)
[comment @main (166..172) /] (157..174)

public template t11(param1 : EClass (197..219))
@main
[file url .add(.aqlFeatureAccess(param1, 'name'), '.txt') (232..252) mode overwrite
generated from import.t11(EClass) (newLineNeeded) (271..306)
[.t41(Sequence{param1, }) (311..333)/] (newLineNeeded (310..337) (265..339)
[/file] (225..346)
(newLineNeeded) (346..348) (221..348)
[/template] (176..359) (0..361)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@moduleElements.1/@body/@statements.0/@body/@statements.1/@expression/@aql
Add template t41(EClassifier=EClass) to this module
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionReceiverPrivate/importmoduleQueryCollectionReceiverPrivate.mtl [361, 11, 0, 361, 11, 0]
[template public t41(parameter0 : ecore::EClass)]
[/template]
Add template t41(EClassifier=EClass) to resolution::importmoduleQueryCollectionReceiverPrivate::imported
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionReceiverPrivate/imported.mtl [155, 2, 94, 155, 2, 94]

[template public t41(parameter0 : ecore::EClass)]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(null 0 2) null[]
(org.eclipse.acceleo.aql 0 2) AQL evaluation issue[org.eclipse.acceleo.impl.ExpressionImpl@00000000 (ast: org.eclipse.acceleo.query.parser.AstResult@00000000 [(param1, org.eclipse.emf.ecore.impl.EClassImpl@00000000 (name: World) (instanceClassName: null) (abstract: false, interface: false)), ]]
(org.eclipse.acceleo.query 0 2) Couldn't find the 't41(EClassifier=EClass)' service[null]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR Couldn't find the 't41(EClassifier=EClass)' service - 327 333
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

header position 0..75
module importmoduleQueryPrivate
metamodel http://www.eclipse.org/emf/2002/Ecore (34..72)
imports resolution::importmoduleQueryCollectionReceiverPrivate::imported (85..149) (77..151)
[comment @main (162..168) /] (153..170)

public template t11(param1 : EClass (192..214))
@main
[file url .add(.aqlFeatureAccess(param1, 'name'), '.txt') (226..246) mode overwrite
generated from import.t11(EClass) (newLineNeeded) (264..298)
[.t41(Sequence{param1, }) (303..325)/] (newLineNeeded (302..328) (259..330)
[/file] (219..337)
(newLineNeeded) (337..338) (216..338)
[/template] (171..349) (0..350)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@moduleElements.1/@body/@statements.0/@body/@statements.1/@expression/@aql
Add template t41(EClassifier=EClass) to this module
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionReceiverPrivate/importmoduleQueryCollectionReceiverPrivate.mtl [350, 11, 0, 350, 11, 0]
[template public t41(parameter0 : ecore::EClass)]
[/template]
Add template t41(EClassifier=EClass) to resolution::importmoduleQueryCollectionReceiverPrivate::imported
Replace file:/home/development/git/acceleo/tests/org.eclipse.acceleo.aql.tests/resources/resolution/importmoduleQueryCollectionReceiverPrivate/imported.mtl [155, 2, 94, 155, 2, 94]

[template public t41(parameter0 : ecore::EClass)]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(null 0 2) null[]
(org.eclipse.acceleo.aql 0 2) AQL evaluation issue[org.eclipse.acceleo.impl.ExpressionImpl@00000000 (ast: org.eclipse.acceleo.query.parser.AstResult@00000000 [(param1, org.eclipse.emf.ecore.impl.EClassImpl@00000000 (name: World) (instanceClassName: null) (abstract: false, interface: false)), ]]
(org.eclipse.acceleo.query 0 2) Couldn't find the 't41(EClassifier=EClass)' service[null]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR Couldn't find the 't41(EClassifier=EClass)' service - 319 325
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[module importmoduleQueryPrivate('http://www.eclipse.org/emf/2002/Ecore')/]

[import resolution::importmoduleQueryCollectionReceiverPrivate::imported/]

[comment @main /]
[template public t11(param1 : ecore::EClass)]
[file (param1.name + '.txt', overwrite)]
generated from import.t11(EClass)
[Sequence{param1}.t41()/]
[/file]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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"/>
</ecore:EPackage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[module imported('http://www.eclipse.org/emf/2002/Ecore')/]

[query private t41(param1 : null::null) : ecore::EObject = /]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[module importmoduleQueryPrivate('http://www.eclipse.org/emf/2002/Ecore')/]

[import resolution::importmoduleQueryCollectionReceiverPrivate::imported/]

[comment @main /]
[template public t11(param1 : ecore::EClass)]
[file (param1.name + '.txt', overwrite)]
generated from import.t11(EClass)
[param1->t41()/]
[/file]
[/template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[module imported('http://www.eclipse.org/emf/2002/Ecore')/]

[query private t41(param1 : ecore::EObject) : String = 'generated from imported.t41(EClass)'/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[module importmoduleQueryPrivate('http://www.eclipse.org/emf/2002/Ecore')/]

[import resolution::importmoduleQueryCollectionReceiverPrivate::imported/]

[comment @main /]
[template public t11(param1 : ecore::EClass)]
[file (param1.name + '.txt', overwrite)]
generated from import.t11(EClass)
[Sequence{param1}.t41()/]
[/file]
[/template]

0 comments on commit 27a6022

Please sign in to comment.