Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Add EAnnotation in generated Ecore
Add EAnnotation in generated Ecore [message #1823342] Wed, 25 March 2020 09:41 Go to next message
Axel RICHARD is currently offline Axel RICHARDFriend
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 #1823343 is a reply to message #1823342] Wed, 25 March 2020 09:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
overrding
org.eclipse.xtext.XtextRuntimeModule.configureIXtext2EcorePostProcessor(Binder)
and do a binding there should do the trick


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Add EAnnotation in generated Ecore [message #1823348 is a reply to message #1823343] Wed, 25 March 2020 10:47 Go to previous message
Axel RICHARD is currently offline Axel RICHARDFriend
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

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


Current Time: Tue Apr 23 10:59:12 GMT 2024

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

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

Back to the top