Search in sources :

Example 96 with XtextResourceSet

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

the class Bug266082Test method _testRedundantImportLarge.

public void _testRedundantImportLarge() {
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    resourceSet.setClasspathURIContext(getClass().getClassLoader());
    URI uri = URI.createURI("classpath:/org/eclipse/xtext/linking/04.importuritestlanguage");
    Resource res = resourceSet.getResource(uri, true);
    assertNotNull("res", res);
    EcoreUtil.resolveAll(res);
    assertFalse(res.getErrors().toString(), res.getErrors().isEmpty());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 97 with XtextResourceSet

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

the class Bug266082Test method testRedundantImport.

@Test
public void testRedundantImport() {
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    resourceSet.setClasspathURIContext(getClass().getClassLoader());
    URI uri = URI.createURI("classpath:/org/eclipse/xtext/linking/03.importuritestlanguage");
    Resource res = resourceSet.getResource(uri, true);
    assertNotNull("res", res);
    EcoreUtil.resolveAll(res);
    assertFalse(res.getErrors().toString(), res.getErrors().isEmpty());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 98 with XtextResourceSet

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

the class Bug266082Test method testManyResolvedImports.

@Test
public void testManyResolvedImports() throws Exception {
    StringBuilder model = new StringBuilder(2000);
    int max = 100;
    for (int i = 1; i <= max; i++) {
        model.append("import '" + i + ".importuritestlanguage'\n");
    }
    model.append("type Foo extends Bar");
    final String modelAsString = model.toString();
    model = null;
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    resourceSet.setClasspathURIContext(getClass().getClassLoader());
    final URIConverter converter = resourceSet.getURIConverter();
    resourceSet.setURIConverter(new URIConverter() {

        @Override
        public Map<String, ?> contentDescription(URI uri, Map<?, ?> options) throws IOException {
            return converter.contentDescription(uri, options);
        }

        @Override
        public InputStream createInputStream(URI uri) throws IOException {
            return new StringInputStream(modelAsString);
        }

        @Override
        public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
            return new StringInputStream(modelAsString);
        }

        @Override
        public OutputStream createOutputStream(URI uri) throws IOException {
            return converter.createOutputStream(uri);
        }

        @Override
        public OutputStream createOutputStream(URI uri, Map<?, ?> options) throws IOException {
            return converter.createOutputStream(uri, options);
        }

        @Override
        public void delete(URI uri, Map<?, ?> options) throws IOException {
            converter.delete(uri, options);
        }

        @Override
        public boolean exists(URI uri, Map<?, ?> options) {
            return true;
        }

        @Override
        public Map<String, ?> getAttributes(URI uri, Map<?, ?> options) {
            return converter.getAttributes(uri, options);
        }

        @Override
        public EList<ContentHandler> getContentHandlers() {
            return converter.getContentHandlers();
        }

        @Override
        public URIHandler getURIHandler(URI uri) {
            return converter.getURIHandler(uri);
        }

        @Override
        public EList<URIHandler> getURIHandlers() {
            return converter.getURIHandlers();
        }

        @Override
        public Map<URI, URI> getURIMap() {
            return converter.getURIMap();
        }

        @Override
        public URI normalize(URI uri) {
            return converter.normalize(uri);
        }

        @Override
        public void setAttributes(URI uri, Map<String, ?> attributes, Map<?, ?> options) throws IOException {
            converter.setAttributes(uri, attributes, options);
        }
    });
    Resource res = resourceSet.getResource(URI.createURI("file:/1.importuritestlanguage"), true);
    EcoreUtil.resolveAll(res);
    assertEquals(res.getErrors().toString(), 1, res.getErrors().size());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) StringInputStream(org.eclipse.xtext.util.StringInputStream) EList(org.eclipse.emf.common.util.EList) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URIHandler(org.eclipse.emf.ecore.resource.URIHandler) URIConverter(org.eclipse.emf.ecore.resource.URIConverter) Map(java.util.Map) Test(org.junit.Test)

Example 99 with XtextResourceSet

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

the class Bug287988WithEagerLinkingTest method doGetResource.

@Override
protected XtextResource doGetResource(InputStream in, URI uri) throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    rs.setClasspathURIContext(getClass());
    XtextResource resource = (XtextResource) factory.createResource(uri);
    rs.getResources().add(resource);
    resource.load(in, null);
    EcoreUtil.resolveAll(resource);
    return resource;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 100 with XtextResourceSet

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

the class IgnoreCaseLinkingWithURIImportsTest method testWithImports.

@Override
@Test
public void testWithImports() throws Exception {
    SyntheticModelAwareURIConverter uriConverter = new SyntheticModelAwareURIConverter();
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    resourceSet.setURIConverter(uriConverter);
    uriConverter.addModel("a.ignorecaseimportstestlanguage", "a A {}");
    XtextResource resource = (XtextResource) getResourceFactory().createResource(URI.createURI("b.ignorecaseimportstestlanguage"));
    resourceSet.getResources().add(resource);
    resource.load(new StringInputStream("'a.ignorecaseimportstestlanguage' b A {}"), null);
    EcoreUtil.resolveAll(resource);
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) SyntheticModelAwareURIConverter(org.eclipse.xtext.scoping.impl.SyntheticModelAwareURIConverter) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

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