Search in sources :

Example 96 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class XtextResourceSet method registerURI.

/**
 * @since 2.3
 */
protected void registerURI(Resource resource) {
    Map<URI, Resource> map = getURIResourceMap();
    if (map != null) {
        final URI uri = resource.getURI();
        if (uri != null) {
            URI normalized = getURIConverter().normalize(uri);
            if (!normalized.equals(uri)) {
                Resource previous = map.put(normalized, resource);
                if (previous != null && previous != resource) {
                    throw new IllegalStateException("A resource with the normalized URI '" + normalized + "' was already registered. The resource with the URI '" + previous + "' is no longer registered with the normalized form.");
                }
            }
            normalizationMap.put(uri, normalized);
        }
        Resource previous = map.put(uri, resource);
        if (previous != null && previous != resource) {
            throw new IllegalStateException("A different resource with the URI '" + uri + "' was already registered.");
        }
    }
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 97 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class XtextResourceSet method updateURI.

void updateURI(Resource resource, URI old, final Map<URI, Resource> uriResourceMap) {
    uriResourceMap.remove(old);
    URI oldNormalized = normalizationMap.remove(old);
    if (old != null && !old.equals(oldNormalized)) {
        uriResourceMap.remove(oldNormalized);
    }
    registerURI(resource);
}
Also used : URI(org.eclipse.emf.common.util.URI)

Example 98 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class XtextResourceSet method getResource.

@Override
public Resource getResource(URI uri, boolean loadOnDemand) {
    Map<URI, Resource> map = getURIResourceMap();
    if (map == null || resourceLocator != null)
        return super.getResource(uri, loadOnDemand);
    Resource resource = map.get(uri);
    if (resource == null) {
        URI normalizedURI = getURIConverter().normalize(uri);
        resource = map.get(normalizedURI);
        if (resource != null) {
            normalizationMap.put(uri, normalizedURI);
        }
    }
    if (resource != null) {
        if (loadOnDemand && !resource.isLoaded()) {
            demandLoadHelper(resource);
        }
        return resource;
    }
    Resource delegatedResource = delegatedGetResource(uri, loadOnDemand);
    if (delegatedResource != null) {
        return delegatedResource;
    }
    if (loadOnDemand) {
        resource = demandCreateResource(uri);
        if (resource == null) {
            throw new RuntimeException("Cannot create a resource for '" + uri + "'; a registered resource factory is needed");
        }
        demandLoadHelper(resource);
        return resource;
    }
    return null;
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 99 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class FlatResourceSetBasedAllContainersState method getContainedURIs.

@Override
public Collection<URI> getContainedURIs(String containerHandle) {
    if (!HANDLE.equals(containerHandle))
        return Collections.emptySet();
    if (resourceSet instanceof XtextResourceSet) {
        ResourceDescriptionsData descriptionsData = findResourceDescriptionsData(resourceSet);
        if (descriptionsData != null) {
            return descriptionsData.getAllURIs();
        }
        return newArrayList(((XtextResourceSet) resourceSet).getNormalizationMap().values());
    }
    List<URI> uris = Lists.newArrayListWithCapacity(resourceSet.getResources().size());
    URIConverter uriConverter = resourceSet.getURIConverter();
    for (Resource r : resourceSet.getResources()) uris.add(uriConverter.normalize(r.getURI()));
    return uris;
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) URIConverter(org.eclipse.emf.ecore.resource.URIConverter) URI(org.eclipse.emf.common.util.URI)

Example 100 with URI

use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.

the class LiveShadowedAllContainerState method getContainedURIs.

@Override
public Collection<URI> getContainedURIs(String containerHandle) {
    Set<URI> result = Sets.newLinkedHashSet();
    for (IResourceDescription descriptions : localDescriptions.getAllResourceDescriptions()) {
        String computedHandle = getContainerHandle(descriptions.getURI());
        if (computedHandle != null && computedHandle.equals(containerHandle))
            result.add(descriptions.getURI());
    }
    result.addAll(globalState.getContainedURIs(containerHandle));
    return result;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URI(org.eclipse.emf.common.util.URI)

Aggregations

URI (org.eclipse.emf.common.util.URI)305 Resource (org.eclipse.emf.ecore.resource.Resource)85 Test (org.junit.Test)79 EObject (org.eclipse.emf.ecore.EObject)55 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)37 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)33 XtextResource (org.eclipse.xtext.resource.XtextResource)32 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)26 BuildRequest (org.eclipse.xtext.build.BuildRequest)23 File (java.io.File)20 AbstractIncrementalBuilderTest (org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)19 IOException (java.io.IOException)18 InternalEObject (org.eclipse.emf.ecore.InternalEObject)18 EPackage (org.eclipse.emf.ecore.EPackage)15 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)15 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ArrayList (java.util.ArrayList)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13