Add EAnnotation in generated Ecore [message #1823342] |
Wed, 25 March 2020 09:41 |
Axel RICHARD Messages: 43 Registered: September 2010 Location: France |
Member |
|
|
Hello,
I'm using Xtext 2.20.
I want to add a specific eAnnotation in some of my eClasses in my generated Ecore from my grammar.
I tried to implement IXtext2EcorePostProcessor (through https://www.dietrich-it.de/xtext/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2.html), but it seems no more possible to use it.
Indeed in the following,
public class MyCustomEcoreGenerator extends XtextGenerator {
public MyCustomEcoreGenerator() {
new XtextStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(new XtextRuntimeModule() {
public Class<? extends IXtext2EcorePostProcessor> bindIXtext2EcorePostProcessor() {
return MyXtext2EcorePostProcessor.class;
}
});
}
}.createInjectorAndDoEMFRegistration();
}
}
@Override annotation must be removed above bindIXtext2EcorePostProcessor
Then, when I try to run MyGenerator.mwe2, I get the following error :
A binding to org.eclipse.xtext.xtext.ecoreInference.IXtext2EcorePostProcessor was already configured at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:57).
at org.eclipse.xtext.XtextRuntimeModule.configureIXtext2EcorePostProcessor(XtextRuntimeModule.java:115)
I also tried to declare MyXtext2EcorePostProcessor through
bindEcorePostProcessor() , but bindEcorePostProcessor() it is not accessible in MyGrammarRuntimeModule.xtend
I also tried to declare MyXtext2EcorePostProcessor through
postprocessor = MyXtext2EcorePostProcessor {} , but it seems not possible to use it anymore in MyGenerator.mwe2
So I'm a little bit confused. How it is possible to add a specific eAnnotation to some of my eClasses in my generated Ecore ?
Any help would be appreciated.
Best regards,
Axel Richard
Obeo
[Updated on: Wed, 25 March 2020 09:43] Report message to a moderator
|
|
|
|
Re: Add EAnnotation in generated Ecore [message #1823348 is a reply to message #1823343] |
Wed, 25 March 2020 10:47 |
Axel RICHARD Messages: 43 Registered: September 2010 Location: France |
Member |
|
|
Thank you Christian for your prompt answer.
I tried to do this:
public class MyCustomEcoreGenerator extends XtextGenerator {
public MyCustomEcoreGenerator() {
new XtextStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(new MyCustomEcoreXtextRuntimeModule());
}
}.createInjectorAndDoEMFRegistration();
}
private class MyCustomEcoreXtextRuntimeModule extends XtextRuntimeModule {
@Override
public void configureIXtext2EcorePostProcessor(Binder binder) {
binder.bind(IXtext2EcorePostProcessor.class).to(MyXtext2EcorePostProcessor.class);
}
}
}
----
class MyXtext2EcorePostProcessor implements IXtext2EcorePostProcessor {
...
}
and it does the trick !
Best regards,
Axel Richard
Obeo
[Updated on: Wed, 25 March 2020 10:56] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02831 seconds