org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment Java Examples
The following examples show how to use
org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractGeneratorFragmentTests.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public <T extends AbstractXtextGeneratorFragment> T initializeFragmentWithGrammarFromStringWithXbase(final Class<T> fragmentClass, final String grammarString) { try { if ((this.rs == null)) { this.rs = this.<XtextResourceSet>get(XtextResourceSet.class); } StringConcatenation _builder = new StringConcatenation(); _builder.append("grammar org.eclipse.xtext.xbase.Xbase with org.eclipse.xtext.common.Terminals"); _builder.newLine(); _builder.append("import \"http://www.eclipse.org/emf/2002/Ecore\" as ecore"); _builder.newLine(); _builder.append("Model returns ecore::EClass : name=ID;"); _builder.newLine(); String _currentFileExtension = this.getCurrentFileExtension(); String _plus = ("fakeXbase." + _currentFileExtension); this.getResource(this.getAsStream(_builder.toString()), URI.createURI(_plus)); return this.<T>initializeFragmentWithGrammarFromString(fragmentClass, grammarString); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #2
Source File: AbstractGeneratorFragmentTests.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public <T extends AbstractXtextGeneratorFragment> T initializeFragmentWithGrammarFromString(final Class<T> fragmentClass, final String grammarString) { try { if ((this.rs == null)) { this.rs = this.<XtextResourceSet>get(XtextResourceSet.class); } 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()); AbstractGeneratorFragmentTests.lang.setResourceSet(resource.getResourceSet()); this.rs = null; return generatorInjector.<T>getInstance(fragmentClass); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }