Search in sources :

Example 1 with IAllContainersState

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

the class RuntimeResourceSetInitializer method getInitializedResourceSet.

public ResourceSet getInitializedResourceSet(List<String> pathes, UriFilter filter) {
    ResourceSet resourceSet = resourceSetProvider.get();
    Multimap<String, URI> pathToUriMap = getPathToUriMap(pathes, filter);
    IAllContainersState containersState = factory.getContainersState(pathes, pathToUriMap);
    resourceSet.eAdapters().add(new DelegatingIAllContainerAdapter(containersState));
    for (URI uri : pathToUriMap.values()) {
        resourceSet.createResource(uri);
    }
    return resourceSet;
}
Also used : IAllContainersState(org.eclipse.xtext.resource.containers.IAllContainersState) DelegatingIAllContainerAdapter(org.eclipse.xtext.resource.containers.DelegatingIAllContainerAdapter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 2 with IAllContainersState

use of org.eclipse.xtext.resource.containers.IAllContainersState in project n4js by eclipse.

the class XcoreReader method invokeInternal.

@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
    ResourceSet resourceSet = getResourceSet();
    // due to some Xcore peculiarity we have to access the IAllContainerState here
    // to trigger some lazy init logic
    IAllContainersState allContainerState = (IAllContainersState) EcoreUtil.getAdapter(resourceSet.eAdapters(), IAllContainersState.class);
    allContainerState.isEmpty("");
    Multimap<String, URI> uris = getPathTraverser().resolvePathes(pathes, new Predicate<URI>() {

        @Override
        public boolean apply(URI input) {
            return input.fileExtension().equals(XCORE_FILE_EXT);
        }
    });
    List<Resource> resources = new ArrayList<>();
    for (URI uri : uris.values()) {
        LOGGER.info(uri);
        try {
            resources.add(parse(uri, resourceSet));
        } catch (Exception e) {
            LOGGER.error("Problem during loading of resource @ " + uri, e);
        }
    }
    installIndex(resourceSet);
    for (Resource r : resources) {
        EcoreUtil.resolveAll(r);
        for (Diagnostic x : r.getErrors()) {
            issues.addError(x.getMessage(), x);
        }
    }
    ctx.set(slot, resources);
}
Also used : IAllContainersState(org.eclipse.xtext.resource.containers.IAllContainersState) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 3 with IAllContainersState

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

the class Reader method invokeInternal.

@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
    ResourceSet resourceSet = getResourceSet();
    Multimap<String, URI> uris = getPathTraverser().resolvePathes(pathes, new Predicate<URI>() {

        @Override
        public boolean apply(URI input) {
            boolean result = true;
            if (getUriFilter() != null)
                result = getUriFilter().matches(input);
            if (result)
                result = getRegistry().getResourceServiceProvider(input) != null;
            return result;
        }
    });
    IAllContainersState containersState = containersStateFactory.getContainersState(pathes, uris);
    installAsAdapter(resourceSet, containersState);
    populateResourceSet(resourceSet, uris);
    getValidator().validate(resourceSet, getRegistry(), issues);
    addModelElementsToContext(ctx, resourceSet);
}
Also used : IAllContainersState(org.eclipse.xtext.resource.containers.IAllContainersState) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 4 with IAllContainersState

use of org.eclipse.xtext.resource.containers.IAllContainersState in project xtext-eclipse by eclipse.

the class LiveShadowedAllContainerStateTest method formatContainers.

private String formatContainers(final ResourceSet rs) {
    String _xblockexpression = null;
    {
        final IResourceDescriptions resourceDescriptions = this.resourceDescriptionProvider.getResourceDescriptions(rs);
        final IAllContainersState containerState = this.containerStateProvider.get(resourceDescriptions);
        final Function1<Resource, URI> _function = (Resource it) -> {
            return it.getURI();
        };
        final Set<URI> allURIs = IterableExtensions.<URI>toSet(ListExtensions.<Resource, URI>map(rs.getResources(), _function));
        final Function1<URI, String> _function_1 = (URI it) -> {
            return containerState.getContainerHandle(it);
        };
        final Set<String> allContainers = IterableExtensions.<String>toSet(IterableExtensions.<String>filterNull(IterableExtensions.<URI, String>map(allURIs, _function_1)));
        final Function1<IProject, String> _function_2 = (IProject it) -> {
            return it.getName();
        };
        List<String> _map = ListExtensions.<IProject, String>map(((List<IProject>) Conversions.doWrapArray(ResourcesPlugin.getWorkspace().getRoot().getProjects())), _function_2);
        Iterables.<String>addAll(allContainers, _map);
        StringConcatenation _builder = new StringConcatenation();
        {
            for (final String container : allContainers) {
                _builder.append("container ");
                _builder.append(container);
                _builder.append(" isEmpty=");
                boolean _isEmpty = containerState.isEmpty(container);
                _builder.append(_isEmpty);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                {
                    final Function1<URI, String> _function_3 = (URI it) -> {
                        return it.toString();
                    };
                    List<URI> _sortBy = IterableExtensions.<URI, String>sortBy(containerState.getContainedURIs(container), _function_3);
                    for (final URI uri : _sortBy) {
                        _builder.append("\t");
                        _builder.append("resourceURI=");
                        _builder.append(uri, "\t");
                        _builder.append(" exported=[");
                        final Function1<IEObjectDescription, QualifiedName> _function_4 = (IEObjectDescription it) -> {
                            return it.getName();
                        };
                        String _join = IterableExtensions.join(IterableExtensions.<IEObjectDescription, QualifiedName>map(resourceDescriptions.getResourceDescription(uri).getExportedObjects(), _function_4), ", ");
                        _builder.append(_join, "\t");
                        _builder.append("]");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("}");
                _builder.newLine();
            }
        }
        _xblockexpression = _builder.toString();
    }
    return _xblockexpression;
}
Also used : IAllContainersState(org.eclipse.xtext.resource.containers.IAllContainersState) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Set(java.util.Set) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List)

Example 5 with IAllContainersState

use of org.eclipse.xtext.resource.containers.IAllContainersState in project xtext-eclipse by eclipse.

the class PersistableResourceDescriptionsTest method createResourceSet.

public ResourceSet createResourceSet() {
    ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
    resourceSetImpl.setURIConverter(uriConverter);
    resourceSetImpl.eAdapters().add(new DelegatingIAllContainerAdapter(new IAllContainersState() {

        @Override
        public List<String> getVisibleContainerHandles(String handle) {
            return null;
        }

        @Override
        public Collection<URI> getContainedURIs(String containerHandle) {
            return null;
        }

        @Override
        public String getContainerHandle(URI uri) {
            return null;
        }

        @Override
        public boolean isEmpty(String containerHandle) {
            return true;
        }
    }));
    return resourceSetImpl;
}
Also used : DelegatingIAllContainerAdapter(org.eclipse.xtext.resource.containers.DelegatingIAllContainerAdapter) IAllContainersState(org.eclipse.xtext.resource.containers.IAllContainersState) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) URI(org.eclipse.emf.common.util.URI)

Aggregations

URI (org.eclipse.emf.common.util.URI)6 IAllContainersState (org.eclipse.xtext.resource.containers.IAllContainersState)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 Resource (org.eclipse.emf.ecore.resource.Resource)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 DelegatingIAllContainerAdapter (org.eclipse.xtext.resource.containers.DelegatingIAllContainerAdapter)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 IProject (org.eclipse.core.resources.IProject)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1