use of org.eclipse.xtext.validation.Issue in project n4js by eclipse.
the class N4HeadlessCompiler method postProcessResources.
/*
* ===============================================================================================================
*
* PROJECT POST-PROCESSING
*
* ===============================================================================================================
*/
/**
* Post processing on the whole project. While validations can trigger post processing in a lazy way, they do not
* guarantee that all resources will be fully processed. This is an issue in larger project graphs. Unlike in the
* IDE which can at any point load AST on demand based on the TModel, the HLC does not allow to access AST after
* unloading therefore we explicitly post process all N4JS resources in the given project.
*
* @param markedProject
* project to trigger post process.
*/
private void postProcessResources(MarkedProject markedProject) {
if (logger.isCreateDebugOutput())
logger.debug(" PostProcessing " + markedProject);
Iterables.filter(markedProject.resources, resource -> resource.isLoaded()).forEach(resource -> {
if (resource instanceof N4JSResource) {
N4JSResource n4jsResource = (N4JSResource) resource;
// Make sure the resource is fully postprocessed before unloading the AST. Otherwise, resolving
// cross references to the elements inside the resources from dependent projects will fail.
n4jsResource.performPostProcessing();
}
});
}
use of org.eclipse.xtext.validation.Issue in project dsl-devkit by dsldevkit.
the class ExportFragment method getModel.
/**
* Get the export model that we have to process.
*
* @param grammar
* The grammar
* @return The model
*/
private synchronized ExportModel getModel(final Grammar grammar) {
// NOPMD NPathComplexity by wth on 24.11.10 08:22
if (modelLoaded) {
return model;
}
modelLoaded = true;
Resource resource = grammar.eResource();
if (resource == null) {
return null;
}
final ResourceSet resourceSet = resource.getResourceSet();
URI uri = null;
if (getExportFileURI() != null) {
uri = URI.createURI(getExportFileURI());
} else {
uri = grammar.eResource().getURI().trimFileExtension().appendFileExtension(EXPORT_FILE_EXTENSION);
}
try {
resource = resourceSet.getResource(uri, true);
final List<Issue> issues = VALIDATOR.validate(resource, LOGGER);
for (final Issue issue : issues) {
if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
throw new WorkflowInterruptedException(NLS.bind(Messages.ExportFragment_EXPORT_ERRORS, uri));
}
}
if (resource.getContents().size() == 0) {
return null;
}
model = (ExportModel) resource.getContents().get(0);
return model;
} catch (final ClasspathUriResolutionException e) {
// Resource does not exist.
if (getExportFileURI() != null) {
// NOPMD PreserveStackTrace by wth on 24.11.10 08:27
throw new WorkflowInterruptedException(NLS.bind(Messages.ExportFragment_NO_EXPORT_FILE, uri));
}
// No file found at implicit location: work with a null model, generating code that implements the default behavior.
return null;
}
}
use of org.eclipse.xtext.validation.Issue in project dsl-devkit by dsldevkit.
the class ValidMarkerUpdateJob method validate.
/**
* Validate the given resource and create the corresponding markers. The CheckMode is a constant calculated from the constructor
* parameters.
*
* @param resourceValidator
* the resource validator (not null)
* @param file
* the EFS file (not null)
* @param resource
* the EMF resource (not null)
* @param monitor
* the monitor (not null)
*/
protected void validate(final IResourceValidator resourceValidator, final IFile file, final Resource resource, final IProgressMonitor monitor) {
try {
// $NON-NLS-1$
monitor.subTask("validating " + file.getName());
final List<Issue> list = resourceValidator.validate(resource, checkMode, getCancelIndicator(monitor));
if (list != null) {
// resourceValidator.validate returns null if canceled (and not an empty list)
file.deleteMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
file.deleteMarkers(MarkerTypes.NORMAL_VALIDATION, true, IResource.DEPTH_ZERO);
if (performExpensiveValidation) {
file.deleteMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO);
}
for (final Issue issue : list) {
markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
}
}
} catch (final CoreException e) {
LOGGER.error(e.getMessage(), e);
} finally {
monitor.worked(1);
}
}
use of org.eclipse.xtext.validation.Issue in project dsl-devkit by dsldevkit.
the class ValidValidatorFragment method getValidModel.
/**
* Gets the valid model.
*
* @param grammar
* the grammar
* @return the valid model
*/
private ValidModel getValidModel(final Grammar grammar) {
if (model != null) {
return model;
}
Resource resource = null;
final String name = GrammarUtil.getName(grammar) + '.' + XTEXT_EXTENSION;
URI uri;
for (final Resource res : grammar.eResource().getResourceSet().getResources()) {
if (res.getURI() != null && name.equals(EmfResourceUtil.getFileName(res.getURI()))) {
resource = res;
break;
}
}
if (getValidURI() == null) {
Assert.isNotNull(resource, NLS.bind(Messages.RESOURCE_NOT_FOUND, name));
uri = resource.getURI().trimFileExtension().appendFileExtension(VALID_EXTENSION);
} else {
uri = URI.createURI(getValidURI());
}
resource = resource.getResourceSet().getResource(uri, true);
final List<Issue> issues = VALIDATOR.validate(resource, LOGGER);
for (final Issue issue : issues) {
if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
throw new WorkflowInterruptedException(NLS.bind(Messages.ERROR_FOUND, uri.toString()));
}
}
model = (ValidModel) resource.getContents().get(0);
return model;
}
use of org.eclipse.xtext.validation.Issue in project statecharts by Yakindu.
the class DefaultValidationJob method runInternal.
@Override
protected IStatus runInternal(final IProgressMonitor monitor) {
try {
if (!resource.isLoaded())
return Status.CANCEL_STATUS;
if (resource instanceof AbstractSCTResource) {
relinkModel(monitor, (AbstractSCTResource) resource);
}
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
TransactionalValidationRunner runner = new TransactionalValidationRunner(validator, resource, CheckMode.FAST_ONLY, new CancelIndicator() {
public boolean isCanceled() {
return monitor.isCanceled();
}
});
TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
if (editingDomain == null)
return Status.CANCEL_STATUS;
try {
editingDomain.runExclusive(runner);
} catch (Throwable ex) {
// Since xtext 2.8 this may throw an OperationCanceledError
return Status.CANCEL_STATUS;
}
final List<Issue> issues = runner.getResult();
if (issues == null)
return Status.CANCEL_STATUS;
validationIssueProcessor.processIssues(issues, monitor);
} catch (Exception ex) {
ex.printStackTrace();
return new Status(IStatus.ERROR, DiagramActivator.PLUGIN_ID, ex.getMessage());
}
return Status.OK_STATUS;
}
Aggregations