Search in sources :

Example 81 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class UriBasedReaderTest method testIssuesInOtherResource.

@Test
public void testIssuesInOtherResource() throws Exception {
    UriBasedReader reader = new UriBasedReader() {

        {
            getValidator().setStopOnError(false);
        }
    };
    reader.setClasspathURIContext(getClass());
    reader.addRegister(new XtextStandaloneSetup() {

        @Override
        public Injector createInjector() {
            return Guice.createInjector(new org.eclipse.xtext.XtextRuntimeModule() {

                @Override
                public void configureFileExtensions(Binder binder) {
                    binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("xtexterror");
                }
            });
        }

        @Override
        public void register(Injector injector) {
            EPackage.Registry.INSTANCE.put(XtextPackage.eINSTANCE.getNsURI(), XtextPackage.eINSTANCE);
            IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
            IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
            Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", resourceFactory);
            IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", serviceProvider);
        }
    });
    final String errorURI = (getClass().getName() + "ResourceWithError").replace('.', '/') + ".xtexterror";
    final String loadingURI = "classpath:/" + (getClass().getName() + "LoadingResourceWithError").replace('.', '/') + ".xtexterror";
    reader.addUri(loadingURI);
    SlotEntry slotEntry = new SlotEntry();
    slotEntry.setType("Grammar");
    slotEntry.setFirstOnly(true);
    reader.addLoad(slotEntry);
    WorkflowContextDefaultImpl ctx = new WorkflowContextDefaultImpl();
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    assertFalse(issues.toString(), issues.hasErrors());
    reader.invoke(ctx, new NullProgressMonitor(), issues);
    assertTrue(ctx.get(slotEntry.getSlot()) instanceof Grammar);
    assertEquals(1, issues.getErrors().length);
    final String errorString = issues.getErrors()[0].toString();
    assertFalse(errorString, errorString.contains(loadingURI));
    assertTrue(errorString, errorString.contains(errorURI));
}
Also used : NullProgressMonitor(org.eclipse.emf.mwe.core.monitor.NullProgressMonitor) WorkflowContextDefaultImpl(org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl) Grammar(org.eclipse.xtext.Grammar) Binder(com.google.inject.Binder) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Injector(com.google.inject.Injector) IssuesImpl(org.eclipse.emf.mwe.core.issues.IssuesImpl) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory) XtextStandaloneSetup(org.eclipse.xtext.XtextStandaloneSetup) Test(org.junit.Test)

Example 82 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class XtextGenerator method initializeEncoding.

protected void initializeEncoding() {
    IResourceServiceProvider.Registry serviceProviderRegistry = IResourceServiceProvider.Registry.INSTANCE;
    IResourceServiceProvider serviceProvider = (IResourceServiceProvider) serviceProviderRegistry.getExtensionToFactoryMap().get("xtext");
    String encoding = null;
    if (grammarEncoding != null) {
        encoding = grammarEncoding;
    } else {
        encoding = configuration.getCode().getEncoding();
    }
    if (serviceProvider != null && encoding != null) {
        IEncodingProvider encodingProvider = serviceProvider.get(IEncodingProvider.class);
        if (encodingProvider instanceof IEncodingProvider.Runtime) {
            ((IEncodingProvider.Runtime) encodingProvider).setDefaultEncoding(encoding);
        }
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IEncodingProvider(org.eclipse.xtext.parser.IEncodingProvider)

Example 83 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class WrappingInjectorProvider method registerFactory.

private void registerFactory(Injector injector) {
    IResourceFactory factory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    FileExtensionProvider fileExtensionProvider = injector.getInstance(FileExtensionProvider.class);
    for (String ext : fileExtensionProvider.getFileExtensions()) {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(ext, factory);
        IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put(ext, serviceProvider);
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) FileExtensionProvider(org.eclipse.xtext.resource.FileExtensionProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Example 84 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class EnumAndReferenceTestLanguageStandaloneSetupGenerated method register.

public void register(Injector injector) {
    IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("enumandreferencetestlanguage", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("enumandreferencetestlanguage", serviceProvider);
    if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2009/tmf/xtext/EnumAndReferenceTest")) {
        EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2009/tmf/xtext/EnumAndReferenceTest", EnumAndReferenceTestLanguagePackage.eINSTANCE);
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Example 85 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class MultiRuleEnumTestLanguageStandaloneSetupGenerated method register.

public void register(Injector injector) {
    IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("multiruleenumtestlanguage", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("multiruleenumtestlanguage", serviceProvider);
    if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2009/tmf/xtext/MultiRuleEnums")) {
        EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2009/tmf/xtext/MultiRuleEnums", MultiRuleenumsPackage.eINSTANCE);
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Aggregations

IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)267 IResourceFactory (org.eclipse.xtext.resource.IResourceFactory)190 URI (org.eclipse.emf.common.util.URI)25 Resource (org.eclipse.emf.ecore.resource.Resource)21 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)20 XtextResource (org.eclipse.xtext.resource.XtextResource)13 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)10 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)5 IResource (org.eclipse.core.resources.IResource)5 EObject (org.eclipse.emf.ecore.EObject)5 Manager (org.eclipse.xtext.resource.IResourceDescription.Manager)5 Issue (org.eclipse.xtext.validation.Issue)5 Injector (com.google.inject.Injector)4 IProject (org.eclipse.core.resources.IProject)4 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)4