Skip to content

Commit

Permalink
Merge pull request #151 from LorenzoBettini/task_150-Interpreter_Prov…
Browse files Browse the repository at this point in the history
…ider

Task 150 interpreter provider
  • Loading branch information
LorenzoBettini committed May 5, 2020
2 parents 0d678b1 + 2601902 commit 61dc304
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
@@ -0,0 +1,33 @@
/**
*
*/
package edelta.interpreter;

import org.eclipse.emf.ecore.resource.Resource;

import com.google.inject.Inject;
import com.google.inject.Provider;

import edelta.interpreter.internal.EdeltaInterpreterConfigurator;

/**
* Creates an {@link IEdeltaInterpreter} and configures it with
* {@link EdeltaInterpreterConfigurator}.
*
* @author Lorenzo Bettini
*
*/
public class EdeltaInterpreterFactory {

@Inject
private Provider<IEdeltaInterpreter> provider;

@Inject
private EdeltaInterpreterConfigurator configurator;

public IEdeltaInterpreter create(Resource resource) {
IEdeltaInterpreter interpreter = provider.get();
configurator.configureInterpreter(interpreter, resource);
return interpreter;
}
}
Expand Up @@ -36,7 +36,7 @@ public class EdeltaInterpreterConfigurator {
@Inject
private ClassLoader parentClassLoader;

public void configureInterpreter(IEdeltaInterpreter interpreter2, Resource resource) {
public void configureInterpreter(IEdeltaInterpreter interpreter, Resource resource) {
ResourceSet set = resource.getResourceSet();
if (set instanceof XtextResourceSet) {
Object context = ((XtextResourceSet) set).getClasspathURIContext();
Expand Down Expand Up @@ -87,7 +87,7 @@ public void configureInterpreter(IEdeltaInterpreter interpreter2, Resource resou
URLClassLoader cl = new URLClassLoader(
urls.toArray(new URL[urls.size()]),
parentClassLoader);
interpreter2.setClassLoader(cl);
interpreter.setClassLoader(cl);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Expand Up @@ -5,8 +5,8 @@ import com.google.inject.Singleton
import com.google.inject.name.Named
import edelta.edelta.EdeltaEcoreReferenceExpression
import edelta.edelta.EdeltaProgram
import edelta.interpreter.IEdeltaInterpreter
import edelta.interpreter.internal.EdeltaInterpreterConfigurator
import edelta.interpreter.EdeltaInterpreterFactory
import edelta.interpreter.EdeltaInterpreterHelper
import edelta.lib.EdeltaEcoreUtil
import edelta.scoping.EdeltaOriginalENamedElementRecorder
import edelta.services.IEdeltaEcoreModelAssociations
Expand All @@ -21,7 +21,6 @@ import org.eclipse.xtext.parser.antlr.IReferableElementsUnloader.GenericUnloader
import org.eclipse.xtext.resource.DerivedStateAwareResource
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator
import edelta.interpreter.EdeltaInterpreterHelper

@Singleton
class EdeltaDerivedStateComputer extends JvmModelAssociator implements IEdeltaEcoreModelAssociations {
Expand All @@ -32,12 +31,10 @@ class EdeltaDerivedStateComputer extends JvmModelAssociator implements IEdeltaEc

@Inject GenericUnloader unloader

@Inject IEdeltaInterpreter interpreter
@Inject EdeltaInterpreterFactory interpreterFactory

@Inject EdeltaInterpreterHelper interpreterHelper

@Inject EdeltaInterpreterConfigurator interpreterConfigurator

@Inject EdeltaOriginalENamedElementRecorder originalENamedElementRecorder

static class EdeltaDerivedStateAdapter extends AdapterImpl {
Expand Down Expand Up @@ -86,8 +83,7 @@ class EdeltaDerivedStateComputer extends JvmModelAssociator implements IEdeltaEc
resource.contents += copiedEPackagesMap.values
// record original ecore references before running the interpreter
recordEcoreReferenceOriginalENamedElement(resource)
// configure and run the interpreter
interpreterConfigurator.configureInterpreter(interpreter, resource)
// run the interpreter
runInterpreter(
program,
copiedEPackagesMap
Expand All @@ -98,7 +94,7 @@ class EdeltaDerivedStateComputer extends JvmModelAssociator implements IEdeltaEc
protected def void runInterpreter(EdeltaProgram program,
EdeltaCopiedEPackagesMap copiedEPackagesMap
) {
interpreter.evaluateModifyEcoreOperations(
interpreterFactory.create(program.eResource).evaluateModifyEcoreOperations(
program,
copiedEPackagesMap
)
Expand Down

0 comments on commit 61dc304

Please sign in to comment.