Search in sources :

Example 1 with XtextResourceSetProvider

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

the class CheckMarkerUpdateJob method getResourceSet.

/**
 * Gets the resource set. Note that not all sources must be part of the same resource set.
 *
 * @param storage2UriMapper
 *          the storage2 uri mapper, must not be {@code null}
 * @param uri
 *          the uri, must not be {@code null}
 * @return the resource set, may be {@code null}
 */
private ResourceSet getResourceSet(final IStorage2UriMapper storage2UriMapper, final URI uri) {
    Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(uri);
    if (!Iterables.isEmpty(storages)) {
        IProject project = Iterables.get(storages, 0).getSecond();
        XtextResourceSetProvider resourceSetProvider = this.serviceProviderRegistry.getResourceServiceProvider(uri).get(XtextResourceSetProvider.class);
        return resourceSetProvider.get(project);
    }
    return null;
}
Also used : XtextResourceSetProvider(org.eclipse.xtext.ui.resource.XtextResourceSetProvider) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Example 2 with XtextResourceSetProvider

use of org.eclipse.xtext.ui.resource.XtextResourceSetProvider in project xtext-eclipse by eclipse.

the class GrammarLinkingInWorkspaceTest method testReferencedGrammarIsPlatformResourceURI.

@Test
public void testReferencedGrammarIsPlatformResourceURI() throws Exception {
    IJavaProject project = JavaProjectSetupUtil.createJavaProject("p1");
    IFile grammar1 = project.getProject().getFile("src/Grammar1.xtext");
    grammar1.create(new StringInputStream("grammar Grammar1 MyRule : 'foo';"), true, null);
    Injector injector = Activator.getDefault().getInjector(org.eclipse.xtext.xtext.ui.internal.Activator.ORG_ECLIPSE_XTEXT_XTEXT);
    XtextResourceSetProvider resourceSetProvider = injector.getInstance(XtextResourceSetProvider.class);
    ResourceSet resourceSet = resourceSetProvider.get(project.getProject());
    XtextResourceFactory resourceFactory = injector.getInstance(XtextResourceFactory.class);
    Resource resource = resourceFactory.createResource(URI.createURI("synthetic://MyGrammar.xtext"));
    resourceSet.getResources().add(resource);
    resource.load(new StringInputStream("grammar g2 with Grammar1 OtherRule : MyRule ;"), null);
    EcoreUtil.resolveAll(resource);
    assertEquals(2, resourceSet.getResources().size());
    assertTrue(resourceSet.getResources().get(1).getURI().isPlatformResource());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) XtextResourceFactory(org.eclipse.xtext.resource.XtextResourceFactory) Injector(com.google.inject.Injector) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResourceSetProvider(org.eclipse.xtext.ui.resource.XtextResourceSetProvider) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.Test)

Aggregations

XtextResourceSetProvider (org.eclipse.xtext.ui.resource.XtextResourceSetProvider)2 Injector (com.google.inject.Injector)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 XtextResourceFactory (org.eclipse.xtext.resource.XtextResourceFactory)1 Pair (org.eclipse.xtext.util.Pair)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1 Test (org.junit.Test)1