4 package org.opendaylight.nemo.tool.eclipse.plugin;
6 import org.eclipse.xtext.junit4.GlobalRegistries;
7 import org.eclipse.xtext.junit4.GlobalRegistries.GlobalStateMemento;
8 import org.eclipse.xtext.junit4.IInjectorProvider;
9 import org.eclipse.xtext.junit4.IRegistryConfigurator;
11 import com.google.inject.Injector;
13 public class EditorInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
15 protected GlobalStateMemento stateBeforeInjectorCreation;
16 protected GlobalStateMemento stateAfterInjectorCreation;
17 protected Injector injector;
20 GlobalRegistries.initializeDefaults();
24 public Injector getInjector()
26 if (injector == null) {
27 stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
28 this.injector = internalCreateInjector();
29 stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
34 protected Injector internalCreateInjector() {
35 return new EditorStandaloneSetup().createInjectorAndDoEMFRegistration();
39 public void restoreRegistry() {
40 stateBeforeInjectorCreation.restoreGlobalState();
44 public void setupRegistry() {
46 stateAfterInjectorCreation.restoreGlobalState();