Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » EMF registries and guice injection
EMF registries and guice injection [message #1746900] Mon, 07 November 2016 13:32 Go to next message
Jason Pell is currently offline Jason PellFriend
Messages: 55
Registered: February 2011
Member
I am having a few issues with validators that extend AbstractDeclarativeValidator not being isolated to a particular guice injector.

Is there a way to completely isolate validators to an injector. I am wondering if somehow I can create a Diagnostician with a EValidator.Registry that I create myself that is scoped to a single instance of the injector.

Reason I ask is I am trying to do some unit tests loading and validating my DSL files and some of my validators actually behave differently based on how they are configured.

The configuration object is @Injected into the validator, but it does not seem to be the same configuration I would expect, I think this means that the validator was created already added to this global EValidator.Registry.INSTANCE and does not actyually use the same configuration object as the current injector (an earlier injector maybe the one created just before the validator was first called, I don't know)

I know I could force the issue by clearing out this global registry in @Before, but I would prefer to see if I can get the validators to be created and isolated to the current injector instead.

Is it possible to create a diagnostician with a validator registry that I can force to be created in the injector.

I found the org.eclipse.xtext.validation.EValidatorRegistrar

But I can't figure out how the setRegistry gets called..

[Updated on: Mon, 07 November 2016 13:37]

Report message to a moderator

Re: EMF registries and guice injection [message #1746954 is a reply to message #1746900] Tue, 08 November 2016 02:21 Go to previous message
Jason Pell is currently offline Jason PellFriend
Messages: 55
Registered: February 2011
Member
Ok so I updated the RuntimeModule to define a guice controlled registry instead of the EMF global one. For unit tests it works a treat, I suspect this is going to cause some serious issues when I run the eclipse plugins, but I guess I can have a RuntimeModule specifically for test cases if I need to.

@Override
public org.eclipse.emf.ecore.EValidator.Registry bindEValidatorRegistry() {
return new MyEvalidatorRegistry();
}

public class MyEvalidatorRegistry extends org.eclipse.emf.ecore.impl.EValidatorRegistryImpl {
}


I created a Diagnostician via Guice injecting the EValidator.Registry and used that to programmatically do validation and all my validation tests passed (I disabled the sledge hammer global registries reset code)

Before I had added the sledge hammer code some tests would fail because the configuration object was not the same object as the current injector I was using, now it is because the validators are all created and added to the guice controlled evalidator registry.

[Updated on: Tue, 08 November 2016 02:24]

Report message to a moderator

Previous Topic:[Xtext] Formatter2 usage when programmatically save Xtext resource
Next Topic:Using ResourceFactory without depending in UI project
Goto Forum:
  


Current Time: Sat Apr 20 04:40:48 GMT 2024

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

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

Back to the top