Skip to content

Commit

Permalink
Improved type parameter and query return type completion.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Feb 22, 2024
1 parent 83d9b18 commit b711a15
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.acceleo.Module;
import org.eclipse.acceleo.Query;
import org.eclipse.acceleo.Template;
import org.eclipse.acceleo.TypedElement;
import org.eclipse.acceleo.Variable;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposal;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposalsProvider;
Expand Down Expand Up @@ -76,6 +77,7 @@
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.validation.type.ClassType;
import org.eclipse.acceleo.query.validation.type.IType;
import org.eclipse.acceleo.query.validation.type.NothingType;
import org.eclipse.acceleo.util.AcceleoSwitch;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
Expand Down Expand Up @@ -454,8 +456,22 @@ public List<AcceleoCompletionProposal> caseErrorTemplate(ErrorTemplate errorTemp
res.add(new AcceleoCodeTemplateCompletionProposal(sampleParameterName, sampleParameterName,
AcceleoPackage.Literals.TEMPLATE));
} else if (errorTemplate.getMissingCloseParenthesis() != -1) {
res.add(AcceleoSyntacticCompletionProposals.CLOSE_PARENTHESIS);
res.add(AcceleoSyntacticCompletionProposals.COMMA_SPACE);
if (!errorTemplate.getParameters().isEmpty()) {
final Variable parameter = errorTemplate.getParameters().get(errorTemplate.getParameters()
.size() - 1);
final Set<IType> types = getPossibleTypes(parameter);
if (types.stream().filter(t -> !(t instanceof NothingType)).collect(Collectors.toList())
.isEmpty()) {
res.addAll(this.getAqlCompletionProposals(Collections.emptyMap(), acceleoValidationResult
.getValidationResult(parameter.getType())));
} else {
res.add(AcceleoSyntacticCompletionProposals.CLOSE_PARENTHESIS);
res.add(AcceleoSyntacticCompletionProposals.COMMA_SPACE);
}
} else {
res.add(AcceleoSyntacticCompletionProposals.CLOSE_PARENTHESIS);
res.add(AcceleoSyntacticCompletionProposals.COMMA_SPACE);
}
} else if (errorTemplate.getMissingGuardOpenParenthesis() != -1) {
res.add(AcceleoSyntacticCompletionProposals.OPEN_PARENTHESIS);
} else if (errorTemplate.getGuard() != null && errorTemplate.getGuard().getAst()
Expand Down Expand Up @@ -535,8 +551,22 @@ public List<AcceleoCompletionProposal> caseErrorQuery(ErrorQuery errorQuery) {
res.add(new AcceleoCodeTemplateCompletionProposal(sampleParameterName, sampleParameterName,
AcceleoPackage.Literals.TEMPLATE));
} else if (errorQuery.getMissingCloseParenthesis() != -1) {
res.add(AcceleoSyntacticCompletionProposals.CLOSE_PARENTHESIS);
res.add(AcceleoSyntacticCompletionProposals.COMMA_SPACE);
if (!errorQuery.getParameters().isEmpty()) {
final Variable parameter = errorQuery.getParameters().get(errorQuery.getParameters().size()
- 1);
final Set<IType> types = getPossibleTypes(parameter);
if (types.stream().filter(t -> !(t instanceof NothingType)).collect(Collectors.toList())
.isEmpty()) {
res.addAll(this.getAqlCompletionProposals(Collections.emptyMap(), acceleoValidationResult
.getValidationResult(parameter.getType())));
} else {
res.add(AcceleoSyntacticCompletionProposals.CLOSE_PARENTHESIS);
res.add(AcceleoSyntacticCompletionProposals.COMMA_SPACE);
}
} else {
res.add(AcceleoSyntacticCompletionProposals.CLOSE_PARENTHESIS);
res.add(AcceleoSyntacticCompletionProposals.COMMA_SPACE);
}
} else if (errorQuery.getMissingColon() != -1) {
res.add(AcceleoSyntacticCompletionProposals.COLON_SPACE);
} else if (errorQuery.getMissingType() != -1) {
Expand All @@ -545,7 +575,14 @@ public List<AcceleoCompletionProposal> caseErrorQuery(ErrorQuery errorQuery) {
res.addAll(astCompletor.getProposals(Collections.emptySet(), typeValidation).stream().map(
AcceleoAstCompletor::transform).collect(Collectors.toList()));
} else if (errorQuery.getMissingEqual() != -1) {
res.add(AcceleoSyntacticCompletionProposals.EQUAL_SPACE);
final Set<IType> types = getPossibleTypes(errorQuery);
if (types.stream().filter(t -> !(t instanceof NothingType)).collect(Collectors.toList())
.isEmpty()) {
res.addAll(this.getAqlCompletionProposals(Collections.emptyMap(), acceleoValidationResult
.getValidationResult(errorQuery.getType())));
} else {
res.add(AcceleoSyntacticCompletionProposals.EQUAL_SPACE);
}
} else if (errorQuery.getBody().getAst().getAst() instanceof org.eclipse.acceleo.query.ast.Error) {
res.addAll(this.getAqlCompletionProposals(getVariables(errorQuery), acceleoValidationResult
.getValidationResult(errorQuery.getBody().getAst())));
Expand All @@ -572,6 +609,9 @@ public List<AcceleoCompletionProposal> caseErrorVariable(ErrorVariable errorVari
.getType());
res.addAll(astCompletor.getProposals(Collections.emptySet(), typeValidation).stream().map(
AcceleoAstCompletor::transform).collect(Collectors.toList()));
} else {
res.addAll(this.getAqlCompletionProposals(Collections.emptyMap(), acceleoValidationResult
.getValidationResult(errorVariable.getType())));
}

return res;
Expand Down Expand Up @@ -638,13 +678,13 @@ private Map<String, Set<IType>> getVariables(AcceleoASTNode scope) {
}

/**
* Gets the {@link Set} of possible {@link IType} for the given {@link Variable}.
* Gets the {@link Set} of possible {@link IType} for the given {@link TypedElement}.
*
* @param variable
* the {@link Variable}
* @return the {@link Set} of possible {@link IType} for the given {@link Variable}
* @return the {@link Set} of possible {@link IType} for the given {@link TypedElement}
*/
private LinkedHashSet<IType> getPossibleTypes(Variable variable) {
private LinkedHashSet<IType> getPossibleTypes(TypedElement variable) {
final LinkedHashSet<IType> res = new LinkedHashSet<IType>();

final IValidationResult validationResult = acceleoValidationResult.getValidationResult(variable
Expand Down Expand Up @@ -672,7 +712,7 @@ private Set<IType> getPossibleTypes(Binding binding) {
res = new LinkedHashSet<IType>();
res.addAll(validationResult.getPossibleTypes(binding.getInitExpression().getAst().getAst()));
} else {
res = getPossibleTypes((Variable)binding);
res = getPossibleTypes((TypedElement)binding);
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,8 @@ protected Variable parseVariable() {
}

if (missingName == -1) {
if (missingType != -1 || missingColon != -1) {
if (missingType != -1 || missingColon != -1 || type
.getAst() instanceof org.eclipse.acceleo.query.ast.Error) {
res = AcceleoPackage.eINSTANCE.getAcceleoFactory().createErrorVariable();
((ErrorVariable)res).setMissingName(missingName);
((ErrorVariable)res).setMissingColon(missingColon);
Expand Down

0 comments on commit b711a15

Please sign in to comment.