Search in sources :

Example 1 with Xtext2EcoreTransformer

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);
    }
}
Also used : Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Grammar(org.eclipse.xtext.Grammar)

Example 2 with Xtext2EcoreTransformer

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"));
}
Also used : Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) TypeRef(org.eclipse.xtext.TypeRef) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) AbstractRule(org.eclipse.xtext.AbstractRule) EClassifierInfos(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfos) ReferencedMetamodel(org.eclipse.xtext.ReferencedMetamodel) Test(org.junit.Test)

Example 3 with Xtext2EcoreTransformer

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);
    }
}
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)

Example 4 with Xtext2EcoreTransformer

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;
}
Also used : TransformationDiagnosticsProducer(org.eclipse.xtext.xtext.ecoreInference.TransformationDiagnosticsProducer) Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer)

Example 5 with Xtext2EcoreTransformer

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);
}
Also used : Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) TestErrorAcceptor(org.eclipse.xtext.tests.TestErrorAcceptor)

Aggregations

Xtext2EcoreTransformer (org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer)7 Grammar (org.eclipse.xtext.Grammar)5 EObject (org.eclipse.emf.ecore.EObject)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 TestErrorAcceptor (org.eclipse.xtext.tests.TestErrorAcceptor)2 Test (org.junit.Test)2 Injector (com.google.inject.Injector)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)1 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)1 TypeRef (org.eclipse.xtext.TypeRef)1 XtextRuntimeModule (org.eclipse.xtext.XtextRuntimeModule)1 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)1 IDiagnosticConsumer (org.eclipse.xtext.diagnostics.IDiagnosticConsumer)1 ILinker (org.eclipse.xtext.linking.ILinker)1 LinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1