Search in sources :

Example 1 with XtextRuntimeModule

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);
    }
}
Also used : Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) XtextRuntimeModule(org.eclipse.xtext.XtextRuntimeModule) Injector(com.google.inject.Injector) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

Injector (com.google.inject.Injector)1 EObject (org.eclipse.emf.ecore.EObject)1 Grammar (org.eclipse.xtext.Grammar)1 XtextRuntimeModule (org.eclipse.xtext.XtextRuntimeModule)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 Xtext2EcoreTransformer (org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer)1