mirror of
				https://github.com/Minres/RDL-Editor.git
				synced 2025-11-04 04:31:37 +00:00 
			
		
		
		
	Iniital checkin
This commit is contained in:
		@@ -0,0 +1,66 @@
 | 
			
		||||
/*
 | 
			
		||||
 * generated by Xtext 2.12.0
 | 
			
		||||
 */
 | 
			
		||||
package com.minres.rdl.tests;
 | 
			
		||||
 | 
			
		||||
import com.google.inject.Guice;
 | 
			
		||||
import com.google.inject.Injector;
 | 
			
		||||
import com.minres.rdl.RDLRuntimeModule;
 | 
			
		||||
import com.minres.rdl.RDLStandaloneSetup;
 | 
			
		||||
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 RDLInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
 | 
			
		||||
 | 
			
		||||
	protected GlobalStateMemento stateBeforeInjectorCreation;
 | 
			
		||||
	protected GlobalStateMemento stateAfterInjectorCreation;
 | 
			
		||||
	protected Injector injector;
 | 
			
		||||
 | 
			
		||||
	static {
 | 
			
		||||
		GlobalRegistries.initializeDefaults();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Injector getInjector() {
 | 
			
		||||
		if (injector == null) {
 | 
			
		||||
			stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
 | 
			
		||||
			this.injector = internalCreateInjector();
 | 
			
		||||
			stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
 | 
			
		||||
		}
 | 
			
		||||
		return injector;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected Injector internalCreateInjector() {
 | 
			
		||||
		return new RDLStandaloneSetup() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public Injector createInjector() {
 | 
			
		||||
				return Guice.createInjector(createRuntimeModule());
 | 
			
		||||
			}
 | 
			
		||||
		}.createInjectorAndDoEMFRegistration();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected RDLRuntimeModule createRuntimeModule() {
 | 
			
		||||
		// make it work also with Maven/Tycho and OSGI
 | 
			
		||||
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672
 | 
			
		||||
		return new RDLRuntimeModule() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public ClassLoader bindClassLoaderToInstance() {
 | 
			
		||||
				return RDLInjectorProvider.class
 | 
			
		||||
						.getClassLoader();
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void restoreRegistry() {
 | 
			
		||||
		stateBeforeInjectorCreation.restoreGlobalState();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void setupRegistry() {
 | 
			
		||||
		getInjector();
 | 
			
		||||
		stateAfterInjectorCreation.restoreGlobalState();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user