Search in sources :

Example 51 with IResourceServiceProvider

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

the class TypesStandaloneSetupGenerated 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("n4ts", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4ts", serviceProvider);
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Example 52 with IResourceServiceProvider

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

the class TestDiscoveryUIUtils method getSelectedElement.

private static EObject getSelectedElement(final XtextEditor editor, final ITextSelection textSelection) {
    return editor.getDocument().modify(resource -> {
        final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
        final EObjectAtOffsetHelper offsetHelper = serviceProvider.get(EObjectAtOffsetHelper.class);
        return offsetHelper.resolveElementAt(resource, textSelection.getOffset());
    });
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper)

Example 53 with IResourceServiceProvider

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

the class N4HeadlessCompiler method indexResource.

/**
 * Install the given resource's description into the given index. Raw JavaScript files will not be indexed. Note
 * that when this method is called for the given resource, it is not yet fully processed and therefore the
 * serialized type model is not added to the index.
 * <p>
 * This is due to the fact that we keep a common resource set for all projects that contains the resources of all
 * projects with unprocessed dependencies, unlike in the IDE case where we have one resource set per open document
 * and load the type models from the index.
 * </p>
 * <p>
 * Since the type models are available in the resource set as long as they may still be referenced, they need not be
 * serialized and stored into the index.
 * </p>
 *
 * @param resource
 *            the resource to be indexed
 * @param index
 *            the index to add the given resource to
 */
private void indexResource(Resource resource, ResourceDescriptionsData index) {
    if (!shouldIndexResource(resource))
        return;
    final URI uri = resource.getURI();
    IResourceServiceProvider serviceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(uri);
    if (serviceProvider != null) {
        if (logger.isCreateDebugOutput()) {
            logger.debug("  Indexing resource " + uri);
        }
        IResourceDescription.Manager resourceDescriptionManager = serviceProvider.getResourceDescriptionManager();
        IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource);
        if (resourceDescription != null) {
            index.addDescription(uri, resourceDescription);
        }
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URI(org.eclipse.emf.common.util.URI)

Example 54 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 55 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)

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