Search in sources :

Example 6 with IResourceServiceProvider

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

the class RegularExpressionStandaloneSetupGenerated method register.

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

Example 7 with IResourceServiceProvider

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

the class EagerResourceSetBasedResourceDescriptions method computeResourceDescription.

private IResourceDescription computeResourceDescription(URI uri) {
    Resource resource = resourceSet.getResource(uri, false);
    if (resource == null)
        return null;
    IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
    if (resourceServiceProvider == null)
        return null;
    IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
    if (manager == null)
        return null;
    return manager.getResourceDescription(resource);
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 8 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 9 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 10 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)

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