use of org.eclipse.xtext.validation.IResourceValidator in project snow-owl by b2ihealthcare.
the class SnomedEclLabelerRequestTest method setup.
@Before
public void setup() {
final IParser parser = ECL_INJECTOR.getInstance(IParser.class);
final IResourceValidator resourceValidator = ECL_INJECTOR.getInstance(IResourceValidator.class);
final ISerializer serializer = ECL_INJECTOR.getInstance(ISerializer.class);
Builder contextBuilder = TestBranchContext.on(MAIN).with(EclParser.class, new DefaultEclParser(parser, resourceValidator)).with(EclSerializer.class, new DefaultEclSerializer(serializer)).with(Index.class, rawIndex()).with(RevisionIndex.class, index()).with(ObjectMapper.class, getMapper());
CodeSystemResource.configureCodeSystem(contextBuilder);
context = contextBuilder.build();
}
use of org.eclipse.xtext.validation.IResourceValidator in project dsl-devkit by dsldevkit.
the class ValidMarkerUpdateJob method run.
/**
* {@inheritDoc}
*/
@Override
protected IStatus run(final IProgressMonitor monitor) {
final IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator();
// Object the list of resources
final List<URI> uris = getResourceDescriptionURIs();
// Let's start (number of task = number of resource * 2 (loading + validating))
// $NON-NLS-1$
monitor.beginTask("", uris.size() * 2);
for (final URI uri : uris) {
// Last chance to cancel before next validation
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
// Get the file; only local files will be re-validated, derived files are ignored
final IFile iFile = getFileFromStorageMapper(uri);
if (iFile != null && !iFile.isDerived(IFile.CHECK_ANCESTORS)) {
// $NON-NLS-1$
monitor.subTask("loading " + iFile.getName());
// 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) {
validate(resourceValidator, iFile, eResource, monitor);
if (loaded) {
// NOPMD
// unload any resource that was previously loaded as part of this loop.
eResource.unload();
}
}
}
}
}
monitor.done();
return Status.OK_STATUS;
}
use of org.eclipse.xtext.validation.IResourceValidator in project n4js by eclipse.
the class OwnResourceValidatorAwareValidatingEditorCallback method newValidationJob.
private ValidationJob newValidationJob(final XtextEditor editor) {
final IXtextDocument document = editor.getDocument();
final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();
final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);
final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider), new MarkerIssueProcessor(editor.getResource(), markerCreator, markerTypeProvider));
return editor.getDocument().modify(resource -> {
final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
});
}
use of org.eclipse.xtext.validation.IResourceValidator in project n4js by eclipse.
the class N4HeadlessCompiler method validateProject.
/*
* ===============================================================================================================
*
* PROJECT VALIDATION
*
* ===============================================================================================================
*/
/**
* Validates all non-external Xtext resources of the given project. Prints issues and adds them to the given issue
* acceptor.
*
* @param markedProject
* the project to validate
* @param recorder
* the progress recorder
* @param issueAcceptor
* the issue acceptor
* @throws N4JSCompileErrorException
* if an error occurs during validation
*/
private void validateProject(MarkedProject markedProject, N4ProgressStateRecorder recorder, IssueAcceptor issueAcceptor) throws N4JSCompileErrorException {
if (logger.isVerbose())
logger.info(" Validating project " + markedProject);
IssueCollector issueCollector = new IssueCollector();
IssueFilter issueFilter = new IssueFilter(issueCollector, issue -> issue.getSeverity() == Severity.ERROR);
issueAcceptor = new IssueAcceptorTee(issueAcceptor, issueFilter);
// validation TODO see IDE-1426 redesign validation calls with generators
for (Resource resource : markedProject.resources) {
if (// is Xtext resource
resource instanceof XtextResource && // is validating
(!n4jsCore.isNoValidate(resource.getURI())) && // not in external folder
(!markedProject.externalResources.contains(resource))) {
if (logger.isCreateDebugOutput())
logger.debug(" Validating resource " + resource.getURI());
XtextResource xtextResource = (XtextResource) resource;
IResourceValidator validator = xtextResource.getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(xtextResource, CheckMode.ALL, CancelIndicator.NullImpl);
if (!issues.isEmpty()) {
recorder.markResourceIssues(resource, issues);
issueAcceptor.acceptAll(issues);
issues.stream().forEach(logger::issue);
}
}
}
// Projects should not compile if there are severe errors:
if (!isKeepOnCompiling()) {
failOnErrors(issueCollector.getCollectedIssues(), markedProject.project.getProjectId());
}
}
use of org.eclipse.xtext.validation.IResourceValidator 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