Search in sources :

Example 1 with URIHandler

use of org.eclipse.emf.ecore.resource.URIHandler in project xtext-core by eclipse.

the class ExternalContentSupport method configureConverter.

public void configureConverter(URIConverter converter, IExternalContentProvider contentProvider) {
    List<URIHandler> uriHandlers = converter.getURIHandlers();
    ListIterator<URIHandler> iter = uriHandlers.listIterator();
    while (iter.hasNext()) {
        URIHandler transformed = new ExternalContentAwareURIHandler(iter.next(), contentProvider);
        iter.set(transformed);
    }
}
Also used : URIHandler(org.eclipse.emf.ecore.resource.URIHandler)

Example 2 with URIHandler

use of org.eclipse.emf.ecore.resource.URIHandler in project xtext-core by eclipse.

the class AbstractIncrementalBuilderTest method newBuildRequest.

protected BuildRequest newBuildRequest(final Procedure1<? super BuildRequest> init) {
    BuildRequest _buildRequest = new BuildRequest();
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        final ResourceDescriptionsData newIndex = this.indexState.getResourceDescriptions().copy();
        it.setBaseDir(this.uri(""));
        XtextResourceSet _get = this.resourceSetProvider.get();
        final Procedure1<XtextResourceSet> _function_1 = (XtextResourceSet it_1) -> {
            it_1.getURIConverter().getURIHandlers().clear();
            EList<URIHandler> _uRIHandlers = it_1.getURIConverter().getURIHandlers();
            _uRIHandlers.add(this.inMemoryURIHandler);
            it_1.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
            ProjectDescription _projectDescription = new ProjectDescription();
            final Procedure1<ProjectDescription> _function_2 = (ProjectDescription it_2) -> {
                it_2.setName("test-project");
            };
            final ProjectDescription projectDescription = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription, _function_2);
            projectDescription.attachToEmfObject(it_1);
            Map<String, ResourceDescriptionsData> _emptyMap = CollectionLiterals.<String, ResourceDescriptionsData>emptyMap();
            final ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(_emptyMap, it_1);
            index.setContainer(projectDescription.getName(), newIndex);
        };
        XtextResourceSet _doubleArrow = ObjectExtensions.<XtextResourceSet>operator_doubleArrow(_get, _function_1);
        it.setResourceSet(_doubleArrow);
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
            Iterables.<Issue>addAll(this.issues, issues);
            return IterableExtensions.isEmpty(issues);
        };
        it.setAfterValidate(_function_2);
        final Procedure1<URI> _function_3 = (URI it_1) -> {
            this.deleted.add(it_1);
        };
        it.setAfterDeleteFile(_function_3);
        final Procedure2<URI, URI> _function_4 = (URI source, URI target) -> {
            this.generated.put(source, target);
        };
        it.setAfterGenerateFile(_function_4);
        Source2GeneratedMapping _copy = this.indexState.getFileMappings().copy();
        IndexState _indexState = new IndexState(newIndex, _copy);
        it.setState(_indexState);
    };
    final BuildRequest result = ObjectExtensions.<BuildRequest>operator_doubleArrow(_buildRequest, _function);
    init.apply(result);
    return result;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Source2GeneratedMapping(org.eclipse.xtext.build.Source2GeneratedMapping) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) IndexState(org.eclipse.xtext.build.IndexState) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Procedure2(org.eclipse.xtext.xbase.lib.Procedures.Procedure2) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) URIHandler(org.eclipse.emf.ecore.resource.URIHandler) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Example 3 with URIHandler

use of org.eclipse.emf.ecore.resource.URIHandler 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)

Aggregations

URIHandler (org.eclipse.emf.ecore.resource.URIHandler)3 URI (org.eclipse.emf.common.util.URI)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Map (java.util.Map)1 EList (org.eclipse.emf.common.util.EList)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 URIConverter (org.eclipse.emf.ecore.resource.URIConverter)1 BuildRequest (org.eclipse.xtext.build.BuildRequest)1 IndexState (org.eclipse.xtext.build.IndexState)1 Source2GeneratedMapping (org.eclipse.xtext.build.Source2GeneratedMapping)1 ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)1 ProjectDescription (org.eclipse.xtext.resource.impl.ProjectDescription)1 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)1 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1 Issue (org.eclipse.xtext.validation.Issue)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1