Removed IAcceleoEnvironment.
Change-Id: I4e63ea7ef1c7c60d0d2a30eb2cb132fe3b35bfbd
diff --git a/plugins/org.eclipse.acceleo.aql.launcher/src/org/eclipse/acceleo/aql/launcher/AcceleoLauncher.java b/plugins/org.eclipse.acceleo.aql.launcher/src/org/eclipse/acceleo/aql/launcher/AcceleoLauncher.java
index 60939ab..b89d2c0 100644
--- a/plugins/org.eclipse.acceleo.aql.launcher/src/org/eclipse/acceleo/aql/launcher/AcceleoLauncher.java
+++ b/plugins/org.eclipse.acceleo.aql.launcher/src/org/eclipse/acceleo/aql/launcher/AcceleoLauncher.java
@@ -17,17 +17,15 @@
import java.util.Set;
import org.eclipse.acceleo.Module;
-import org.eclipse.acceleo.aql.AcceleoEnvironment;
import org.eclipse.acceleo.aql.AcceleoUtil;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.evaluation.AcceleoEvaluator;
import org.eclipse.acceleo.aql.evaluation.GenerationResult;
import org.eclipse.acceleo.aql.parser.AcceleoParser;
import org.eclipse.acceleo.aql.parser.ModuleLoader;
import org.eclipse.acceleo.query.ide.QueryPlugin;
import org.eclipse.acceleo.query.ide.runtime.impl.namespace.OSGiQualifiedNameResolver;
-import org.eclipse.acceleo.query.runtime.impl.namespace.QualifiedNameQueryEnvironment;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
+import org.eclipse.acceleo.query.runtime.Query;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.Diagnostic;
@@ -216,11 +214,10 @@
IQualifiedNameResolver resolver = new OSGiQualifiedNameResolver(bundle,
AcceleoParser.QUALIFIER_SEPARATOR);
- final QualifiedNameQueryEnvironment queryEnvironment = new QualifiedNameQueryEnvironment(resolver);
- // TODO generation strategy should be configurable
- IAcceleoEnvironment acceleoEnvironment = new AcceleoEnvironment(queryEnvironment);
- AcceleoEvaluator evaluator = new AcceleoEvaluator(acceleoEnvironment, queryEnvironment
- .getLookupEngine());
+ /* FIXME we need a cross reference provider, and we need to make it configurable */
+ final IQualifiedNameQueryEnvironment queryEnvironment = Query
+ .newQualifiedNameEnvironmentWithDefaultServices(resolver, null, null);
+ AcceleoEvaluator evaluator = new AcceleoEvaluator(queryEnvironment.getLookupEngine());
resolver.addLoader(new ModuleLoader(new AcceleoParser(), evaluator));
resolver.addLoader(QueryPlugin.getPlugin().createJavaLoader(AcceleoParser.QUALIFIER_SEPARATOR));
@@ -232,14 +229,14 @@
} else {
mainModule = null;
}
- evaluate(evaluator, acceleoEnvironment, queryEnvironment.getLookupEngine(), mainModule,
- modelResourceSet);
- return acceleoEnvironment.getGenerationResult();
+ evaluate(evaluator, queryEnvironment, mainModule, modelResourceSet);
+ return evaluator.getGenerationResult();
}
- private void evaluate(AcceleoEvaluator evaluator, IAcceleoEnvironment environment,
- IQualifiedNameLookupEngine lookupEngine, Module mainModule, ResourceSet modelResourceSet) {
- AcceleoUtil.generate(evaluator, environment, mainModule, modelResourceSet, URI.createURI(target));
+ private void evaluate(AcceleoEvaluator evaluator, IQualifiedNameQueryEnvironment queryEnvironment,
+ Module mainModule, ResourceSet modelResourceSet) {
+ AcceleoUtil.generate(evaluator, queryEnvironment, mainModule, modelResourceSet, URI.createURI(
+ target));
}
private void printDiagnostic(PrintStream stream, Diagnostic diagnostic, String indentation) {
diff --git a/plugins/org.eclipse.acceleo.aql.ls.debug/src/org/eclipse/acceleo/aql/ls/debug/AcceleoDebugger.java b/plugins/org.eclipse.acceleo.aql.ls.debug/src/org/eclipse/acceleo/aql/ls/debug/AcceleoDebugger.java
index 4f04a64..fdf2b3a 100644
--- a/plugins/org.eclipse.acceleo.aql.ls.debug/src/org/eclipse/acceleo/aql/ls/debug/AcceleoDebugger.java
+++ b/plugins/org.eclipse.acceleo.aql.ls.debug/src/org/eclipse/acceleo/aql/ls/debug/AcceleoDebugger.java
@@ -26,9 +26,7 @@
import org.eclipse.acceleo.Query;
import org.eclipse.acceleo.Statement;
import org.eclipse.acceleo.Template;
-import org.eclipse.acceleo.aql.AcceleoEnvironment;
import org.eclipse.acceleo.aql.AcceleoUtil;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.evaluation.AcceleoEvaluator;
import org.eclipse.acceleo.aql.ide.AcceleoPlugin;
import org.eclipse.acceleo.aql.parser.AcceleoAstResult;
@@ -40,8 +38,6 @@
import org.eclipse.acceleo.debug.util.StackFrame;
import org.eclipse.acceleo.query.ast.VariableDeclaration;
import org.eclipse.acceleo.query.ide.QueryPlugin;
-import org.eclipse.acceleo.query.runtime.impl.namespace.QualifiedNameQueryEnvironment;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
import org.eclipse.core.resources.IContainer;
@@ -78,19 +74,17 @@
spawnRunningThread(threadID, Thread.currentThread().getName(), module);
try {
if (isNoDebug()) {
- generateNoDebug(environment, module, model);
+ generateNoDebug(queryEnvironment, module, model);
} else {
- evaluator = new AcceleoDebugEvaluator(environment, environment.getQueryEnvironment()
- .getLookupEngine());
+ evaluator = new AcceleoDebugEvaluator(queryEnvironment);
- final IQualifiedNameResolver resolver = environment.getQueryEnvironment()
- .getLookupEngine().getResolver();
+ final IQualifiedNameResolver resolver = queryEnvironment.getLookupEngine().getResolver();
resolver.clearLoaders();
resolver.addLoader(new ModuleLoader(new AcceleoParser(), evaluator));
resolver.addLoader(QueryPlugin.getPlugin().createJavaLoader(
AcceleoParser.QUALIFIER_SEPARATOR));
- AcceleoUtil.generate(evaluator, environment, module, model, getDestination());
+ AcceleoUtil.generate(evaluator, queryEnvironment, module, model, getDestination());
}
} finally {
// FIXME workaround: UI jobs are coming from core.debug even if the gen has finished,
@@ -133,13 +127,11 @@
/**
* Constructor.
*
- * @param environment
- * the {@link IllegalAccessError}
- * @param lookupEngine
- * the {@link IQualifiedNameLookupEngine}
+ * @param queryEnvironment
+ * the {@link IQualifiedNameQueryEnvironment}
*/
- AcceleoDebugEvaluator(IAcceleoEnvironment environment, IQualifiedNameLookupEngine lookupEngine) {
- super(environment, lookupEngine);
+ AcceleoDebugEvaluator(IQualifiedNameQueryEnvironment queryEnvironment) {
+ super(queryEnvironment.getLookupEngine());
}
@Override
@@ -185,9 +177,9 @@
public static final String DESTINATION = "destination";
/**
- * The {@link IAcceleoEnvironment}.
+ * The {@link IQualifiedNameQueryEnvironment}.
*/
- private IAcceleoEnvironment environment;
+ private IQualifiedNameQueryEnvironment queryEnvironment;
/**
* The destination {@link URI}.
@@ -232,8 +224,9 @@
final IQualifiedNameResolver resolver = QueryPlugin.getPlugin().createQualifiedNameResolver(
AcceleoPlugin.getPlugin().getClass().getClassLoader(), project,
AcceleoParser.QUALIFIER_SEPARATOR);
- final IQualifiedNameQueryEnvironment queryEnvironment = new QualifiedNameQueryEnvironment(resolver);
- environment = new AcceleoEnvironment(queryEnvironment);
+ /* FIXME we need a cross reference provider, and we need to make it configurable */
+ queryEnvironment = org.eclipse.acceleo.query.runtime.Query
+ .newQualifiedNameEnvironmentWithDefaultServices(resolver, null, null);
for (String nsURI : new ArrayList<String>(EPackage.Registry.INSTANCE.keySet())) {
registerEPackage(queryEnvironment, EPackage.Registry.INSTANCE.getEPackage(nsURI));
}
@@ -259,15 +252,15 @@
/**
* Registers the given {@link EPackage} in the given {@link IQualifiedNameQueryEnvironment} recursively.
*
- * @param queryEnvironment
+ * @param environment
* the {@link IQualifiedNameQueryEnvironment}
* @param ePackage
* the {@link EPackage}
*/
- private void registerEPackage(IQualifiedNameQueryEnvironment queryEnvironment, EPackage ePackage) {
- queryEnvironment.registerEPackage(ePackage);
+ private void registerEPackage(IQualifiedNameQueryEnvironment environment, EPackage ePackage) {
+ environment.registerEPackage(ePackage);
for (EPackage child : ePackage.getESubpackages()) {
- registerEPackage(queryEnvironment, child);
+ registerEPackage(environment, child);
}
}
@@ -308,23 +301,22 @@
/**
* Generates without debug.
*
- * @param env
- * the {@link IAcceleoEnvironment}
+ * @param environment
+ * the {@link IQualifiedNameQueryEnvironment}
* @param module
* the {@link Module} to generate
* @param modelResource
* the model {@link Resource}
*/
- protected void generateNoDebug(IAcceleoEnvironment env, Module module, Resource modelResource) {
- final AcceleoEvaluator noDebugEvaluator = new AcceleoEvaluator(env, env.getQueryEnvironment()
- .getLookupEngine());
- final IQualifiedNameResolver resolver = environment.getQueryEnvironment().getLookupEngine()
- .getResolver();
+ protected void generateNoDebug(IQualifiedNameQueryEnvironment environment, Module module,
+ Resource modelResource) {
+ final AcceleoEvaluator noDebugEvaluator = new AcceleoEvaluator(environment.getLookupEngine());
+ final IQualifiedNameResolver resolver = environment.getLookupEngine().getResolver();
resolver.clearLoaders();
resolver.addLoader(new ModuleLoader(new AcceleoParser(), noDebugEvaluator));
resolver.addLoader(QueryPlugin.getPlugin().createJavaLoader(AcceleoParser.QUALIFIER_SEPARATOR));
- AcceleoUtil.generate(noDebugEvaluator, env, module, modelResource, getDestination());
+ AcceleoUtil.generate(noDebugEvaluator, environment, module, modelResource, getDestination());
}
@Override
@@ -360,8 +352,7 @@
public EObject getInstruction(String path, long line, long column) {
AcceleoAstResult moduleAstResult = null;
try {
- final IQualifiedNameResolver resolver = environment.getQueryEnvironment().getLookupEngine()
- .getResolver();
+ final IQualifiedNameResolver resolver = queryEnvironment.getLookupEngine().getResolver();
final String moduleQualifiedName = resolver.getQualifiedName(new URL("file://" + path));
if (moduleQualifiedName != null) {
final Object resolved = resolver.resolve(moduleQualifiedName);
@@ -411,8 +402,7 @@
Module module = getModule(instruction);
if (module != null) {
final AcceleoAstResult moduleAstResult = module.getAst();
- final IQualifiedNameResolver resolver = environment.getQueryEnvironment().getLookupEngine()
- .getResolver();
+ final IQualifiedNameResolver resolver = queryEnvironment.getLookupEngine().getResolver();
final String moduleQualifiedName = resolver.getQualifiedName(moduleAstResult.getModule());
URL moduleSourceURL = resolver.getSourceURL(moduleQualifiedName);
try {
diff --git a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoLocationLinkResolver.java b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoLocationLinkResolver.java
index 65e68bc..a32f651 100644
--- a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoLocationLinkResolver.java
+++ b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoLocationLinkResolver.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -343,8 +343,8 @@
// open source file whenever it's possible
java.net.URI targetDocumentUri;
try {
- final IQualifiedNameResolver resolver = destinationTextDocument.getAcceleoEnvironment()
- .getQueryEnvironment().getLookupEngine().getResolver();
+ final IQualifiedNameResolver resolver = destinationTextDocument.getQueryEnvironment()
+ .getLookupEngine().getResolver();
targetDocumentUri = resolver.getSourceURL(qualifiedName).toURI();
} catch (
diff --git a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocument.java b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocument.java
index ea4d278..5628070 100644
--- a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocument.java
+++ b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocument.java
@@ -19,8 +19,6 @@
import org.eclipse.acceleo.Metamodel;
import org.eclipse.acceleo.Module;
import org.eclipse.acceleo.ModuleElement;
-import org.eclipse.acceleo.aql.AcceleoEnvironment;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.location.AcceleoLocator;
import org.eclipse.acceleo.aql.location.common.AbstractLocationLink;
import org.eclipse.acceleo.aql.ls.AcceleoLanguageServer;
@@ -30,7 +28,7 @@
import org.eclipse.acceleo.aql.parser.AcceleoParser;
import org.eclipse.acceleo.aql.validation.AcceleoValidator;
import org.eclipse.acceleo.aql.validation.IAcceleoValidationResult;
-import org.eclipse.acceleo.query.runtime.impl.namespace.QualifiedNameQueryEnvironment;
+import org.eclipse.acceleo.query.runtime.Query;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
@@ -62,9 +60,9 @@
private AcceleoProject ownerProject;
/**
- * The {@link IAcceleoEnvironment} for this text document.
+ * The {@link IQualifiedNameQueryEnvironment} for this text document.
*/
- private IAcceleoEnvironment acceleoEnvironment;
+ private IQualifiedNameQueryEnvironment queryEnvironment;
/**
* The {@link String} contents of the text document.
@@ -121,7 +119,7 @@
// TODO: we probably only want to send this notification out when the "publicly-accessible" parts of
// the Module have changed, like a public/protected Template/Query signature.
if (this.getProject() != null) {
- // This text document belongs to an AcceleoProject which holds the AcceleoEnvironment in which
+ // This text document belongs to an AcceleoProject which holds the resolver in which
// this module is registered.
this.getProject().documentSaved(this);
}
@@ -176,9 +174,9 @@
AcceleoAstResult parsingResult = null;
parsingResult = doParsing(this.getModuleQualifiedName(), this.contents);
- final IQualifiedNameQueryEnvironment queryEnvironment = new QualifiedNameQueryEnvironment(getProject()
- .getResolver());
- acceleoEnvironment = new AcceleoEnvironment(queryEnvironment);
+ /* FIXME we need a cross reference provider, and we need to make it configurable */
+ queryEnvironment = Query.newQualifiedNameEnvironmentWithDefaultServices(getProject().getResolver(),
+ null, null);
for (Metamodel metamodel : parsingResult.getModule().getMetamodels()) {
if (metamodel.getReferencedPackage() != null) {
@@ -209,8 +207,8 @@
*/
public void validateContents() {
IAcceleoValidationResult validationResults = null;
- if (this.acceleoAstResult != null && this.getAcceleoEnvironment() != null) {
- validationResults = doValidation(this.acceleoAstResult, this.getAcceleoEnvironment());
+ if (this.acceleoAstResult != null && this.getQueryEnvironment() != null) {
+ validationResults = doValidation(this.acceleoAstResult, this.getQueryEnvironment());
}
this.acceleoValidationResult = validationResults;
}
@@ -221,17 +219,17 @@
*
* @param acceleoAstResult
* the (non-{@code null}) {@link AcceleoAstResult} to validate.
- * @param acceleoEnvironment
- * the (non-{@code null}) {@link IAcceleoEnvironment} of the document being validated.
+ * @param queryEnvironment
+ * the (non-{@code null}) {@link IQualifiedNameQueryEnvironment} of the document being
+ * validated.
* @return the {@link IAcceleoValidationResult}.
*/
private static IAcceleoValidationResult doValidation(AcceleoAstResult acceleoAstResult,
- IAcceleoEnvironment acceleoEnvironment) {
+ IQualifiedNameQueryEnvironment queryEnvironment) {
Objects.requireNonNull(acceleoAstResult);
- Objects.requireNonNull(acceleoEnvironment);
+ Objects.requireNonNull(queryEnvironment);
- return validate(acceleoEnvironment, new AcceleoValidator(acceleoEnvironment, acceleoEnvironment
- .getQueryEnvironment().getLookupEngine()), acceleoAstResult);
+ return validate(queryEnvironment, acceleoAstResult);
}
/**
@@ -281,10 +279,10 @@
/**
* Provides the qualified name of the Acceleo {@link Module} represented by this document, as computed by
- * the {@link AcceleoEnvironment}'s {@link IQualifiedNameResolver}.
+ * the {@link IQualifiedNameResolver}.
*
* @return the qualified name of the {@link Module}. {@code null} if this document has no
- * {@link IAcceleoEnvironment}.
+ * {@link IQualifiedNameResolver}.
*/
public String getModuleQualifiedName() {
if (getProject() == null) {
@@ -318,14 +316,12 @@
* the Acceleo element found at the given position in the source contents.
*/
public List<AbstractLocationLink<?, ?>> getDefinitionLocations(int position) {
- IAcceleoEnvironment env = getAcceleoEnvironment();
// FIXME we need any module element
ModuleElement moduleElement = acceleoAstResult.getModule().getModuleElements().get(0);
- final IQualifiedNameLookupEngine lookupEngine = env.getQueryEnvironment().getLookupEngine();
+ final IQualifiedNameLookupEngine lookupEngine = getQueryEnvironment().getLookupEngine();
lookupEngine.pushImportsContext(getModuleQualifiedName(), getModuleQualifiedName());
- List<AbstractLocationLink<?, ?>> definitionLocations = new AcceleoLocator(env, env
- .getQueryEnvironment().getLookupEngine()).getDefinitionLocations(this.acceleoAstResult,
- position);
+ List<AbstractLocationLink<?, ?>> definitionLocations = new AcceleoLocator(getQueryEnvironment())
+ .getDefinitionLocations(this.acceleoAstResult, position);
lookupEngine.popContext(getModuleQualifiedName());
return definitionLocations;
}
@@ -340,9 +336,8 @@
* of the Acceleo element found at the given position in the source contents.
*/
public List<AbstractLocationLink<?, ?>> getDeclarationLocations(int position) {
- return new AcceleoLocator(this.getAcceleoEnvironment(), this.getAcceleoEnvironment()
- .getQueryEnvironment().getLookupEngine()).getDeclarationLocations(this.acceleoAstResult,
- position);
+ return new AcceleoLocator(getQueryEnvironment()).getDeclarationLocations(this.acceleoAstResult,
+ position);
}
/**
@@ -403,13 +398,13 @@
}
/**
- * Provides the {@link IAcceleoEnvironment} associated to this text document.
+ * Provides the {@link IQualifiedNameQueryEnvironment} associated to this text document.
*
- * @return the (maybe-{@code null}) {@link IAcceleoEnvironment} associated to this
+ * @return the (maybe-{@code null}) {@link IQualifiedNameQueryEnvironment} associated to this
* {@link AcceleoTextDocument}.
*/
- public IAcceleoEnvironment getAcceleoEnvironment() {
- return acceleoEnvironment;
+ public IQualifiedNameQueryEnvironment getQueryEnvironment() {
+ return queryEnvironment;
}
/**
@@ -424,10 +419,8 @@
/**
* Performs the Acceleo validation.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) {@link IAcceleoEnvironment}.
- * @param acceleoValidator
- * the (non-{@code null}) {@link AcceleoValidator}.
+ * @param queryEnvironment
+ * the (non-{@code null}) {@link IQualifiedNameQueryEnvironment}.
* @param acceleoAstResult
* the (non-{@code null}) {@link AcceleoAstResult}.
* @return the {@link IAcceleoValidationResult}.
@@ -435,15 +428,15 @@
// FIXME the "synchronized" here is an ugly but convenient way to ensure that a validation finishes before
// any other is triggered. Otherwise a validation can push imports which invalidates the services lookup
// for another validation
- private static synchronized IAcceleoValidationResult validate(IAcceleoEnvironment acceleoEnvironment,
- AcceleoValidator acceleoValidator, AcceleoAstResult acceleoAstResult) {
+ private static synchronized IAcceleoValidationResult validate(
+ IQualifiedNameQueryEnvironment queryEnvironment, AcceleoAstResult acceleoAstResult) {
String moduleQualifiedNameForValidation = VALIDATION_NAMESPACE + AcceleoParser.QUALIFIER_SEPARATOR
+ acceleoAstResult.getModule().getName();
- final IQualifiedNameResolver resolver = acceleoEnvironment.getQueryEnvironment().getLookupEngine()
- .getResolver();
+ final IQualifiedNameResolver resolver = queryEnvironment.getLookupEngine().getResolver();
resolver.register(moduleQualifiedNameForValidation, acceleoAstResult.getModule());
- IAcceleoValidationResult validationResults = acceleoValidator.validate(acceleoAstResult,
+ final AcceleoValidator acceleoValidator = new AcceleoValidator(queryEnvironment);
+ final IAcceleoValidationResult validationResults = acceleoValidator.validate(acceleoAstResult,
moduleQualifiedNameForValidation);
return validationResults;
}
diff --git a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocumentService.java b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocumentService.java
index 0fe68b7..d552537 100644
--- a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocumentService.java
+++ b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/textdocument/AcceleoTextDocumentService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,7 +20,6 @@
import java.util.stream.Collectors;
import org.eclipse.acceleo.Module;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.completion.AcceleoCompletor;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposal;
import org.eclipse.acceleo.aql.location.common.AbstractLocationLink;
@@ -271,12 +270,11 @@
// Acceleo provides an API to access completion proposals.
final AcceleoCompletor acceleoCompletor = new AcceleoCompletor();
- IAcceleoEnvironment acceleoEnvironment = acceleoTextDocument.getAcceleoEnvironment();
String source = acceleoTextDocument.getContents();
int atIndex = AcceleoLanguageServerPositionUtils.getCorrespondingCharacterIndex(position, source);
List<AcceleoCompletionProposal> completionProposals = acceleoCompletor.getProposals(
- acceleoEnvironment, acceleoEnvironment.getQueryEnvironment().getLookupEngine(),
- acceleoTextDocument.getFileNameWithoutExtension(), source, atIndex);
+ acceleoTextDocument.getQueryEnvironment(), acceleoTextDocument
+ .getFileNameWithoutExtension(), source, atIndex);
canceler.checkCanceled();
List<CompletionItem> completionItems = AcceleoLanguageServerServicesUtils.transform(
diff --git a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/workspace/AcceleoProject.java b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/workspace/AcceleoProject.java
index 7d6527b..c7cc17f 100644
--- a/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/workspace/AcceleoProject.java
+++ b/plugins/org.eclipse.acceleo.aql.ls/src/org/eclipse/acceleo/aql/ls/services/workspace/AcceleoProject.java
@@ -21,17 +21,16 @@
import java.util.TreeMap;
import org.eclipse.acceleo.Import;
-import org.eclipse.acceleo.aql.AcceleoEnvironment;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.ls.AcceleoLanguageServer;
import org.eclipse.acceleo.aql.ls.services.textdocument.AcceleoTextDocument;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
/**
* A representation, in the {@link AcceleoLanguageServer} of a container of {@link AcceleoTextDocument
- * AcceleoTextDocuments} that share a same {@link IAcceleoEnvironment}. It may or may not correspond to a
- * physical element in the client.
+ * AcceleoTextDocuments} that share a same {@link IQualifiedNameQueryEnvironment}. It may or may not
+ * correspond to a physical element in the client.
*
* @author Florent Latombe
*/
@@ -204,16 +203,17 @@
}
/**
- * We receive this notification when an {@link AcceleoTextDocument} in our {@link AcceleoEnvironment} has
- * changed and saved. We want to re-validate any of our modules that depended on it.
+ * We receive this notification when an {@link AcceleoTextDocument} in our
+ * {@link IQualifiedNameQueryEnvironment} has changed and saved. We want to re-validate any of our modules
+ * that depended on it.
*
* @param savedTextDocument
* the (non-{@code null}) {@link AcceleoTextDocument} that was saved.
*/
public void documentSaved(AcceleoTextDocument savedTextDocument) {
final String qualifiedNameOfSavedModule = savedTextDocument.getModuleQualifiedName();
- final IQualifiedNameLookupEngine lookupEngine = savedTextDocument.getAcceleoEnvironment()
- .getQueryEnvironment().getLookupEngine();
+ final IQualifiedNameLookupEngine lookupEngine = savedTextDocument.getQueryEnvironment()
+ .getLookupEngine();
// First clear the environment for the document that was changed.
lookupEngine.clearContext(qualifiedNameOfSavedModule);
@@ -236,16 +236,16 @@
}
/**
- * We receive this notification when an {@link AcceleoTextDocument} in our {@link AcceleoEnvironment} has
- * been removed. We want to unregister any services it has contributed and re-parse and re-validate any of
- * our modules that depended on it.
+ * We receive this notification when an {@link AcceleoTextDocument} in our
+ * {@link IQualifiedNameQueryEnvironment} has been removed. We want to unregister any services it has
+ * contributed and re-parse and re-validate any of our modules that depended on it.
*
* @param removedTextDocument
* the (non-{@code null}) {@link AcceleoTextDocument} that has been removed.
*/
public void documentRemoved(AcceleoTextDocument removedTextDocument) {
- final IQualifiedNameLookupEngine lookupEngine = removedTextDocument.getAcceleoEnvironment()
- .getQueryEnvironment().getLookupEngine();
+ final IQualifiedNameLookupEngine lookupEngine = removedTextDocument.getQueryEnvironment()
+ .getLookupEngine();
// Since the qualified name of a module depends on its environment, we want the qualified name
// according to our environment.
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/AcceleoEnvironment.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/AcceleoEnvironment.java
deleted file mode 100644
index e6358f1..0000000
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/AcceleoEnvironment.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016, 2021 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.acceleo.aql;
-
-import org.eclipse.acceleo.aql.evaluation.GenerationResult;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
-
-/**
- * This environment will keep track of Acceleo's evaluation context. TODO doc.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
-public class AcceleoEnvironment implements IAcceleoEnvironment {
-
- /** The AQL environment that will be used to evaluate aql expressions from this Acceleo context. */
- private IQualifiedNameQueryEnvironment aqlEnvironment;
-
- /**
- * The {@link GenerationResult}.
- */
- private final GenerationResult generationResult = new GenerationResult();
-
- /**
- * Constructor.
- *
- * @param aqlEnvironment
- * the {@link IQualifiedNameQueryEnvironment}
- */
- public AcceleoEnvironment(IQualifiedNameQueryEnvironment aqlEnvironment) {
- this.aqlEnvironment = aqlEnvironment;
- /* FIXME we need a cross reference provider, and we need to make it configurable */
- org.eclipse.acceleo.query.runtime.Query.configureEnvironment(aqlEnvironment, null, null);
- }
-
- @Override
- public IQualifiedNameQueryEnvironment getQueryEnvironment() {
- return aqlEnvironment;
- }
-
- @Override
- public GenerationResult getGenerationResult() {
- return generationResult;
- }
-
-}
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/AcceleoUtil.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/AcceleoUtil.java
index 467d588..66fa601 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/AcceleoUtil.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/AcceleoUtil.java
@@ -26,6 +26,7 @@
import org.eclipse.acceleo.aql.evaluation.writer.DefaultGenerationStrategy;
import org.eclipse.acceleo.query.ast.EClassifierTypeLiteral;
import org.eclipse.acceleo.query.runtime.IQueryEnvironment;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.services.EObjectServices;
import org.eclipse.acceleo.util.AcceleoSwitch;
import org.eclipse.emf.common.util.URI;
@@ -90,8 +91,8 @@
*
* @param evaluator
* the {@link AcceleoEvaluator}
- * @param acceleoEnvironment
- * the {@link IAcceleoEnvironment}
+ * @param queryEnvironment
+ * the {@link IQualifiedNameQueryEnvironment}
* @param module
* the {@link Module}
* @param model
@@ -99,18 +100,18 @@
* @param destination
* destination {@link URI}
*/
- public static void generate(AcceleoEvaluator evaluator, IAcceleoEnvironment acceleoEnvironment,
+ public static void generate(AcceleoEvaluator evaluator, IQualifiedNameQueryEnvironment queryEnvironment,
Module module, Resource model, URI destination) {
- generate(evaluator, acceleoEnvironment, module, Collections.singletonList(model), destination);
+ generate(evaluator, queryEnvironment, module, Collections.singletonList(model), destination);
}
/**
- * Generates with the given {@link AcceleoEvaluator} and {@link IAcceleoEnvironment}.
+ * Generates with the given {@link AcceleoEvaluator} and {@link IQueryEnvironment}.
*
* @param evaluator
* the {@link AcceleoEvaluator}
- * @param acceleoEnvironment
- * the {@link IAcceleoEnvironment}
+ * @param queryEnvironment
+ * the {@link IQueryEnvironment}
* @param module
* the {@link Module}
* @param resourceSet
@@ -118,14 +119,13 @@
* @param destination
* the destination {@link URI}
*/
- public static void generate(AcceleoEvaluator evaluator, IAcceleoEnvironment acceleoEnvironment,
+ public static void generate(AcceleoEvaluator evaluator, IQualifiedNameQueryEnvironment queryEnvironment,
Module module, ResourceSet resourceSet, URI destination) {
- generate(evaluator, acceleoEnvironment, module, resourceSet.getResources(), destination);
+ generate(evaluator, queryEnvironment, module, resourceSet.getResources(), destination);
}
- private static void generate(AcceleoEvaluator evaluator, IAcceleoEnvironment acceleoEnvironment,
+ private static void generate(AcceleoEvaluator evaluator, IQualifiedNameQueryEnvironment queryEnvironment,
Module module, List<Resource> resources, URI destination) {
- final IQueryEnvironment queryEnvironment = acceleoEnvironment.getQueryEnvironment();
final EObjectServices services = new EObjectServices(queryEnvironment, null, null);
final Template main = getMainTemplate(module);
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/IAcceleoEnvironment.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/IAcceleoEnvironment.java
deleted file mode 100644
index 9426285..0000000
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/IAcceleoEnvironment.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2017, 2021 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.acceleo.aql;
-
-import org.eclipse.acceleo.aql.evaluation.GenerationResult;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
-
-/**
- * Acceleo environment.
- *
- * @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
- */
-public interface IAcceleoEnvironment {
-
- /**
- * Gets the {@link IQualifiedNameQueryEnvironment}.
- *
- * @return the {@link IQualifiedNameQueryEnvironment}
- */
- IQualifiedNameQueryEnvironment getQueryEnvironment();
-
- /**
- * Gets the {@link GenerationResult}.
- *
- * @return the {@link GenerationResult}
- */
- GenerationResult getGenerationResult();
-
-}
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoAstCompletor.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoAstCompletor.java
index 3d3920b..6ff0f34 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoAstCompletor.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoAstCompletor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -50,7 +50,6 @@
import org.eclipse.acceleo.Query;
import org.eclipse.acceleo.Template;
import org.eclipse.acceleo.Variable;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposal;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposalsProvider;
import org.eclipse.acceleo.aql.completion.proposals.syntax.AcceleoSyntacticCompletionProposals;
@@ -73,7 +72,7 @@
import org.eclipse.acceleo.query.runtime.impl.completion.EOperationServiceCompletionProposal;
import org.eclipse.acceleo.query.runtime.impl.completion.VariableCompletionProposal;
import org.eclipse.acceleo.query.runtime.impl.completion.VariableDeclarationCompletionProposal;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
+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.util.AcceleoSwitch;
@@ -86,7 +85,6 @@
*
* @author Florent Latombe
*/
-@SuppressWarnings("restriction")
public class AcceleoAstCompletor extends AcceleoSwitch<List<AcceleoCompletionProposal>> {
/**
@@ -161,9 +159,9 @@
private static final String SPACE = " ";
/**
- * The {@link IAcceleoEnvironment}.
+ * The {@link IQualifiedNameQueryEnvironment}.
*/
- private final IAcceleoEnvironment acceleoEnvironment;
+ private final IQualifiedNameQueryEnvironment queryEnvironment;
/**
* The {@link IAcceleoValidationResult}.
@@ -191,30 +189,21 @@
private String moduleSourceFragment;
/**
- * The {@link IQualifiedNameResolver}.
- */
- private final IQualifiedNameResolver resolver;
-
- /**
* Constructor.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) contextual {@link IAcceleoEnvironment}.
+ * @param queryEnvironment
+ * the (non-{@code null}) contextual {@link IQualifiedNameQueryEnvironment}.
* @param acceleoValidationResult
* the (non-{@code null}) contextual {@link IAcceleoValidationResult}.
- * @param resolver
- * the (non-{@code null}) contextual {@link IQualifiedNameResolver}.
*/
- public AcceleoAstCompletor(IAcceleoEnvironment acceleoEnvironment,
- IAcceleoValidationResult acceleoValidationResult, IQualifiedNameResolver resolver) {
- this.acceleoEnvironment = Objects.requireNonNull(acceleoEnvironment);
+ public AcceleoAstCompletor(IQualifiedNameQueryEnvironment queryEnvironment,
+ IAcceleoValidationResult acceleoValidationResult) {
+ this.queryEnvironment = Objects.requireNonNull(queryEnvironment);
this.acceleoValidationResult = Objects.requireNonNull(acceleoValidationResult);
- this.resolver = Objects.requireNonNull(resolver);
- this.astCompletor = new AstCompletor(new CompletionServices(this.acceleoEnvironment
- .getQueryEnvironment()));
- this.aqlCompletionEngine = new QueryCompletionEngine(this.acceleoEnvironment.getQueryEnvironment());
- this.acceleoCompletionProposalProvider = new AcceleoCompletionProposalsProvider(acceleoEnvironment);
+ this.astCompletor = new AstCompletor(new CompletionServices(this.queryEnvironment));
+ this.aqlCompletionEngine = new QueryCompletionEngine(queryEnvironment);
+ this.acceleoCompletionProposalProvider = new AcceleoCompletionProposalsProvider(queryEnvironment);
}
/**
@@ -372,8 +361,8 @@
ErrorModuleReference errorModuleReference) {
final List<AcceleoCompletionProposal> completionProposals = new ArrayList<AcceleoCompletionProposal>();
- final List<String> availableQualifiedNames = new ArrayList<String>(resolver
- .getAvailableQualifiedNames());
+ final List<String> availableQualifiedNames = new ArrayList<String>(queryEnvironment.getLookupEngine()
+ .getResolver().getAvailableQualifiedNames());
Collections.sort(availableQualifiedNames);
for (String qualifiedName : availableQualifiedNames) {
completionProposals.add(new AcceleoCodeTemplateCompletionProposal(qualifiedName, qualifiedName,
@@ -415,8 +404,8 @@
} else if (errorTemplate.getPost() != null && errorTemplate.getPost().getAst()
.getAst() instanceof org.eclipse.acceleo.query.ast.Error) {
final Map<String, Set<IType>> variables = new HashMap<String, Set<IType>>();
- final Set<IType> possibleTypes = Collections.singleton(new ClassType(acceleoEnvironment
- .getQueryEnvironment(), String.class));
+ final Set<IType> possibleTypes = Collections.singleton(new ClassType(queryEnvironment,
+ String.class));
variables.put("self", possibleTypes);
completionProposals.addAll(getAqlCompletionProposals(variables, acceleoValidationResult
.getValidationResult(errorTemplate.getPost().getAst())));
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoCompletor.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoCompletor.java
index 04db369..c9ab853 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoCompletor.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/AcceleoCompletor.java
@@ -18,14 +18,12 @@
import org.eclipse.acceleo.Error;
import org.eclipse.acceleo.Module;
import org.eclipse.acceleo.ModuleElement;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposal;
import org.eclipse.acceleo.aql.parser.AcceleoAstResult;
import org.eclipse.acceleo.aql.parser.AcceleoParser;
import org.eclipse.acceleo.aql.validation.AcceleoValidator;
import org.eclipse.acceleo.aql.validation.IAcceleoValidationResult;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.emf.ecore.EObject;
/**
@@ -44,10 +42,8 @@
* Provides the {@link List} of {@link AcceleoCompletionProposal completion proposals} available for the
* given Acceleo source at the given position in the given environment.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) contextual {@link IAcceleoEnvironment}.
- * @param lookupEngine
- * the {@link IQualifiedNameLookupEngine}
+ * @param queryEnvironment
+ * the {@link IQualifiedNameQueryEnvironment}
* @param moduleFileName
* the (non-{@code null}) name of the file containing the module (without extension).
* @param source
@@ -57,8 +53,8 @@
* @return the {@link List} of {@link AcceleoCompletionProposal} for the given source at the given
* position
*/
- public List<AcceleoCompletionProposal> getProposals(IAcceleoEnvironment acceleoEnvironment,
- IQualifiedNameLookupEngine lookupEngine, String moduleFileName, String source, int position) {
+ public List<AcceleoCompletionProposal> getProposals(IQualifiedNameQueryEnvironment queryEnvironment,
+ String moduleFileName, String source, int position) {
String moduleQualifiedNameForCompletion = TO_COMPLETION_NAMESPACE + AcceleoParser.QUALIFIER_SEPARATOR
+ moduleFileName;
@@ -71,26 +67,28 @@
// Second, validate the AST - this is required further on for the AQL completion.
final AcceleoAstResult acceleoAstResult = acceleoParser.parse(source,
moduleQualifiedNameForCompletion);
- lookupEngine.getResolver().register(moduleQualifiedNameForCompletion, acceleoAstResult.getModule());
+ queryEnvironment.getLookupEngine().getResolver().register(moduleQualifiedNameForCompletion,
+ acceleoAstResult.getModule());
final List<AcceleoCompletionProposal> proposals;
try {
- final AcceleoValidator acceleoValidator = new AcceleoValidator(acceleoEnvironment, lookupEngine);
+ final AcceleoValidator acceleoValidator = new AcceleoValidator(queryEnvironment);
IAcceleoValidationResult acceleoValidationResult = acceleoValidator.validate(
partialAcceleoAstResult, moduleQualifiedNameForCompletion);
// Find which element of the AST we are completing.
EObject acceleoElementToComplete = getElementToComplete(partialAcceleoAstResult);
- lookupEngine.pushImportsContext(moduleQualifiedNameForCompletion,
+ queryEnvironment.getLookupEngine().pushImportsContext(moduleQualifiedNameForCompletion,
moduleQualifiedNameForCompletion);
try {
- proposals = this.getProposals(acceleoEnvironment, lookupEngine.getResolver(),
- partialAcceleoSource, acceleoValidationResult, acceleoElementToComplete);
+ proposals = this.getProposals(queryEnvironment, partialAcceleoSource, acceleoValidationResult,
+ acceleoElementToComplete);
} finally {
- lookupEngine.popContext(moduleQualifiedNameForCompletion);
+ queryEnvironment.getLookupEngine().popContext(moduleQualifiedNameForCompletion);
}
} finally {
- lookupEngine.getResolver().clear(Collections.singleton(moduleQualifiedNameForCompletion));
- lookupEngine.clearContext(moduleQualifiedNameForCompletion);
+ queryEnvironment.getLookupEngine().getResolver().clear(Collections.singleton(
+ moduleQualifiedNameForCompletion));
+ queryEnvironment.getLookupEngine().clearContext(moduleQualifiedNameForCompletion);
}
return proposals;
@@ -123,10 +121,8 @@
* Provides the {@link List} of {@link AcceleoCompletionProposal completion proposals} for the given
* {@link EObject} of an Acceleo AST in the given environment.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) contextual {@link IAcceleoEnvironment}.
- * @param resolver
- * the (non-{@code null}) contextual {@link IQualifiedNameResolver}.
+ * @param queryEnvironment
+ * the (non-{@code null}) contextual {@link IQualifiedNameQueryEnvironment}.
* @param sourceFragment
* the module source fragment
* @param acceleoValidationResult
@@ -135,13 +131,13 @@
* the {@link EObject Acceleo AST element} to complete.
* @return the {@link List} of {@link AcceleoCompletionProposal}.
*/
- protected List<AcceleoCompletionProposal> getProposals(IAcceleoEnvironment acceleoEnvironment,
- IQualifiedNameResolver resolver, String sourceFragment,
- IAcceleoValidationResult acceleoValidationResult, EObject acceleoElementToComplete) {
+ protected List<AcceleoCompletionProposal> getProposals(IQualifiedNameQueryEnvironment queryEnvironment,
+ String sourceFragment, IAcceleoValidationResult acceleoValidationResult,
+ EObject acceleoElementToComplete) {
final List<AcceleoCompletionProposal> completionProposals = new ArrayList<>();
- AcceleoAstCompletor acceleoSyntaxCompletor = new AcceleoAstCompletor(acceleoEnvironment,
- acceleoValidationResult, resolver);
+ AcceleoAstCompletor acceleoSyntaxCompletor = new AcceleoAstCompletor(queryEnvironment,
+ acceleoValidationResult);
completionProposals.addAll(acceleoSyntaxCompletor.getCompletion(sourceFragment,
acceleoElementToComplete));
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/AcceleoCompletionProposalsProvider.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/AcceleoCompletionProposalsProvider.java
index d088774..b2f7f3f 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/AcceleoCompletionProposalsProvider.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/AcceleoCompletionProposalsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -33,11 +33,11 @@
import org.eclipse.acceleo.Query;
import org.eclipse.acceleo.Statement;
import org.eclipse.acceleo.Template;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.completion.proposals.syntax.AcceleoSyntacticCompletionProposals;
import org.eclipse.acceleo.aql.completion.proposals.templates.AcceleoCodeTemplateCompletionProposal;
import org.eclipse.acceleo.aql.completion.proposals.templates.AcceleoCodeTemplateCompletionProposalsProvider;
import org.eclipse.acceleo.aql.completion.proposals.templates.AcceleoCodeTemplates;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.util.AcceleoSwitch;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
@@ -59,12 +59,12 @@
/**
* The constructor.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) contextual {@link IAcceleoENvironment}.
+ * @param queryEnvironment
+ * the (non-{@code null}) contextual {@link IQualifiedNameQueryEnvironment}.
*/
- public AcceleoCompletionProposalsProvider(IAcceleoEnvironment acceleoEnvironment) {
+ public AcceleoCompletionProposalsProvider(IQualifiedNameQueryEnvironment queryEnvironment) {
this.acceleoCodeTemplatesProvider = new AcceleoCodeTemplateCompletionProposalsProvider(
- acceleoEnvironment);
+ queryEnvironment);
}
/**
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/templates/AcceleoCodeTemplateCompletionProposalsProvider.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/templates/AcceleoCodeTemplateCompletionProposalsProvider.java
index e00d278..7a1ac30 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/templates/AcceleoCodeTemplateCompletionProposalsProvider.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/completion/proposals/templates/AcceleoCodeTemplateCompletionProposalsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -25,11 +25,11 @@
import org.eclipse.acceleo.ModuleElementDocumentation;
import org.eclipse.acceleo.Query;
import org.eclipse.acceleo.Template;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.completion.AcceleoAstCompletor;
import org.eclipse.acceleo.aql.completion.AcceleoCompletor;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposal;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposalsProvider;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.util.AcceleoSwitch;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
@@ -135,18 +135,18 @@
AcceleoCodeTemplates.NEW_COMMENT_MAIN, AcceleoPackage.Literals.COMMENT);
/**
- * The {@link IAcceleoEnvironment}.
+ * The {@link IQualifiedNameQueryEnvironment}.
*/
- private final IAcceleoEnvironment acceleoEnvironment;
+ private final IQualifiedNameQueryEnvironment queryEnvironment;
/**
* Constructor.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) contextual {@link IAcceleoEnvironment}.
+ * @param queryEnvironment
+ * the (non-{@code null}) contextual {@link IQualifiedNameQueryEnvironment}.
*/
- public AcceleoCodeTemplateCompletionProposalsProvider(IAcceleoEnvironment acceleoEnvironment) {
- this.acceleoEnvironment = Objects.requireNonNull(acceleoEnvironment);
+ public AcceleoCodeTemplateCompletionProposalsProvider(IQualifiedNameQueryEnvironment queryEnvironment) {
+ this.queryEnvironment = Objects.requireNonNull(queryEnvironment);
}
/**
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/evaluation/AcceleoEvaluator.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/evaluation/AcceleoEvaluator.java
index 37fcc93..0aa135f 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/evaluation/AcceleoEvaluator.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/evaluation/AcceleoEvaluator.java
@@ -45,7 +45,6 @@
import org.eclipse.acceleo.Template;
import org.eclipse.acceleo.TextStatement;
import org.eclipse.acceleo.aql.AcceleoUtil;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.evaluation.writer.IAcceleoGenerationStrategy;
import org.eclipse.acceleo.aql.evaluation.writer.IAcceleoWriter;
import org.eclipse.acceleo.query.parser.AstResult;
@@ -83,9 +82,6 @@
*/
private static final String NEW_LINE = "\n";
- /** The current evaluation environment. */
- private final IAcceleoEnvironment environment;
-
/**
* The {@link IQueryEvaluationEngine} used to evaluate AQL expressions.
*/
@@ -128,29 +124,31 @@
private IAcceleoGenerationStrategy generationStrategy;
/**
+ * The {@link GenerationResult}.
+ */
+ private GenerationResult generationResult;
+
+ /**
* Constructor.
*
* @param other
* the other {@link AcceleoEvaluator}.
*/
public AcceleoEvaluator(AcceleoEvaluator other) {
- this(other.environment, other.lookupEngine);
+ this(other.lookupEngine);
destination = other.destination;
generationStrategy = other.generationStrategy;
+ generationResult = other.generationResult;
}
/**
* Constructor.
*
- * @param environment
- * the {@link IAcceleoEnvironment}
* @param lookupEngine
* the {@link IQualifiedNameLookupEngine}
*/
- public AcceleoEvaluator(IAcceleoEnvironment environment, IQualifiedNameLookupEngine lookupEngine) {
- this.environment = environment;
- final IQueryEnvironment queryEnvironment = environment.getQueryEnvironment();
- this.aqlEngine = QueryEvaluation.newEngine(queryEnvironment);
+ public AcceleoEvaluator(IQualifiedNameLookupEngine lookupEngine) {
+ this.aqlEngine = QueryEvaluation.newEngine((IQueryEnvironment)lookupEngine.getQueryEnvironment());
this.lookupEngine = lookupEngine;
}
@@ -175,6 +173,11 @@
destination = destinationURI;
generationStrategy = strategy;
lastLineOfLastStatement = "";
+ // TODO this is an issue for calling generate() multiple times
+ if (generationResult == null) {
+ generationResult = new GenerationResult();
+ }
+
pushVariables(variables);
try {
res = doSwitch(node);
@@ -268,15 +271,6 @@
}
/**
- * Gets the {@link IAcceleoEnvironment}.
- *
- * @return the {@link IAcceleoEnvironment}
- */
- protected IAcceleoEnvironment getEnvironment() {
- return environment;
- }
-
- /**
* {@inheritDoc}
*
* @see org.eclipse.acceleo.util.AcceleoSwitch#caseExpression(org.eclipse.acceleo.Expression)
@@ -288,7 +282,7 @@
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.ERROR, ID, 0,
"AQL parsing issue", new Object[] {expression });
diagnostic.addAll(ast.getDiagnostic());
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
}
final EvaluationResult evalResult = aqlEngine.eval(ast, peekVariables());
@@ -297,7 +291,7 @@
ID, 0, "AQL evaluation issue", new Object[] {expression, new HashMap<String, Object>(
peekVariables()) });
diagnostic.addAll(evalResult.getDiagnostic());
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
}
return evalResult.getResult();
@@ -515,7 +509,7 @@
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.ERROR, ID, 0,
"The URL can't be null", new Object[] {fileStatement.getUrl(),
new HashMap<String, Object>(peekVariables()) });
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
res = EMPTY_RESULT;
} else {
@@ -538,7 +532,7 @@
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.ERROR, ID, 0, e
.getMessage(), new Object[] {fileStatement, new HashMap<String, Object>(
peekVariables()) });
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
}
res = EMPTY_RESULT;
@@ -566,7 +560,7 @@
final IAcceleoWriter writer = generationStrategy.createWriterFor(uri, openMode, charset,
lineDelimiter);
writers.addLast(writer);
- environment.getGenerationResult().getGeneratedFiles().add(uri);
+ generationResult.getGeneratedFiles().add(uri);
}
/**
@@ -614,14 +608,14 @@
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.WARNING, ID, 0, e
.getMessage() + " fallback to UTF-8", new Object[] {fileStatement.getUrl(),
new HashMap<String, Object>(peekVariables()) });
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
}
charset = defaultCharset;
} else {
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.WARNING, ID, 0,
"The Charset can't be null, fallback to UTF-8", new Object[] {fileStatement.getUrl(),
new HashMap<String, Object>(peekVariables()) });
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
charset = StandardCharsets.UTF_8;
}
} else {
@@ -657,7 +651,7 @@
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.ERROR, ID, 0,
"The expression must be evaluated to a boolean not: " + toString(condition),
new Object[] {ifStatement.getCondition(), new HashMap<String, Object>(peekVariables()) });
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
res = EMPTY_RESULT;
}
@@ -678,7 +672,7 @@
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.WARNING, ID, 0,
"The expression should not be null", new Object[] {forStatement.getBinding()
.getInitExpression(), new HashMap<String, Object>(peekVariables()) });
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
}
if (!iteration.isEmpty()) {
final Map<String, Object> variables = new HashMap<String, Object>(peekVariables());
@@ -717,7 +711,7 @@
public Object caseError(Error error) {
final BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.ERROR, ID, 0,
"Acceleo parsing error see validation for more details", new Object[] {error });
- environment.getGenerationResult().addDiagnostic(diagnostic);
+ generationResult.addDiagnostic(diagnostic);
return EMPTY_RESULT;
}
@@ -761,4 +755,13 @@
return generationStrategy;
}
+ /**
+ * Gets the {@link GenerationResult}.
+ *
+ * @return the {@link GenerationResult}
+ */
+ public GenerationResult getGenerationResult() {
+ return generationResult;
+ }
+
}
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoDefinitionLocator.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoDefinitionLocator.java
index 7c8d8e3..1cc855e 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoDefinitionLocator.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoDefinitionLocator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -26,9 +26,8 @@
import org.eclipse.acceleo.Query;
import org.eclipse.acceleo.Template;
import org.eclipse.acceleo.Variable;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.location.common.AbstractLocationLink;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.util.AcceleoSwitch;
/**
@@ -40,28 +39,19 @@
public class AcceleoDefinitionLocator extends AcceleoSwitch<List<AbstractLocationLink<?, ?>>> {
/**
- * The {@link IAcceleoEnvironment} in which this locator searches for definitions.
+ * The {@link IQualifiedNameQueryEnvironment} in which this locator searches for definitions.
*/
- private final IAcceleoEnvironment acceleoEnvironment;
-
- /**
- * The {@link IQualifiedNameLookupEngine}.
- */
- private IQualifiedNameLookupEngine lookupEngine;
+ private final IQualifiedNameQueryEnvironment queryEnvironment;
/**
* Constructor.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) {@link IAcceleoEnvironment} of the {@link Module} to which the
- * argument {@link ASTNode} belongs.
- * @param lookupEngine
- * the {@link IQualifiedNameLookupEngine}
+ * @param queryEnvironment
+ * the (non-{@code null}) {@link IQualifiedNameQueryEnvironment} of the {@link Module} to which
+ * the argument {@link ASTNode} belongs.
*/
- public AcceleoDefinitionLocator(IAcceleoEnvironment acceleoEnvironment,
- IQualifiedNameLookupEngine lookupEngine) {
- this.acceleoEnvironment = acceleoEnvironment;
- this.lookupEngine = lookupEngine;
+ public AcceleoDefinitionLocator(IQualifiedNameQueryEnvironment queryEnvironment) {
+ this.queryEnvironment = queryEnvironment;
}
// Simple cases where the argument element is its own definition.
@@ -113,7 +103,8 @@
*/
@Override
public List<AbstractLocationLink<?, ?>> caseModuleReference(ModuleReference moduleReference) {
- final Object resolved = lookupEngine.getResolver().resolve(moduleReference.getQualifiedName());
+ final Object resolved = queryEnvironment.getLookupEngine().getResolver().resolve(moduleReference
+ .getQualifiedName());
if (resolved instanceof Module) {
return Collections.singletonList(new AcceleoLocationLinkToAcceleo(moduleReference,
(Module)resolved));
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoExpressionVariablesContextProvider.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoExpressionVariablesContextProvider.java
index 1a75f8e..ce965fb 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoExpressionVariablesContextProvider.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoExpressionVariablesContextProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,9 +23,9 @@
import org.eclipse.acceleo.TypedElement;
import org.eclipse.acceleo.Variable;
import org.eclipse.acceleo.aql.AcceleoUtil;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.location.aql.AqlVariablesLocalContext;
import org.eclipse.acceleo.aql.validation.AcceleoValidationUtils;
+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.util.AcceleoSwitch;
@@ -40,18 +40,18 @@
public class AcceleoExpressionVariablesContextProvider extends AcceleoSwitch<AqlVariablesLocalContext> {
/**
- * The {@link IAcceleoEnvironment}.
+ * The {@link IQualifiedNameQueryEnvironment}.
*/
- private final IAcceleoEnvironment acceleoEnvironment;
+ private final IQualifiedNameQueryEnvironment queryEnvironment;
/**
* Constructor.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) {@link IAcceleoEnvironment}.
+ * @param queryEnvironment
+ * the (non-{@code null}) {@link IQualifiedNameQueryEnvironment}.
*/
- public AcceleoExpressionVariablesContextProvider(IAcceleoEnvironment acceleoEnvironment) {
- this.acceleoEnvironment = acceleoEnvironment;
+ public AcceleoExpressionVariablesContextProvider(IQualifiedNameQueryEnvironment queryEnvironment) {
+ this.queryEnvironment = queryEnvironment;
}
// Expression and TypedElement are the two entry points into this because these are the only ASTNodes that
@@ -102,8 +102,7 @@
AqlVariablesLocalContext variablesContext = new AqlVariablesLocalContext();
// Deal with the implicit "self" variable.
- Set<IType> selfPossibleTypes = Collections.singleton(new ClassType(this.acceleoEnvironment
- .getQueryEnvironment(), String.class));
+ Set<IType> selfPossibleTypes = Collections.singleton(new ClassType(queryEnvironment, String.class));
variablesContext.addVariable(AcceleoUtil.getTemplateImplicitVariableName(), template,
selfPossibleTypes);
@@ -143,7 +142,7 @@
AqlVariablesLocalContext variablesContext = new AqlVariablesLocalContext();
Set<IType> variablePossibleTypes = AcceleoValidationUtils.getPossibleTypes(variable,
- this.acceleoEnvironment.getQueryEnvironment());
+ queryEnvironment);
variablesContext.addVariable(variable.getName(), variable, variablePossibleTypes);
return variablesContext;
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoLocator.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoLocator.java
index eaa9193..6e91c2f 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoLocator.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/location/AcceleoLocator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 Obeo.
+ * Copyright (c) 2020, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,14 +14,13 @@
import java.util.List;
import org.eclipse.acceleo.ASTNode;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.location.aql.AqlLocator;
import org.eclipse.acceleo.aql.location.aql.AqlVariablesLocalContext;
import org.eclipse.acceleo.aql.location.common.AbstractLocationLink;
import org.eclipse.acceleo.aql.parser.AcceleoAstResult;
import org.eclipse.acceleo.aql.parser.AcceleoAstUtils;
import org.eclipse.acceleo.query.parser.AstResult;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.emf.ecore.EObject;
/**
@@ -33,9 +32,9 @@
public class AcceleoLocator {
/**
- * The {@link IAcceleoEnvironment} of the Acceleo contents.
+ * The {@link IQualifiedNameQueryEnvironment} of the Acceleo contents.
*/
- private final IAcceleoEnvironment acceleoEnvironment;
+ private final IQualifiedNameQueryEnvironment queryEnvironment;
/**
* The {@link AqlLocator} we delegate to in case we are inside an AQL expression.
@@ -43,23 +42,15 @@
private final AqlLocator aqlLocator;
/**
- * The {@link IQualifiedNameLookupEngine}.
- */
- private IQualifiedNameLookupEngine lookupEngine;
-
- /**
* Creates a new {@link AcceleoLocator}.
*
- * @param acceleoEnvironment
- * the (non-{@code null}) {@link IAcceleoEnvironment} of the Acceleo contents.
- * @param lookupEngine
- * the {@link IQualifiedNameLookupEngine}
+ * @param queryEnvironment
+ * the (non-{@code null}) {@link IQualifiedNameQueryEnvironment} of the Acceleo contents.
*/
- public AcceleoLocator(IAcceleoEnvironment acceleoEnvironment, IQualifiedNameLookupEngine lookupEngine) {
- this.acceleoEnvironment = acceleoEnvironment;
- this.lookupEngine = lookupEngine;
+ public AcceleoLocator(IQualifiedNameQueryEnvironment queryEnvironment) {
+ this.queryEnvironment = queryEnvironment;
- this.aqlLocator = new AqlLocator(this.acceleoEnvironment.getQueryEnvironment());
+ this.aqlLocator = new AqlLocator(queryEnvironment);
}
/**
@@ -134,8 +125,8 @@
*/
private AqlVariablesLocalContext getVariablesContext(EObject aqlAstElement) {
ASTNode acceleoContainerOfAqlElement = AcceleoAstUtils.getContainerOfAqlAstElement(aqlAstElement);
- AqlVariablesLocalContext context = new AcceleoExpressionVariablesContextProvider(
- this.acceleoEnvironment).doSwitch(acceleoContainerOfAqlElement);
+ AqlVariablesLocalContext context = new AcceleoExpressionVariablesContextProvider(queryEnvironment)
+ .doSwitch(acceleoContainerOfAqlElement);
return context;
}
@@ -145,8 +136,7 @@
// The definition locator needs the environment for resolving references to out-of-file elements, and
// the position so it can delegate to the AQL locator if we are inside an expression.
- AcceleoDefinitionLocator definitionLocator = new AcceleoDefinitionLocator(this.acceleoEnvironment,
- lookupEngine);
+ AcceleoDefinitionLocator definitionLocator = new AcceleoDefinitionLocator(queryEnvironment);
// Retrieve the links from our element to its definition location(s).
List<AbstractLocationLink<?, ?>> linksToDefinitionLocations = definitionLocator.doSwitch(
diff --git a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/validation/AcceleoValidator.java b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/validation/AcceleoValidator.java
index eb8c4e8..dbc5a6f 100644
--- a/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/validation/AcceleoValidator.java
+++ b/plugins/org.eclipse.acceleo.aql/src/org/eclipse/acceleo/aql/validation/AcceleoValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2017, 2020 Obeo.
+ * Copyright (c) 2017, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -59,7 +59,6 @@
import org.eclipse.acceleo.TextStatement;
import org.eclipse.acceleo.Variable;
import org.eclipse.acceleo.aql.AcceleoUtil;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.parser.AcceleoAstResult;
import org.eclipse.acceleo.aql.parser.AcceleoParser;
import org.eclipse.acceleo.query.parser.AstValidator;
@@ -68,7 +67,7 @@
import org.eclipse.acceleo.query.runtime.ValidationMessageLevel;
import org.eclipse.acceleo.query.runtime.impl.ValidationMessage;
import org.eclipse.acceleo.query.runtime.impl.ValidationServices;
-import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.validation.type.ClassType;
import org.eclipse.acceleo.query.validation.type.ICollectionType;
import org.eclipse.acceleo.query.validation.type.IType;
@@ -81,7 +80,6 @@
*
* @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
*/
-@SuppressWarnings("restriction")
public class AcceleoValidator extends AcceleoSwitch<Object> {
/**
@@ -100,9 +98,9 @@
private static final Object RETURN_VALUE = new Object();
/**
- * The {@link IAcceleoEnvironment}.
+ * The {@link IQualifiedNameQueryEnvironment}.
*/
- private final IAcceleoEnvironment environment;
+ private final IQualifiedNameQueryEnvironment queryEnvironment;
/**
* The {@link AstValidator}.
@@ -140,25 +138,17 @@
private final IType booleanObjectType;
/**
- * The {@link IQualifiedNameLookupEngine}.
- */
- private final IQualifiedNameLookupEngine lookupEngine;
-
- /**
* Constructor.
*
- * @param environment
- * the {@link IAcceleoEnvironment}
- * @param lookupEngine
- * the {@link IQualifiedNameLookupEngine}
+ * @param queryEnvironment
+ * the {@link IQualifiedNameQueryEnvironment}
*/
- public AcceleoValidator(IAcceleoEnvironment environment, IQualifiedNameLookupEngine lookupEngine) {
- this.environment = environment;
- this.lookupEngine = lookupEngine;
- this.stringType = new ClassType(environment.getQueryEnvironment(), String.class);
- this.booleanType = new ClassType(environment.getQueryEnvironment(), boolean.class);
- this.booleanObjectType = new ClassType(environment.getQueryEnvironment(), Boolean.class);
- validator = new AstValidator(new ValidationServices(environment.getQueryEnvironment()));
+ public AcceleoValidator(IQualifiedNameQueryEnvironment queryEnvironment) {
+ this.queryEnvironment = queryEnvironment;
+ this.stringType = new ClassType(queryEnvironment, String.class);
+ this.booleanType = new ClassType(queryEnvironment, boolean.class);
+ this.booleanObjectType = new ClassType(queryEnvironment, Boolean.class);
+ validator = new AstValidator(new ValidationServices(queryEnvironment));
}
/**
@@ -204,11 +194,11 @@
forceCollectionBinding = false;
result = new AcceleoValidationResult(astResult);
- lookupEngine.pushImportsContext(moduleQualifiedName, moduleQualifiedName);
+ queryEnvironment.getLookupEngine().pushImportsContext(moduleQualifiedName, moduleQualifiedName);
try {
doSwitch(astResult.getModule());
} finally {
- lookupEngine.popContext(moduleQualifiedName);
+ queryEnvironment.getLookupEngine().popContext(moduleQualifiedName);
}
return result;
@@ -366,8 +356,8 @@
@Override
public Object caseModuleReference(ModuleReference moduleReference) {
- if (moduleReference.getQualifiedName() != null && lookupEngine.getResolver().getURL(moduleReference
- .getQualifiedName()) == null) {
+ if (moduleReference.getQualifiedName() != null && queryEnvironment.getLookupEngine().getResolver()
+ .getURL(moduleReference.getQualifiedName()) == null) {
final AcceleoAstResult acceleoAstResult = result.getAcceleoAstResult();
addMessage(moduleReference, ValidationMessageLevel.ERROR, "Could not resolve " + moduleReference
.getQualifiedName(), acceleoAstResult.getStartPosition(moduleReference), acceleoAstResult
@@ -413,7 +403,7 @@
if (template.getPost() != null) {
pushVariableTypes(new HashMap<String, Set<IType>>(peekVariableTypes()));
Set<IType> possibleTypes = new LinkedHashSet<IType>();
- possibleTypes.add(new ClassType(environment.getQueryEnvironment(), String.class));
+ possibleTypes.add(new ClassType(queryEnvironment, String.class));
peekVariableTypes().put(AcceleoUtil.getTemplateImplicitVariableName(), possibleTypes);
try {
doSwitch(template.getPost());
@@ -498,8 +488,8 @@
final IValidationResult typeValidationResult = validator.validate(Collections.emptyMap(),
query.getType());
result.getAqlValidationResults().put(query.getType(), typeValidationResult);
- final Set<IType> iTypes = validator.getDeclarationTypes(environment.getQueryEnvironment(),
- typeValidationResult.getPossibleTypes(query.getType().getAst()));
+ final Set<IType> iTypes = validator.getDeclarationTypes(queryEnvironment, typeValidationResult
+ .getPossibleTypes(query.getType().getAst()));
checkTypesCompatibility(query, possibleTypes, iTypes);
}
} finally {
@@ -556,8 +546,8 @@
final IValidationResult typeValidationResult = validator.validate(Collections.emptyMap(), variable
.getType());
result.getAqlValidationResults().put(variable.getType(), typeValidationResult);
- final Set<IType> types = validator.getDeclarationTypes(environment.getQueryEnvironment(),
- typeValidationResult.getPossibleTypes(variable.getType().getAst()));
+ final Set<IType> types = validator.getDeclarationTypes(queryEnvironment, typeValidationResult
+ .getPossibleTypes(variable.getType().getAst()));
peekVariableTypes().put(variable.getName(), types);
return RETURN_VALUE;
@@ -595,8 +585,8 @@
final IValidationResult typeValidationResult = validator.validate(Collections.emptyMap(), binding
.getType());
result.getAqlValidationResults().put(binding.getType(), typeValidationResult);
- final Set<IType> iTypes = validator.getDeclarationTypes(environment.getQueryEnvironment(),
- typeValidationResult.getPossibleTypes(binding.getType().getAst()));
+ final Set<IType> iTypes = validator.getDeclarationTypes(queryEnvironment, typeValidationResult
+ .getPossibleTypes(binding.getType().getAst()));
checkTypesCompatibility(binding, possibleTypes, iTypes);
}
diff --git a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/Query.java b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/Query.java
index 89ab88e..474c7e1 100644
--- a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/Query.java
+++ b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/Query.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 Obeo.
+ * Copyright (c) 2015, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,6 +14,9 @@
import java.util.Set;
import org.eclipse.acceleo.query.runtime.impl.QueryEnvironment;
+import org.eclipse.acceleo.query.runtime.impl.namespace.QualifiedNameQueryEnvironment;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
+import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
import org.eclipse.acceleo.query.services.AnyServices;
import org.eclipse.acceleo.query.services.BooleanServices;
import org.eclipse.acceleo.query.services.CollectionServices;
@@ -138,4 +141,58 @@
return new QueryEnvironment();
}
+ /**
+ * Create a new {@link IQualifiedNameQueryEnvironment} configured with the services provided by default with Acceleo
+ * Query.
+ *
+ * @param resolver
+ * the {@link IQualifiedNameResolver}
+ * @param xRefProvider
+ * an instance to inspect cross references at evaluation time
+ * @return a new {@link IQualifiedNameQueryEnvironment} configured with the services provided by default with Acceleo
+ * Query
+ * @since 9.0
+ */
+ public static IQualifiedNameQueryEnvironment newQualifiedNameEnvironmentWithDefaultServices(
+ IQualifiedNameResolver resolver, CrossReferenceProvider xRefProvider) {
+ return newQualifiedNameEnvironmentWithDefaultServices(resolver, xRefProvider, null);
+ }
+
+ /**
+ * Create a new {@link IQualifiedNameQueryEnvironment} configured with the services provided by default with Acceleo
+ * Query.
+ *
+ * @param resolver
+ * the {@link IQualifiedNameResolver}
+ * @param xRefProvider
+ * an instance to inspect cross references at evaluation time
+ * @param rootProvider
+ * an instance to search all instances at evaluation time
+ * @return a new {@link IQualifiedNameQueryEnvironment} configured with the services provided by default with Acceleo
+ * Query
+ * @since 9.0
+ */
+ public static IQualifiedNameQueryEnvironment newQualifiedNameEnvironmentWithDefaultServices(
+ IQualifiedNameResolver resolver, CrossReferenceProvider xRefProvider,
+ IRootEObjectProvider rootProvider) {
+ final IQualifiedNameQueryEnvironment env = newQualifiedNameEnvironment(resolver);
+
+ configureEnvironment(env, xRefProvider, rootProvider);
+
+ return env;
+ }
+
+ /**
+ * Create a new {@link IQualifiedNameQueryEnvironment} with no services configured.
+ *
+ * @param resolver
+ * the {@link IQualifiedNameResolver}
+ * @return a new {@link IQualifiedNameQueryEnvironment} with no services configured.
+ * @since 9.0
+ */
+ public static IQualifiedNameQueryEnvironment newQualifiedNameEnvironment(
+ IQualifiedNameResolver resolver) {
+ return new QualifiedNameQueryEnvironment(resolver);
+ }
+
}
diff --git a/tests/org.eclipse.acceleo.aql.ide.tests/src/org/eclipse/acceleo/aql/ide/tests/BundleTests.java b/tests/org.eclipse.acceleo.aql.ide.tests/src/org/eclipse/acceleo/aql/ide/tests/BundleTests.java
index d748d8f..1f6278b 100644
--- a/tests/org.eclipse.acceleo.aql.ide.tests/src/org/eclipse/acceleo/aql/ide/tests/BundleTests.java
+++ b/tests/org.eclipse.acceleo.aql.ide.tests/src/org/eclipse/acceleo/aql/ide/tests/BundleTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2017 Obeo.
+ * Copyright (c) 2017, 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,7 +13,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
+import org.eclipse.acceleo.aql.AcceleoUtil;
import org.eclipse.acceleo.aql.ide.AcceleoPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EPackage;
@@ -31,7 +31,7 @@
@Before
public void setUp() {
// Make sure the org.eclipse.acceleo.aql is loaded
- IAcceleoEnvironment.class.getClass();
+ AcceleoUtil.class.getClass();
// Make sure the org.eclipse.acceleo.aql.ide is loaded
AcceleoPlugin.getPlugin();
}
diff --git a/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/completion/CompletionTests.java b/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/completion/CompletionTests.java
index 900b638..b0a56f1 100644
--- a/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/completion/CompletionTests.java
+++ b/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/completion/CompletionTests.java
@@ -30,8 +30,6 @@
import java.util.regex.Pattern;
import org.eclipse.acceleo.Module;
-import org.eclipse.acceleo.aql.AcceleoEnvironment;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.completion.AcceleoCompletor;
import org.eclipse.acceleo.aql.completion.proposals.AcceleoCompletionProposal;
import org.eclipse.acceleo.aql.evaluation.AcceleoEvaluator;
@@ -40,7 +38,6 @@
import org.eclipse.acceleo.aql.parser.ModuleLoader;
import org.eclipse.acceleo.query.runtime.impl.namespace.ClassLoaderQualifiedNameResolver;
import org.eclipse.acceleo.query.runtime.impl.namespace.JavaLoader;
-import org.eclipse.acceleo.query.runtime.impl.namespace.QualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
import org.eclipse.acceleo.tests.utils.AbstractLanguageTestSuite;
@@ -55,7 +52,6 @@
*
* @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
*/
-@SuppressWarnings("restriction")
@RunWith(Parameterized.class)
public class CompletionTests {
@@ -120,11 +116,11 @@
final IQualifiedNameResolver resolver = new ClassLoaderQualifiedNameResolver(getClass()
.getClassLoader(), AcceleoParser.QUALIFIER_SEPARATOR);
- final IQualifiedNameQueryEnvironment queryEnvironment = new QualifiedNameQueryEnvironment(resolver);
- final IAcceleoEnvironment acceleoEnvironment = new AcceleoEnvironment(queryEnvironment);
+ /* FIXME we need a cross reference provider, and we need to make it configurable */
+ final IQualifiedNameQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
+ .newQualifiedNameEnvironmentWithDefaultServices(resolver, null, null);
- final AcceleoEvaluator evaluator = new AcceleoEvaluator(acceleoEnvironment, queryEnvironment
- .getLookupEngine());
+ final AcceleoEvaluator evaluator = new AcceleoEvaluator(queryEnvironment.getLookupEngine());
final AcceleoParser parser = new AcceleoParser();
resolver.addLoader(new ModuleLoader(parser, evaluator));
resolver.addLoader(new JavaLoader(AcceleoParser.QUALIFIER_SEPARATOR));
@@ -132,9 +128,8 @@
final AcceleoAstResult parsingResult = parser.parse(source, "org::eclipse::acceleo::tests::");
final Module module = parsingResult.getModule();
resolver.register("org::eclipse::acceleo::tests::" + module.getName(), module);
- final List<AcceleoCompletionProposal> completionProposals = completor.getProposals(acceleoEnvironment,
- acceleoEnvironment.getQueryEnvironment().getLookupEngine(), module.getName(), source,
- position);
+ final List<AcceleoCompletionProposal> completionProposals = completor.getProposals(queryEnvironment,
+ module.getName(), source, position);
final String actualCompletion = serialize(completionProposals);
final File expectedCompletionFile = getExpectedCompletionFile();
if (!expectedCompletionFile.exists()) {
diff --git a/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractEvaluationTestSuite.java b/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractEvaluationTestSuite.java
index e153f7d..79895e9 100644
--- a/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractEvaluationTestSuite.java
+++ b/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractEvaluationTestSuite.java
@@ -103,12 +103,12 @@
final URI generatedFolderURI = URI.createURI("generated/").resolve(model.getURI());
final List<URI> expectedGeneratedFiles = getExpectedGeneratedFiles(generatedFolderURI);
final List<URI> unexpectedGeneratedFiles = new ArrayList<URI>();
- AcceleoUtil.generate(evaluator, environment, module, model, memoryDestination);
+ AcceleoUtil.generate(evaluator, queryEnvironment, module, model, memoryDestination);
- assertGenerationMessages(environment.getGenerationResult());
+ assertGenerationMessages(evaluator.getGenerationResult());
// assert generated content
- final GenerationResult result = environment.getGenerationResult();
+ final GenerationResult result = evaluator.getGenerationResult();
for (URI memoryGeneratedURI : result.getGeneratedFiles()) {
final URI generatedURI = URI.createURI(memoryGeneratedURI.toString().substring(
memoryDestinationString.length())).resolve(generatedFolderURI);
diff --git a/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractLanguageTestSuite.java b/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractLanguageTestSuite.java
index 41d4759..06afd9c 100644
--- a/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractLanguageTestSuite.java
+++ b/tests/org.eclipse.acceleo.aql.tests/src/org/eclipse/acceleo/tests/utils/AbstractLanguageTestSuite.java
@@ -34,8 +34,6 @@
import java.util.List;
import org.eclipse.acceleo.Module;
-import org.eclipse.acceleo.aql.AcceleoEnvironment;
-import org.eclipse.acceleo.aql.IAcceleoEnvironment;
import org.eclipse.acceleo.aql.evaluation.AcceleoEvaluator;
import org.eclipse.acceleo.aql.parser.AcceleoAstResult;
import org.eclipse.acceleo.aql.parser.AcceleoParser;
@@ -44,7 +42,6 @@
import org.eclipse.acceleo.query.runtime.IValidationMessage;
import org.eclipse.acceleo.query.runtime.impl.namespace.ClassLoaderQualifiedNameResolver;
import org.eclipse.acceleo.query.runtime.impl.namespace.JavaLoader;
-import org.eclipse.acceleo.query.runtime.impl.namespace.QualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameResolver;
import org.eclipse.emf.common.util.URI;
@@ -87,9 +84,9 @@
protected final AcceleoAstResult astResult;
/**
- * The {@link IAcceleoEnvironment}.
+ * The {@link IQualifiedNameQueryEnvironment}.
*/
- protected final IAcceleoEnvironment environment;
+ protected final IQualifiedNameQueryEnvironment queryEnvironment;
/**
* The {@link AcceleoEvaluator}.
@@ -142,10 +139,11 @@
final ClassLoader classLoader = new URLClassLoader(urls, getClass().getClassLoader());
final IQualifiedNameResolver resolver = new ClassLoaderQualifiedNameResolver(classLoader,
AcceleoParser.QUALIFIER_SEPARATOR);
- final IQualifiedNameQueryEnvironment queryEnvironment = new QualifiedNameQueryEnvironment(resolver);
- this.environment = new AcceleoEnvironment(queryEnvironment);
+ /* FIXME we need a cross reference provider, and we need to make it configurable */
+ queryEnvironment = org.eclipse.acceleo.query.runtime.Query
+ .newQualifiedNameEnvironmentWithDefaultServices(resolver, null, null);
- evaluator = new AcceleoEvaluator(this.environment, queryEnvironment.getLookupEngine());
+ evaluator = new AcceleoEvaluator(queryEnvironment.getLookupEngine());
resolver.addLoader(new ModuleLoader(new AcceleoParser(), evaluator));
resolver.addLoader(new JavaLoader(AcceleoParser.QUALIFIER_SEPARATOR));
@@ -236,8 +234,7 @@
*/
@Test
public void validation() throws FileNotFoundException, IOException {
- AcceleoValidator validator = new AcceleoValidator(environment, environment.getQueryEnvironment()
- .getLookupEngine());
+ AcceleoValidator validator = new AcceleoValidator(queryEnvironment);
final List<IValidationMessage> messages = validator.validate(astResult, qualifiedName)
.getValidationMessages();
final String actualContent = getValidationContent(messages);