Search in sources :

Example 91 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.

the class DefaultResourceDescription2Test method testValidLocalLink.

@Test
public void testValidLocalLink() throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
    res1.load(new StringInputStream("type Foo"), null);
    XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
    res2.load(new StringInputStream("import 'foo.langatestlanguage'" + "type Foo type Bar extends Foo"), null);
    EcoreUtil.resolveAll(res2);
    Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
    assertFalse(names.iterator().hasNext());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 92 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.

the class DefaultResourceDescription2Test method testNotYetLinked.

@Test
public void testNotYetLinked() throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
    res1.load(new StringInputStream("type Foo"), null);
    XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
    res2.load(new StringInputStream("import 'foo.langatestlanguage'" + "type Bar extends Foo"), null);
    Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
    assertTrue(names.iterator().hasNext());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 93 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.

the class Bug318343Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    with(LangATestLanguageStandaloneSetup.class);
    globalScopeProvider = get(DefaultGlobalScopeProvider.class);
    XtextResourceSet xtextResourceSet = get(XtextResourceSet.class);
    resource1 = xtextResourceSet.createResource(URI.createFileURI(new File("uri1.langatestlanguage").getAbsolutePath()));
    resource2 = xtextResourceSet.createResource(URI.createFileURI(new File("uri2.langatestlanguage").getAbsolutePath()));
    resource1.load(new StringInputStream("type t1"), null);
    resource2.load(new StringInputStream("type t2"), null);
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) File(java.io.File)

Example 94 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.

the class AbstractPortableURIsTest method setUp.

@Before
public void setUp() throws Exception {
    globalStateMemento = GlobalRegistries.makeCopyOfGlobalState();
    EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE);
    resourceSet = new XtextResourceSet();
    resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    resourceSet.getPackageRegistry().put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("genmodel", new EcoreResourceFactoryImpl());
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
    resourceSet.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/"));
    resourceSet.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/"));
    resourceSet.getLoadOptions().put(XMLResource.OPTION_URI_HANDLER, this);
    resourceSet.setClasspathURIContext(getClasspathURIContext());
}
Also used : EcoreResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Before(org.junit.Before)

Example 95 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.

the class ToEcoreTrafoTest method getResource.

private XtextResource getResource(String uri) {
    XtextResourceSet set = get(XtextResourceSet.class);
    URI nsURI = URI.createURI(EcorePackage.eNS_URI);
    URI platformURI = URI.createURI("platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore");
    set.getURIConverter().getURIMap().put(platformURI, nsURI);
    set.getURIResourceMap().put(platformURI, set.getResource(nsURI, true));
    set.setClasspathURIContext(getClass().getClassLoader());
    // if(AllTests.isPluginContext) {
    // set.setClasspathUriResolver(new BundleClasspathUriResolver());
    // set.setClasspathURIContext(Activator.getDefault());
    // }
    XtextResource r = (XtextResource) set.getResource(URI.createURI(uri), true);
    return r;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) URI(org.eclipse.emf.common.util.URI)

Aggregations

XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)72 XtextResource (org.eclipse.xtext.resource.XtextResource)61 Test (org.junit.Test)44 StringInputStream (org.eclipse.xtext.util.StringInputStream)36 URI (org.eclipse.emf.common.util.URI)24 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)19 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 EObject (org.eclipse.emf.ecore.EObject)11 File (java.io.File)10 AbstractResourceSetTest (org.eclipse.xtext.resource.AbstractResourceSetTest)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Issue (org.eclipse.xtext.validation.Issue)8 Grammar (org.eclipse.xtext.Grammar)7 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)7 ArrayList (java.util.ArrayList)5 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)5 Before (org.junit.Before)5 Injector (com.google.inject.Injector)4