diff options
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/test/xtext-gen/org/eclipse/viatra')
-rw-r--r-- | org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/test/xtext-gen/org/eclipse/viatra/solver/language/tests/ProblemInjectorProvider.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/test/xtext-gen/org/eclipse/viatra/solver/language/tests/ProblemInjectorProvider.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/test/xtext-gen/org/eclipse/viatra/solver/language/tests/ProblemInjectorProvider.java new file mode 100644 index 00000000..7d0ef1bb --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/test/xtext-gen/org/eclipse/viatra/solver/language/tests/ProblemInjectorProvider.java | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.26.0.M1 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.tests; | ||
5 | |||
6 | import com.google.inject.Guice; | ||
7 | import com.google.inject.Injector; | ||
8 | import org.eclipse.viatra.solver.language.ProblemRuntimeModule; | ||
9 | import org.eclipse.viatra.solver.language.ProblemStandaloneSetup; | ||
10 | import org.eclipse.xtext.testing.GlobalRegistries; | ||
11 | import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; | ||
12 | import org.eclipse.xtext.testing.IInjectorProvider; | ||
13 | import org.eclipse.xtext.testing.IRegistryConfigurator; | ||
14 | |||
15 | public class ProblemInjectorProvider implements IInjectorProvider, IRegistryConfigurator { | ||
16 | |||
17 | protected GlobalStateMemento stateBeforeInjectorCreation; | ||
18 | protected GlobalStateMemento stateAfterInjectorCreation; | ||
19 | protected Injector injector; | ||
20 | |||
21 | static { | ||
22 | GlobalRegistries.initializeDefaults(); | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public Injector getInjector() { | ||
27 | if (injector == null) { | ||
28 | this.injector = internalCreateInjector(); | ||
29 | stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState(); | ||
30 | } | ||
31 | return injector; | ||
32 | } | ||
33 | |||
34 | protected Injector internalCreateInjector() { | ||
35 | return new ProblemStandaloneSetup() { | ||
36 | @Override | ||
37 | public Injector createInjector() { | ||
38 | return Guice.createInjector(createRuntimeModule()); | ||
39 | } | ||
40 | }.createInjectorAndDoEMFRegistration(); | ||
41 | } | ||
42 | |||
43 | protected ProblemRuntimeModule createRuntimeModule() { | ||
44 | // make it work also with Maven/Tycho and OSGI | ||
45 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672 | ||
46 | return new ProblemRuntimeModule() { | ||
47 | @Override | ||
48 | public ClassLoader bindClassLoaderToInstance() { | ||
49 | return ProblemInjectorProvider.class | ||
50 | .getClassLoader(); | ||
51 | } | ||
52 | }; | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public void restoreRegistry() { | ||
57 | stateBeforeInjectorCreation.restoreGlobalState(); | ||
58 | stateBeforeInjectorCreation = null; | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public void setupRegistry() { | ||
63 | stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState(); | ||
64 | if (injector == null) { | ||
65 | getInjector(); | ||
66 | } | ||
67 | stateAfterInjectorCreation.restoreGlobalState(); | ||
68 | } | ||
69 | } | ||