Search in sources :

Example 11 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project n4js by eclipse.

the class RegExLiteralConverter method getRegexParser.

private IParser getRegexParser() {
    if (regexParser == null) {
        // no need for sync since we can also use a new regexParser if concurrent access happens by accident
        IResourceServiceProvider serviceProvider = serviceProviders.getResourceServiceProvider(URI.createURI("a.regex"));
        regexParser = serviceProvider.get(IParser.class);
    }
    return regexParser;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IParser(org.eclipse.xtext.parser.IParser)

Example 12 with IResourceServiceProvider

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

the class RegistryBuilderParticipant method initializeParticipant.

/**
 * Initializes the given {@link IXtextBuilderParticipant}.
 *
 * @param participant
 *          the {@link IXtextBuilderParticipant} to initialize, must not be {@code null}
 * @return whether the builder participant was initialized successfully
 */
private boolean initializeParticipant(final IXtextBuilderParticipant participant) {
    String languageId = null;
    if (participant instanceof IGeneratorModuleProvider) {
        languageId = ((IGeneratorModuleProvider) participant).getGeneratorModuleId();
    } else if (participant instanceof ILanguageSpecificBuilderParticipant) {
        languageId = ((ILanguageSpecificBuilderParticipant) participant).getLanguageId();
    }
    if (languageId != null && !BuilderParticipantSettings.isBuilderParticipantEnabled(languageId)) {
        return false;
    }
    if (!initializedParticipants.contains(participant)) {
        if (languageId != null) {
            final IResourceServiceProvider resourceServiceProvider = resourceServiceProviderLocator.getResourceServiceProviderById(languageId);
            if (resourceServiceProvider != null) {
                // inject members of the participant
                final Injector injector = resourceServiceProvider.get(Injector.class);
                injector.injectMembers(participant);
            } else {
                // $NON-NLS-1$
                LOG.error(NLS.bind("No ResourceServiceProvider found for builder participant ''{0}'' and language id ''{1}''", participant.getClass().getName(), languageId));
                return false;
            }
        }
        initializedParticipants.add(participant);
    }
    return true;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Injector(com.google.inject.Injector)

Example 13 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 14 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 15 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)

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