Search in sources :

Example 1 with Registry

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

the class TraceEditor method updateText.

protected void updateText(EObject obj) {
    DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
    if (region == null) {
        text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
        return;
    }
    final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
    SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
    if (sourceURI == null) {
        text.setText("Could not find associated URI");
        return;
    }
    Registry registry = IResourceServiceProvider.Registry.INSTANCE;
    IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
    URI traceURI = obj.eResource().getURI();
    IStorage localStorage = getLocalStorage(serviceProvider, traceURI);
    StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
    traceProvider.setLocalStorage(localStorage);
    traceProvider.setTraceToSource(true);
    traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {

        @Override
        public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
            return trace;
        }
    });
    String newText = traceProvider.toString();
    text.setText(newText);
}
Also used : StorageAwareTrace(org.eclipse.xtext.ui.generator.trace.StorageAwareTrace) Registry(org.eclipse.xtext.resource.IResourceServiceProvider.Registry) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Example 2 with Registry

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

the class ResourceServiceProviderProviderTest method testResourceServiceProviderProvider.

@Test
public void testResourceServiceProviderProvider() {
    String contenttype = "mycontent";
    String ext = "TestResourceServiceProviderProvider";
    URI uri = URI.createFileURI("foofile." + ext);
    Registry registry = IResourceServiceProvider.Registry.INSTANCE;
    // the file extension is registered via plugin.xml
    IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri, contenttype);
    Assert.assertTrue(resourceServiceProvider instanceof TestResourceServiceProvider);
    TestResourceServiceProvider provider = (TestResourceServiceProvider) resourceServiceProvider;
    Assert.assertEquals(uri, provider.uri);
    Assert.assertEquals(contenttype, provider.contentType);
}
Also used : Registry(org.eclipse.xtext.resource.IResourceServiceProvider.Registry) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 3 with Registry

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

the class ResourceServiceProviderProviderTest method testResourceServiceProviderProviderWithExecutableExtensionFactory.

@Test
public void testResourceServiceProviderProviderWithExecutableExtensionFactory() {
    String contenttype = "mycontent";
    String ext = "TestResourceServiceProviderExecutableExtensionFactory";
    URI uri = URI.createFileURI("foofile." + ext);
    Registry registry = IResourceServiceProvider.Registry.INSTANCE;
    // the file extension is registered via plugin.xml
    IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri, contenttype);
    Assert.assertTrue(resourceServiceProvider instanceof TestResourceServiceProvider);
    TestResourceServiceProvider provider = (TestResourceServiceProvider) resourceServiceProvider;
    Assert.assertEquals(uri, provider.uri);
    Assert.assertEquals(contenttype, provider.contentType);
}
Also used : Registry(org.eclipse.xtext.resource.IResourceServiceProvider.Registry) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 4 with Registry

use of org.eclipse.xtext.resource.IResourceServiceProvider.Registry in project smarthome by eclipse.

the class RegistryProvider method createRegistry.

private Registry createRegistry() {
    registerDefaultFactories();
    IResourceServiceProvider.Registry registry = new ResourceServiceProviderRegistryImpl();
    register(registry, new ItemsIdeSetup().createInjector());
    register(registry, new PersistenceIdeSetup().createInjector());
    register(registry, new RulesIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine).createInjector());
    register(registry, new ScriptIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine).createInjector());
    register(registry, new SitemapIdeSetup().createInjector());
    register(registry, new ThingIdeSetup().createInjector());
    return registry;
}
Also used : RulesIdeSetup(org.eclipse.smarthome.model.rule.ide.RulesIdeSetup) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) ItemsIdeSetup(org.eclipse.smarthome.model.ide.ItemsIdeSetup) PersistenceIdeSetup(org.eclipse.smarthome.model.persistence.ide.PersistenceIdeSetup) Registry(org.eclipse.xtext.resource.IResourceServiceProvider.Registry) ResourceServiceProviderRegistryImpl(org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl) SitemapIdeSetup(org.eclipse.smarthome.model.ide.SitemapIdeSetup) ThingIdeSetup(org.eclipse.smarthome.model.thing.ide.ThingIdeSetup) ScriptIdeSetup(org.eclipse.smarthome.model.script.ide.ScriptIdeSetup)

Aggregations

Registry (org.eclipse.xtext.resource.IResourceServiceProvider.Registry)4 URI (org.eclipse.emf.common.util.URI)3 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)2 Test (org.junit.Test)2 IStorage (org.eclipse.core.resources.IStorage)1 ItemsIdeSetup (org.eclipse.smarthome.model.ide.ItemsIdeSetup)1 SitemapIdeSetup (org.eclipse.smarthome.model.ide.SitemapIdeSetup)1 PersistenceIdeSetup (org.eclipse.smarthome.model.persistence.ide.PersistenceIdeSetup)1 RulesIdeSetup (org.eclipse.smarthome.model.rule.ide.RulesIdeSetup)1 ScriptIdeSetup (org.eclipse.smarthome.model.script.ide.ScriptIdeSetup)1 ThingIdeSetup (org.eclipse.smarthome.model.thing.ide.ThingIdeSetup)1 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)1 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)1 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)1 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)1 ResourceServiceProviderRegistryImpl (org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl)1 StorageAwareTrace (org.eclipse.xtext.ui.generator.trace.StorageAwareTrace)1