use of org.eclipse.xtext.XtextRuntimeModule in project xtext-core by eclipse.
the class AbstractGeneratorFragmentTests method initializeFragmentWithGrammarFromString.
public <T extends AbstractXtextGeneratorFragment> T initializeFragmentWithGrammarFromString(final Class<T> fragmentClass, final String grammarString) {
try {
final XtextResource resource = this.getResourceFromString(grammarString);
EObject _head = IterableExtensions.<EObject>head(resource.getContents());
final Grammar grammar = ((Grammar) _head);
XtextRuntimeModule _xtextRuntimeModule = new XtextRuntimeModule();
AbstractGeneratorFragmentTests.FragmentGeneratorModule _fragmentGeneratorModule = new AbstractGeneratorFragmentTests.FragmentGeneratorModule(grammar);
final Injector generatorInjector = Guice.createInjector(Modules2.mixin(_xtextRuntimeModule, _fragmentGeneratorModule));
final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
transformer.transform();
final AbstractGeneratorFragmentTests.FakeEMFGeneratorFragment2 emfGeneratorFragment = generatorInjector.<AbstractGeneratorFragmentTests.FakeEMFGeneratorFragment2>getInstance(AbstractGeneratorFragmentTests.FakeEMFGeneratorFragment2.class);
emfGeneratorFragment.initialize(generatorInjector);
emfGeneratorFragment.getSaveAndReconcileGenModel(grammar, transformer.getGeneratedPackages(), resource.getResourceSet());
return generatorInjector.<T>getInstance(fragmentClass);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations