Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » language inheritance and Xbase
language inheritance and Xbase [message #1702769] Fri, 24 July 2015 13:53 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
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


Re: language inheritance and Xbase [message #1703334 is a reply to message #1702769] Thu, 30 July 2015 17:03 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
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
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: language inheritance and Xbase [message #1703382 is a reply to message #1703334] Fri, 31 July 2015 08:26 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
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


Previous Topic:Combining Xtext with GMF
Next Topic:Newbie Grammar Question - Quoted Attribute List
Goto Forum:
  


Current Time: Fri Apr 26 18:13:52 GMT 2024

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

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

Back to the top