use of org.eclipse.xtext.validation.Issue 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.Issue in project dsl-devkit by dsldevkit.
the class ModelValidator method validate.
/**
* Validate the resource and notify the logger of any error and warning.
*
* @param resource
* the resource
* @param logger
* the logger
* @return the list of issues found in the resource
*/
public List<Issue> validate(final Resource resource, final Logger logger) {
EcoreUtil.resolveAll(resource);
final List<Issue> issues = resourceValidator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
for (final Issue issue : issues) {
logIssue(resource, issue, logger);
}
return issues;
}
use of org.eclipse.xtext.validation.Issue in project dsl-devkit by dsldevkit.
the class DefaultCheckQuickfixProvider method getFixMethodPredicate.
/**
* Returns a method predicate indicating whether a given method is an executable quickfix method. Both Check
* quickfix methods and native quickfix methods are considered.
*
* @param issueCode
* the issue code
* @return the fix method predicate
* @see com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix CoreFix annotation
* @see org.eclipse.xtext.ui.editor.quickfix.Fix Fix annotation
*/
@Override
protected Predicate<Method> getFixMethodPredicate(final String issueCode) {
return new Predicate<Method>() {
@Override
public boolean apply(final Method input) {
CoreFix coreFixAnnotation = input.getAnnotation(CoreFix.class);
Fix fixAnnotation = input.getAnnotation(Fix.class);
if (coreFixAnnotation == null && fixAnnotation == null) {
// Definitely no candidate
return false;
}
final boolean typesMatch = Void.TYPE == input.getReturnType() && input.getParameterTypes().length == 2 && input.getParameterTypes()[0].isAssignableFrom(Issue.class);
boolean result;
if (coreFixAnnotation != null) {
result = coreFixAnnotation != null && issueCode.equals(coreFixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(CoreIssueResolutionAcceptor.class);
} else {
result = fixAnnotation != null && issueCode.equals(fixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(IssueResolutionAcceptor.class);
}
return result;
}
};
}
use of org.eclipse.xtext.validation.Issue in project dsl-devkit by dsldevkit.
the class FormatFragmentUtil method getFormatModel.
/**
* Retrieve the format model associated with a given grammar.
* <p>
* <em>Note</em>: Expected to either be in same folder with the same name (except for the extension) or in the SRC outlet.
* </p>
*
* @param grammar
* the grammar, must not be {@code null}
* @param context
* xpand execution context, must not be {@code null}
* @return the format model, or {@code null} if the resource could not be loaded
* @throws FileNotFoundException
* thrown if the format file could not be found
*/
@SuppressWarnings("PMD.NPathComplexity")
public static FormatConfiguration getFormatModel(final Grammar grammar, final XpandExecutionContext context) throws FileNotFoundException {
Variable resourceUriVariable = context.getVariable("resourceUri");
if (resourceUriVariable == null) {
return null;
}
URI uri = (URI) resourceUriVariable.getValue();
final Resource grammarResource = grammar.eResource();
final ResourceSet resourceSet = grammarResource.getResourceSet();
Resource formatResource = null;
try {
formatResource = resourceSet.getResource(uri, true);
} catch (final ClasspathUriResolutionException e) {
// make another attempt
uri = getDefaultFormatLocation(grammar, context);
try {
formatResource = resourceSet.getResource(uri, true);
} catch (WrappedException e1) {
formatResource = resourceSet.getResource(uri, false);
if (formatResource != null) {
resourceSet.getResources().remove(formatResource);
}
// NOPMD
throw new FileNotFoundException(uri.toString());
}
}
if (formatResource == null) {
throw new FileNotFoundException(uri.toString());
}
final List<Issue> issues = getModelValidator().validate(formatResource, LOG);
for (final Issue issue : issues) {
if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
throw new WorkflowInterruptedException("Errors found in " + uri.toString() + ": " + issue.getMessage());
}
}
return formatResource.getContents().size() == 0 ? null : (FormatConfiguration) formatResource.getContents().get(0);
}
use of org.eclipse.xtext.validation.Issue in project statecharts by Yakindu.
the class DefaultValidationIssueStore method processIssues.
@Override
public synchronized void processIssues(List<Issue> issues, IProgressMonitor monitor) {
final Multimap<String, SCTIssue> newVisibleIssues = ArrayListMultimap.create();
for (Issue issue : issues) {
if (issue instanceof SCTIssue) {
String semanticURI = ((SCTIssue) issue).getSemanticURI();
newVisibleIssues.put(semanticURI, (SCTIssue) issue);
}
}
final Multimap<String, SCTIssue> oldVisibleIssues = ArrayListMultimap.create();
synchronized (visibleIssues) {
oldVisibleIssues.putAll(visibleIssues);
// normal and expensive checks will not be executed by the live
// validation, so persistent markers have to be copied
Iterable<SCTIssue> persistentIssues = Iterables.filter(visibleIssues.values(), new Predicate<SCTIssue>() {
public boolean apply(SCTIssue input) {
CheckType type = input.getType();
Severity severity = input.getSeverity();
return CheckType.NORMAL == type || CheckType.EXPENSIVE == type || Severity.INFO == severity;
}
});
for (SCTIssue sctIssue : persistentIssues) {
newVisibleIssues.put(sctIssue.getSemanticURI(), sctIssue);
}
visibleIssues.clear();
visibleIssues.putAll(newVisibleIssues);
}
SetView<String> changes = Sets.symmetricDifference(oldVisibleIssues.keySet(), newVisibleIssues.keySet());
for (String string : changes) {
notifyListeners(string);
}
SetView<String> intersection = Sets.intersection(oldVisibleIssues.keySet(), newVisibleIssues.keySet());
for (String string : intersection) {
if (changedSeverity(string, oldVisibleIssues, newVisibleIssues) || changedErrorCount(string, oldVisibleIssues, newVisibleIssues)) {
notifyListeners(string);
}
}
}
Aggregations