Search in sources :

Example 56 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project dsl-devkit by dsldevkit.

the class ResourceServiceProviderLocator method getResourceServiceProviderById.

/**
 * Finds the {@link IResourceServiceProvider} for a language by given its id.
 *
 * @param languageId
 *          the language id (grammar name)
 * @return the {@link IResourceServiceProvider} for the given language id
 */
public IResourceServiceProvider getResourceServiceProviderById(final String languageId) {
    ImmutableMap<Map<String, Object>, ? extends Function<String, IResourceServiceProvider>> resourceProvidersMap = getProviderMaps();
    for (Map.Entry<Map<String, Object>, ? extends Function<String, IResourceServiceProvider>> mapEntry : resourceProvidersMap.entrySet()) {
        Map<String, Object> map = mapEntry.getKey();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            try {
                IResourceServiceProvider resourceServiceProvider = mapEntry.getValue().apply(entry.getKey());
                if (resourceServiceProvider == null) {
                    continue;
                }
                IGrammarAccess grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
                if (grammarAccess != null && grammarAccess.getGrammar().getName().equals(languageId)) {
                    return resourceServiceProvider;
                }
            // CHECKSTYLE:OFF
            } catch (ConfigurationException ex) {
            // CHECKSTYLE:ON
            // ignore
            }
        }
    }
    return null;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) ConfigurationException(com.google.inject.ConfigurationException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 57 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project statecharts by Yakindu.

the class AbstractLibraryGlobalScopeProvider method getDescriptions.

protected Iterable<IEObjectDescription> getDescriptions(Resource context, URI uri) {
    List<IEObjectDescription> result = Lists.newArrayList();
    ResourceSet set = context.getResourceSet();
    Resource resource = set.getResource(uri, true);
    IResourceServiceProvider resourceServiceProvider = serviceProviderRegistry.getResourceServiceProvider(uri);
    if (resourceServiceProvider == null) {
        Iterables.addAll(result, Scopes.scopedElementsFor(Lists.newArrayList(resource.getAllContents())));
    } else {
        IResourceDescription resourceDescription = resourceServiceProvider.getResourceDescriptionManager().getResourceDescription(resource);
        Iterables.addAll(result, resourceDescription.getExportedObjects());
    }
    resource.unload();
    return result;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 58 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project metalib by softlang.

the class FsmlStandaloneSetupGenerated method register.

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

Example 59 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project statecharts by Yakindu.

the class DirtyStateAwareDiagramDocumentEditor method createDirtyResource.

private void createDirtyResource(Resource resource) {
    IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(resource.getURI());
    if (resourceServiceProvider == null) {
        return;
    }
    final DirtyResourceAdapter dirtyResource = new DirtyResourceAdapter(resource, resourceServiceProvider);
    dirtyStateManager.manageDirtyState(dirtyResource);
    uri2dirtyResource.put(resource.getURI(), dirtyResource);
    if (EcoreUtil.getExistingAdapter(resource, DirtyResourceUpdater.class) == null)
        resource.eAdapters().add(new DirtyResourceUpdater(dirtyResource));
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider)

Example 60 with IResourceServiceProvider

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

the class DslStandaloneSetupGenerated method register.

public void register(Injector injector) {
    if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/gemoc/Dsl")) {
        EPackage.Registry.INSTANCE.put("http://www.eclipse.org/gemoc/Dsl", DslPackage.eINSTANCE);
    }
    IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("dsl", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("dsl", serviceProvider);
}
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