70 lines
1.8 KiB
Java
70 lines
1.8 KiB
Java
|
/*
|
||
|
* generated by Xtext 2.23.0
|
||
|
*/
|
||
|
package fr.n7.tests;
|
||
|
|
||
|
import com.google.inject.Guice;
|
||
|
import com.google.inject.Injector;
|
||
|
import fr.n7.PDL2RuntimeModule;
|
||
|
import fr.n7.PDL2StandaloneSetup;
|
||
|
import org.eclipse.xtext.testing.GlobalRegistries;
|
||
|
import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento;
|
||
|
import org.eclipse.xtext.testing.IInjectorProvider;
|
||
|
import org.eclipse.xtext.testing.IRegistryConfigurator;
|
||
|
|
||
|
public class PDL2InjectorProvider implements IInjectorProvider, IRegistryConfigurator {
|
||
|
|
||
|
protected GlobalStateMemento stateBeforeInjectorCreation;
|
||
|
protected GlobalStateMemento stateAfterInjectorCreation;
|
||
|
protected Injector injector;
|
||
|
|
||
|
static {
|
||
|
GlobalRegistries.initializeDefaults();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Injector getInjector() {
|
||
|
if (injector == null) {
|
||
|
this.injector = internalCreateInjector();
|
||
|
stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
|
||
|
}
|
||
|
return injector;
|
||
|
}
|
||
|
|
||
|
protected Injector internalCreateInjector() {
|
||
|
return new PDL2StandaloneSetup() {
|
||
|
@Override
|
||
|
public Injector createInjector() {
|
||
|
return Guice.createInjector(createRuntimeModule());
|
||
|
}
|
||
|
}.createInjectorAndDoEMFRegistration();
|
||
|
}
|
||
|
|
||
|
protected PDL2RuntimeModule createRuntimeModule() {
|
||
|
// make it work also with Maven/Tycho and OSGI
|
||
|
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672
|
||
|
return new PDL2RuntimeModule() {
|
||
|
@Override
|
||
|
public ClassLoader bindClassLoaderToInstance() {
|
||
|
return PDL2InjectorProvider.class
|
||
|
.getClassLoader();
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void restoreRegistry() {
|
||
|
stateBeforeInjectorCreation.restoreGlobalState();
|
||
|
stateBeforeInjectorCreation = null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setupRegistry() {
|
||
|
stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
|
||
|
if (injector == null) {
|
||
|
getInjector();
|
||
|
}
|
||
|
stateAfterInjectorCreation.restoreGlobalState();
|
||
|
}
|
||
|
}
|