Search in sources :

Example 6 with Xtext2EcoreTransformer

use of org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testPostProcessorHook.

@Test
public void testPostProcessorHook() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore  generate test \'http://test\' MyRule: myFeature=INT;");
    final String xtextGrammar = _builder.toString();
    EObject _model = this.getModel(xtextGrammar);
    final Grammar grammar = ((Grammar) _model);
    final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
    AbstractMetamodelDeclaration _get = grammar.getMetamodelDeclarations().get(1);
    GeneratedMetamodel testMetamodel = ((GeneratedMetamodel) _get);
    final Xtext2EcoreTransformerTest.MockedXtext2EcorePostProcessor postProcessor = new Xtext2EcoreTransformerTest.MockedXtext2EcorePostProcessor(testMetamodel);
    transformer.setPostProcessor(postProcessor);
    transformer.transform();
    Assert.assertEquals("process mthde called once", 1, postProcessor.proccessMethCalled());
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) Test(org.junit.Test)

Example 7 with Xtext2EcoreTransformer

use of org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method doGetResource.

@Override
public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception {
    XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
    rs.setClasspathURIContext(this.getClass());
    Resource _createResource = this.getResourceFactory().createResource(uri);
    final XtextResource resource = ((XtextResource) _createResource);
    rs.getResources().add(resource);
    XtextLinker linker = new XtextLinker() {

        @Override
        protected Xtext2EcoreTransformer createTransformer(final Grammar grammar, final IDiagnosticConsumer consumer) {
            Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer);
            ErrorAcceptor _errorAcceptor = result.getErrorAcceptor();
            Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor, Xtext2EcoreTransformerTest.this.errorAcceptorMock);
            result.setErrorAcceptor(_myErrorAcceptor);
            return result;
        }
    };
    ILinker _linker = resource.getLinker();
    linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider());
    ILinker _linker_1 = resource.getLinker();
    linker.setLinkingService(((Linker) _linker_1).getLinkingService());
    ILinker _linker_2 = resource.getLinker();
    linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper());
    XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover();
    linker.setPackageRemover(_packageRemover);
    LinkingDiagnosticMessageProvider _linkingDiagnosticMessageProvider = new LinkingDiagnosticMessageProvider();
    linker.setDiagnosticMessageProvider(_linkingDiagnosticMessageProvider);
    OnChangeEvictingCache _onChangeEvictingCache = new OnChangeEvictingCache();
    linker.setCache(_onChangeEvictingCache);
    resource.setLinker(linker);
    resource.load(in, null);
    return resource;
}
Also used : ILinker(org.eclipse.xtext.linking.ILinker) XtextLinker(org.eclipse.xtext.xtext.XtextLinker) Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) TestErrorAcceptor(org.eclipse.xtext.tests.TestErrorAcceptor) ErrorAcceptor(org.eclipse.xtext.xtext.ecoreInference.ErrorAcceptor) IDiagnosticConsumer(org.eclipse.xtext.diagnostics.IDiagnosticConsumer) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)

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