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.");
}
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations