Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Add EAnnotation in generated Ecore
Add EAnnotation in generated Ecore [message #1823342] Wed, 25 March 2020 05:41 Go to next message
Eclipse UserFriend
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,

[Updated on: Wed, 25 March 2020 05:43] by Moderator

Re: Add EAnnotation in generated Ecore [message #1823343 is a reply to message #1823342] Wed, 25 March 2020 05:43 Go to previous messageGo to next message
Eclipse UserFriend
overrding
org.eclipse.xtext.XtextRuntimeModule.configureIXtext2EcorePostProcessor(Binder)
and do a binding there should do the trick
Re: Add EAnnotation in generated Ecore [message #1823348 is a reply to message #1823343] Wed, 25 March 2020 06:47 Go to previous message
Eclipse UserFriend
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,

[Updated on: Wed, 25 March 2020 06:56] by Moderator

Previous Topic:formatter generatestub problem
Next Topic:Maven dependencies
Goto Forum:
  


Current Time: Tue Jul 08 18:54:33 EDT 2025

Powered by FUDForum. Page generated in 0.30394 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top