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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations