Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Dependency injection of ResourceDescriptionsProvider failed
Dependency injection of ResourceDescriptionsProvider failed [message #1856223] Mon, 28 November 2022 09:21 Go to next message
Eclipse UserFriend
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] Mon, 28 November 2022 23:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi, can you please give more details. what and what do you bind, inject, what is null etc.

[Updated on: Tue, 29 November 2022 02:51] by Moderator

Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856243 is a reply to message #1856234] Tue, 29 November 2022 06:51 Go to previous messageGo to next message
Eclipse UserFriend
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 07:22 Go to previous messageGo to next message
Eclipse UserFriend
you should inject
IResourceDescriptionsProvider
Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856270 is a reply to message #1856244] Wed, 30 November 2022 06:42 Go to previous messageGo to next message
Eclipse UserFriend
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 08:50 Go to previous messageGo to next message
Eclipse UserFriend
can you please provide a reproducing unit test + project.

[Updated on: Wed, 30 November 2022 08:50] by Moderator

Re: Dependency injection of ResourceDescriptionsProvider failed [message #1856368 is a reply to message #1856272] Wed, 07 December 2022 11:12 Go to previous messageGo to next message
Eclipse UserFriend
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 11:21 Go to previous message
Eclipse UserFriend
please provide a reproducing unit test.
Previous Topic:How to customize generated eclass from a grammar?
Next Topic:Xcore and mwe2
Goto Forum:
  


Current Time: Thu Mar 20 15:34:53 EDT 2025

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

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

Back to the top