use of org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer in project xtext-core by eclipse.
the class XtextLinker method linkModel.
@Override
public void linkModel(EObject model, IDiagnosticConsumer consumer) {
if (model instanceof Grammar) {
final Xtext2EcoreTransformer transformer = createTransformer((Grammar) model, consumer);
// TODO duplicate
transformer.removeGeneratedPackages();
super.linkModel(model, consumer);
updateOverriddenRules((Grammar) model);
try {
transformer.transform();
} catch (Exception e) {
log.error(e.getMessage(), e);
consumer.consume(new ExceptionDiagnostic(e), Severity.ERROR);
}
if (!model.eResource().eAdapters().contains(packageRemover))
model.eResource().eAdapters().add(packageRemover);
} else {
super.linkModel(model, consumer);
}
}
use of org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method testTypesOfImplicitSuperGrammar.
@Test
public void testTypesOfImplicitSuperGrammar() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate test \'http://test\'");
_builder.newLine();
_builder.append("MyRule: myFeature=INT;");
_builder.newLine();
final String xtextGrammar = _builder.toString();
EObject _model = this.getModel(xtextGrammar);
final Grammar grammar = ((Grammar) _model);
final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
transformer.removeGeneratedPackages();
transformer.transform();
final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
TypeRef type = rule.getType();
Assert.assertNotNull(type);
Assert.assertNotNull(transformer.getEClassifierInfos().getInfo(type));
AbstractMetamodelDeclaration _get = GrammarUtil.allMetamodelDeclarations(grammar).get(1);
final ReferencedMetamodel referenced = ((ReferencedMetamodel) _get);
Assert.assertNotNull(referenced);
Assert.assertEquals("ecore", referenced.getAlias());
Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced, "EString"));
Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced, "EInt"));
EClassifierInfos parentInfos = IterableExtensions.<EClassifierInfos>head(transformer.getEClassifierInfos().getParents());
Assert.assertNotNull(parentInfos.getInfo(referenced, "EString"));
Assert.assertNotNull(parentInfos.getInfo(referenced, "EInt"));
}
use of org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer 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);
}
}
use of org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer in project xtext-core by eclipse.
the class XtextLinker method createTransformer.
protected Xtext2EcoreTransformer createTransformer(Grammar grammar, IDiagnosticConsumer consumer) {
final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
transformer.setErrorAcceptor(new TransformationDiagnosticsProducer(consumer));
transformer.setPostProcessor(postProcessor);
return transformer;
}
use of org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer in project xtext-core by eclipse.
the class MetamodelTransformationErrorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
with(XtextStandaloneSetup.class);
model = "grammar datatypetests with org.eclipse.xtext.common.Terminals\n" + "import 'http://www.eclipse.org/emf/2002/Ecore' as ecore\n" + "generate metamodel 'http://fooo'\n" + "Start:\n" + " id=ValidId id2=ValidId2 failure1=FailureId failure2=Failure2;\n" + "ValidId returns ecore::EString: ID '.' ID;\n" + "ValidId2 returns ecore::EString: ID '.' ValidId;\n" + "FailureId returns ecore::EString: name=ID;\n" + "Failure2 returns ecore::EString: name=Start;";
resource = getResourceFromStringAndExpect(model, 2);
grammar = (Grammar) resource.getContents().get(0);
transformer = new Xtext2EcoreTransformer(grammar);
errorAcceptor = new TestErrorAcceptor();
transformer.setErrorAcceptor(errorAcceptor);
}
Aggregations