2021-11-30 17:25:45 +00:00
|
|
|
/*
|
|
|
|
* generated by Xtext 2.23.0
|
|
|
|
*/
|
2021-12-03 07:37:31 +00:00
|
|
|
package fr.n7.tests;
|
2021-11-30 17:25:45 +00:00
|
|
|
|
|
|
|
import com.google.inject.Guice;
|
|
|
|
import com.google.inject.Injector;
|
2021-12-03 07:37:31 +00:00
|
|
|
import fr.n7.GAMERuntimeModule;
|
|
|
|
import fr.n7.GAMEStandaloneSetup;
|
2021-11-30 17:25:45 +00:00
|
|
|
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;
|
|
|
|
|
2021-12-03 07:37:31 +00:00
|
|
|
public class GAMEInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
|
2021-11-30 17:25:45 +00:00
|
|
|
|
|
|
|
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() {
|
2021-12-03 07:37:31 +00:00
|
|
|
return new GAMEStandaloneSetup() {
|
2021-11-30 17:25:45 +00:00
|
|
|
@Override
|
|
|
|
public Injector createInjector() {
|
|
|
|
return Guice.createInjector(createRuntimeModule());
|
|
|
|
}
|
|
|
|
}.createInjectorAndDoEMFRegistration();
|
|
|
|
}
|
|
|
|
|
2021-12-03 07:37:31 +00:00
|
|
|
protected GAMERuntimeModule createRuntimeModule() {
|
2021-11-30 17:25:45 +00:00
|
|
|
// make it work also with Maven/Tycho and OSGI
|
|
|
|
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672
|
2021-12-03 07:37:31 +00:00
|
|
|
return new GAMERuntimeModule() {
|
2021-11-30 17:25:45 +00:00
|
|
|
@Override
|
|
|
|
public ClassLoader bindClassLoaderToInstance() {
|
2021-12-03 07:37:31 +00:00
|
|
|
return GAMEInjectorProvider.class
|
2021-11-30 17:25:45 +00:00
|
|
|
.getClassLoader();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restoreRegistry() {
|
|
|
|
stateBeforeInjectorCreation.restoreGlobalState();
|
|
|
|
stateBeforeInjectorCreation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setupRegistry() {
|
|
|
|
stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
|
|
|
|
if (injector == null) {
|
|
|
|
getInjector();
|
|
|
|
}
|
|
|
|
stateAfterInjectorCreation.restoreGlobalState();
|
|
|
|
}
|
|
|
|
}
|