use of org.eclipse.xtext.ui.resource.IStorage2UriMapper in project xtext-eclipse by eclipse.
the class EPackageChooser method createResourceSet.
private ResourceSet createResourceSet(URI genModelUri) {
ResourceSetImpl resourceSet;
if (genModelUri.fileExtension().equals("xcore")) {
IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(genModelUri);
IStorage2UriMapper storage2UriMapper = resourceServiceProvider.get(IStorage2UriMapper.class);
IProject project = storage2UriMapper.getStorages(genModelUri).iterator().next().getSecond();
resourceSet = (ResourceSetImpl) resourceServiceProvider.get(IResourceSetProvider.class).get(project);
} else {
resourceSet = new ResourceSetImpl();
}
Resource ecorePackageResource = EcorePackage.eINSTANCE.eResource();
Map<URI, Resource> uriResourceMap = Maps.newHashMap();
uriResourceMap.put(URI.createPlatformResourceURI(PATH_TO_ECORE_ECORE, true), ecorePackageResource);
uriResourceMap.put(URI.createPlatformPluginURI(PATH_TO_ECORE_ECORE, true), ecorePackageResource);
resourceSet.setURIResourceMap(uriResourceMap);
return resourceSet;
}
use of org.eclipse.xtext.ui.resource.IStorage2UriMapper in project xtext-eclipse by eclipse.
the class TraceEditor method getLocalStorage.
protected IStorage getLocalStorage(IResourceServiceProvider serviceProvider, URI traceURI) {
TraceFileNameProvider fileNameProvider = serviceProvider.get(TraceFileNameProvider.class);
IStorage2UriMapper storage2UriMapper = serviceProvider.get(IStorage2UriMapper.class);
String generatedName = fileNameProvider.getJavaFromTrace(traceURI.lastSegment());
URI generatedURI = traceURI.trimSegments(1).appendSegment(generatedName);
for (Pair<IStorage, IProject> x : storage2UriMapper.getStorages(generatedURI)) return x.getFirst();
throw new IllegalStateException("Could not find IStorage for " + generatedURI);
}
use of org.eclipse.xtext.ui.resource.IStorage2UriMapper in project dsl-devkit by dsldevkit.
the class CheckMarkerUpdateJob method run.
/**
* {@inheritDoc}
*/
@Override
protected IStatus run(final IProgressMonitor monitor) {
// Let's start (number of task = number of resource * 2 (loading + validating))
// $NON-NLS-1$
monitor.beginTask("", 2 * this.uris.size());
for (final URI uri : this.uris) {
// Last chance to cancel before next validation
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(uri);
if (serviceProvider == null) {
// This may happen for non-Xtext resources in ice entities
if (LOGGER.isDebugEnabled()) {
// $NON-NLS-1$
LOGGER.debug(MessageFormat.format("Could not validate {0}: no resource service provider found", uri.toString()));
}
// Skip to next URI
continue;
}
final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
final IStorage2UriMapper uriMapper = serviceProvider.get(IStorage2UriMapper.class);
final MarkerCreator markerCreator = serviceProvider.get(MarkerCreator.class);
// Get the file; only local files will be re-validated, derived files are ignored
final IFile iFile = getFileFromStorageMapper(uriMapper, uri);
if (iFile == null) {
// no storage mapping found for this URI
continue;
}
if (resourceValidator == null) {
// $NON-NLS-1$
LOGGER.error(MessageFormat.format("Could not validate {0}: no resource validator found", iFile.getName()));
} else if (iFile != null) {
// $NON-NLS-1$
monitor.subTask("loading " + iFile.getName());
// Don't try to evaluate resource set before it has been checked that the storage provider contains a mapping
// for current uri
final ResourceSet resourceSet = getResourceSet(uriMapper, uri);
// Load the corresponding resource
boolean loaded = false;
Resource eResource = null;
try {
eResource = resourceSet.getResource(uri, false);
if ((eResource == null) || (eResource != null && !eResource.isLoaded())) {
// if the resource does not exist in the resource set, or is not loaded yet
// load it.
eResource = resourceSet.getResource(uri, true);
loaded = true;
}
monitor.worked(1);
// CHECKSTYLE:OFF
} catch (final RuntimeException e) {
// CHECKSTYLE:ON
// $NON-NLS-1$
LOGGER.error(MessageFormat.format("{0} could not be validated.", iFile.getName()), e);
} finally {
if (eResource != null) {
validateAndCreateMarkers(resourceValidator, markerCreator, iFile, eResource, monitor);
// $NON-NLS-1$
LOGGER.debug("Validated " + uri);
if (loaded) {
// NOPMD
// unload any resource that was previously loaded as part of this loop.
eResource.unload();
}
}
}
}
}
monitor.done();
return Status.OK_STATUS;
}
Aggregations