language inheritance and Xbase [message #1702769] |
Fri, 24 July 2015 13:53 |
|
Hi
Say that I have an extension of Xbase, call it XB1, with a new
expression, and thus, with a custom type computer and custom xbase
compiler handling the new expression, and then are specified in the
runtime module.
Now I define a new language XB2 which inherits from XB1. I just
realized that the runtime module for XB2 does not inherit from the one
of XB1, so the bindings for the xbase compiler and the xbase type
computer must be explicitly redefined in the runtime module of XB2.
I guess this manual specification in the runtime module cannot be
avoided, can it?
thanks in advance
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
Re: language inheritance and Xbase [message #1703382 is a reply to message #1703334] |
Fri, 31 July 2015 08:26 |
|
On 30/07/2015 19:03, Sebastian Zarnekow wrote:
> Hi Lorenzo,
>
> there is no built-in facility to avoid that. You could extract the
> necessary bindings into an own module and call that one from all your
> runtime modules by means of binder.install(..)
>
> Best,
> Sebastian
Hi Sebastian
thanks for the suggestion, but that won't work for bindings that have
already been defined in the generated abstract runtime module...
If I understand correctly what you're suggesting, you say (recall XB2
inherits from XB1 which has some custom Xbase classes, like type
computer, compiler, etc, that I want XB2 to reuse):
public class XB2RuntimeModule extends
xjbase.example.purexjbase.AbstractXB2RuntimeModule {
@Override
public void configure(Binder binder) {
super.configure(binder);
binder.install(new XB1InstallableRuntimeModule());
}
}
where XB1InstallableRuntimeModule has bindings of the shape
public Class<? extends IGenerator> bindIGenerator() {
return XB1JvmModelGenerator.class;
}
public Class<? extends XbaseCompiler> bindXbaseCompiler() {
return XB1XbaseCompiler.class;
}
is that right?
So XB1InstallableRuntimeModule has only the bindings for the Xbase
custom components.
Unfortunately this will generate runtime errors since Guice will
complain that a binding for IGenerator is already defined (indeed it's
in the AbstractXB2RuntimeModule), while it works for bindXbaseCompiler
since there's no explicit binding for that.
As an alternative solution I override XB2StandaloneSetup.createInjector
as follows
@Override
public Injector createInjector() {
return Guice.createInjector(
Modules2.mixin(
new XB2RuntimeModule(),
new XB1InstallableRuntimeModule()));
}
and this works! :)
Does this make sense?
thanks in advance
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Powered by
FUDForum. Page generated in 0.03748 seconds