Search in sources :

Example 1 with XtextResourceFactory

use of org.eclipse.xtext.resource.XtextResourceFactory 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

Injector (com.google.inject.Injector)1 IFile (org.eclipse.core.resources.IFile)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 XtextResourceSetProvider (org.eclipse.xtext.ui.resource.XtextResourceSetProvider)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1 Test (org.junit.Test)1