use of org.eclipse.xtext.ui.editor.validation.MarkerCreator 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