|
|
Re: Bug in Mwe2ExecutionEngine? [message #715042 is a reply to message #715035] |
Fri, 12 August 2011 08:14 |
Daniel Missing name Messages: 101 Registered: July 2011 |
Senior Member |
|
|
Quite true, I just recognized that I need to use my own injector rather than use the injector of the Mwe Context.
My workflow looks like this:
JavaCompiler { // JavaCompiler extends Workflow
// component = Reader { slot = "model" ...}
// component = CompilerComponent
// CompilerComponent extends GeneratorComponent
// -> sets the setup and injector
// Reader.modelPath
modelPath = "src"
// CompilerComponent.outlet.path
targetDirectory = "src-java"
// CompilerComponent.template
template = JavaTemplate {} // implements IGenerator
// CompilerComponent.settings
settings = {
javaPackage = "at.bachmann.smi"
}
}
I want to let the injector of the CompilerComponent create my JavaTemplate instance where I need some injected stuff. I have built a workaround by specifying a full qualified class-name as string for the template. The MWE2 grammar does not allow to assign Class<?> references and something like template = at.mydsl.compiler.java.JavaTemplate would lead to an unresolvable reference. Is there a more clean way to specify a sub-component to be created by my injector?
I think of this solution: A special workflow component which can provide an injector. The Mwe2ExecutionEngine checks whether the current component provides an injector and uses it for any instance to be created within this component.
// IWorkflowComponentWithInjector.java
public interface IWorkflowComponentWithInjector extends IWorkflowComponent {
public Injector getInjector();
}
// CompilerComponent.java
public class CompilerComponent implements IWorkflowComponentWithInjector {
private Injector injector;
public void setRegister(ISetup setup) { injector = setup.createInjectorAndDoEMFRegistration(); }
public Injector getInjector() { return injector; }
}
// CompileToJava.mwe2
Workflow {
component = CompilerComponent {
template = MyTemplate {} // gets created by the injector of CompilerComponent
}
}
// Mwe2ExecutionEngine
private Injector currentComponentInjector;
...
protected Object create(JvmType jvmType) {
...
if(currentComponentInjector != null) {
return currentComponentInjector.getInstance(...);
}
else {
...
}
...
}
[Updated on: Fri, 12 August 2011 08:23] Report message to a moderator
|
|
|
Re: Bug in Mwe2ExecutionEngine? [message #715046 is a reply to message #715042] |
Fri, 12 August 2011 08:22 |
|
Hi,
i guess this is currently not possible. otherwise xtext won't do stuff like
fragment = validation.JavaValidatorFragment {
composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
feel free to file an enhancement request against mwe2 to be capable of "Class Literals" too
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Fri, 12 August 2011 08:23] Report message to a moderator
|
|
|
Re: Bug in Mwe2ExecutionEngine? [message #715057 is a reply to message #715046] |
Fri, 12 August 2011 08:50 |
Daniel Missing name Messages: 101 Registered: July 2011 |
Senior Member |
|
|
I filed a bug here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=354591
Shouldn't be too much work to add this feature.
I think I will file a feature request for the "injection-scope" too. I like the idea of specifying which injector to use for instance creation in within the current and child components.
[Edit]
I found another workaround that works.
In my CompilerComponent I simply inject the members to the existing object.
Awesome that Guice can inject members even into objects that are already existing.
...
private CompilerTemplate template;
public CompilerTemplate getTemplate() {return template;}
public void setTemplate(CompilerTemplate template) { this.template = template; }
...
public void preInvoke() {
...
injector.injectMembers(template);
super.preInvoke();
}
[Updated on: Fri, 12 August 2011 09:36] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03226 seconds