Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Dependency injection of ResourceDescriptionsProvider failed
Dependency injection of ResourceDescriptionsProvider failed [message #1856223] Mon, 28 November 2022 14:21 Go to next message
Adrian M is currently offline Adrian MFriend
Messages: 4
Registered: November 2022
Junior Member
Hey everyone,

Im trying to inject the ResourceDescriptionsProvider via Google Guice to obtain the contents of all files of my Xtext language in the project. Unfortunately the injection doesn't work as expected. The ResourceDescriptionsProvider remains null. I also tried to bind the IWorkbench and inject it manually, but that only gives me a ResourceDescriptionsProvider with all internal fields set to null. May somebody have a hint how to solve this?

Kind regards,
Adrian
Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856234 is a reply to message #1856223] Tue, 29 November 2022 04:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14434
Registered: July 2009
Senior Member
Hi, can you please give more details. what and what do you bind, inject, what is null etc.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 29 November 2022 07:51]

Report message to a moderator

Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856243 is a reply to message #1856234] Tue, 29 November 2022 11:51 Go to previous messageGo to next message
Adrian M is currently offline Adrian MFriend
Messages: 4
Registered: November 2022
Junior Member
I inject ResourceDescriptionsProvider as follows:
@Inject
ResourceDescriptionsProvider resourceDescriptionsProvider;

It is located in a class which I instanciate while I'm in a @Check-method of my validator.
With only this, no ResourceDescriptionsProvider will be injected and the field resourceDescriptionsProvider remains null.

Next, I added the following to the configure method of the RuntimeModule of my language:
@Override
public void configure(Binder binder) {
    super.configure(binder);
    binder.bind(IResourceDescriptionsProvider.class).to(ResourceDescriptionsProvider.class);
}

This changed nothing (resourceDescriptionsProvider remained null).

Another try was to inject ResourceDescriptionsProvider manually by creating an Injector:
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
    protected void configure() {
        bind(IResourceDescriptionsProvider.class).to(ResourceDescriptionsProvider.class);
    }
});
resourceDescriptionsProvider = injector.getInstance(ResourceDescriptionsProvider.class);

After that, resourceDescriptionsProvider has been initialized but all inner fields of it are null.
I also tried the manual inject part with an additional binding of the workbench, which changed nothing:
bind(IWorkbench.class).toProvider(() -> PlatformUI.getWorkbench());
Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856244 is a reply to message #1856243] Tue, 29 November 2022 12:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14434
Registered: July 2009
Senior Member
you should inject
IResourceDescriptionsProvider


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856270 is a reply to message #1856244] Wed, 30 November 2022 11:42 Go to previous messageGo to next message
Adrian M is currently offline Adrian MFriend
Messages: 4
Registered: November 2022
Junior Member
I tried this but it did not help...
There is no change to the situation described above.
Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856272 is a reply to message #1856270] Wed, 30 November 2022 13:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14434
Registered: July 2009
Senior Member
can you please provide a reproducing unit test + project.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 30 November 2022 13:50]

Report message to a moderator

Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856368 is a reply to message #1856272] Wed, 07 December 2022 16:12 Go to previous messageGo to next message
Adrian M is currently offline Adrian MFriend
Messages: 4
Registered: November 2022
Junior Member
Sorry for the late reply.
Injecting the ResourceDescriptionsProvider directly as field of the language validator fixed the issue. Xtext probably cannot handle injections which are done outside of the module structure of Xtext.
Nevertheless, thank you for your help, Christian!
Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856370 is a reply to message #1856368] Wed, 07 December 2022 16:21 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14434
Registered: July 2009
Senior Member
please provide a reproducing unit test.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to customize generated eclass from a grammar?
Next Topic:Xcore and mwe2
Goto Forum:
  


Current Time: Sat Feb 04 17:03:11 GMT 2023

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

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

Back to the top