Search code examples
xtextemf

Xtext: Create an EMF Resource on the fly


for reasons, i need to create a non-persistent EMF resource within the Scoping. So i would like to get hold of the ResourceSet that my Language uses. But i need to get it not in the UI project but the main project.

i tried to get it in my ScopeProvider class with

@Inject ResourceSet
@Inject Provider<ResourceSet>
@Inject IResourceFactory

However, none of these ever get injected (stay null) although in the DefaultRuntimeModule, there are indeed bindings for at least ResourceSet and IResourceFactory. I use Xtext 2.5.1.

I would also accept other ways to create an EMF Resource on the fly

Regards,

clericc


Solution

  • You can try

    @Inject Provider<XtextResourceSet> resourceSetProvider;
    

    Also don't forget to execute <YourLanguage>StandaloneSetup.doSetup() in your non-ui app to initialize emf registries and make all your classes injected properly.