use of org.eclipse.xtext.diagnostics.Severity in project xtext-xtend by eclipse.
the class PartialParserTest method validateWithoutException.
protected void validateWithoutException(XtextResource resource) {
ResourceValidatorImpl validator = resourceValidatorProvider.get();
assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
validator.setDiagnosticConverter(new IDiagnosticConverter() {
@Override
public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof BasicDiagnostic) {
List<?> data = diagnostic.getData();
if (!data.isEmpty() && data.get(0) instanceof Throwable) {
Throwable t = (Throwable) data.get(0);
// and AssertionError does not take a throwable as argument
throw new Error(t);
}
if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
throw new Error(new RuntimeException("Dangling reference found."));
}
}
}
@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof ExceptionDiagnostic) {
Exception e = ((ExceptionDiagnostic) diagnostic).getException();
// and AssertionError does not take a throwable as argument
throw new Error(new RuntimeException(e));
}
}
});
validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-core by eclipse.
the class LanguageServerImpl method publishDiagnostics.
private void publishDiagnostics(final URI uri, final Iterable<? extends Issue> issues) {
PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams();
final Procedure1<PublishDiagnosticsParams> _function = (PublishDiagnosticsParams it) -> {
it.setUri(this._uriExtensions.toUriString(uri));
final Function1<Issue, Boolean> _function_1 = (Issue it_1) -> {
Severity _severity = it_1.getSeverity();
return Boolean.valueOf((_severity != Severity.IGNORE));
};
final Function1<Issue, Diagnostic> _function_2 = (Issue it_1) -> {
return this.toDiagnostic(it_1);
};
it.setDiagnostics(IterableExtensions.<Diagnostic>toList(IterableExtensions.map(IterableExtensions.filter(issues, _function_1), _function_2)));
};
final PublishDiagnosticsParams diagnostics = ObjectExtensions.<PublishDiagnosticsParams>operator_doubleArrow(_publishDiagnosticsParams, _function);
this.client.publishDiagnostics(diagnostics);
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-core by eclipse.
the class LanguageServerImpl method toDiagnostic.
private Diagnostic toDiagnostic(final Issue issue) {
Diagnostic _diagnostic = new Diagnostic();
final Procedure1<Diagnostic> _function = (Diagnostic it) -> {
it.setCode(issue.getCode());
DiagnosticSeverity _switchResult = null;
Severity _severity = issue.getSeverity();
if (_severity != null) {
switch(_severity) {
case ERROR:
_switchResult = DiagnosticSeverity.Error;
break;
case WARNING:
_switchResult = DiagnosticSeverity.Warning;
break;
case INFO:
_switchResult = DiagnosticSeverity.Information;
break;
default:
_switchResult = DiagnosticSeverity.Hint;
break;
}
} else {
_switchResult = DiagnosticSeverity.Hint;
}
it.setSeverity(_switchResult);
it.setMessage(issue.getMessage());
Integer _elvis = null;
Integer _lineNumber = issue.getLineNumber();
if (_lineNumber != null) {
_elvis = _lineNumber;
} else {
_elvis = Integer.valueOf(1);
}
final int lineNumber = ((_elvis).intValue() - 1);
Integer _elvis_1 = null;
Integer _column = issue.getColumn();
if (_column != null) {
_elvis_1 = _column;
} else {
_elvis_1 = Integer.valueOf(1);
}
final int column = ((_elvis_1).intValue() - 1);
Integer _elvis_2 = null;
Integer _length = issue.getLength();
if (_length != null) {
_elvis_2 = _length;
} else {
_elvis_2 = Integer.valueOf(0);
}
final Integer length = _elvis_2;
Position _position = new Position(lineNumber, column);
Position _position_1 = new Position(lineNumber, (column + (length).intValue()));
Range _range = new Range(_position, _position_1);
it.setRange(_range);
};
return ObjectExtensions.<Diagnostic>operator_doubleArrow(_diagnostic, _function);
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-core by eclipse.
the class DiagnosticConverterImpl method convertValidatorDiagnostic.
@Override
public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
Severity severity = getSeverity(diagnostic);
if (severity == null)
return;
IssueImpl issue = new Issue.IssueImpl();
issue.setSeverity(severity);
IssueLocation locationData = getLocationData(diagnostic);
if (locationData != null) {
issue.setLineNumber(locationData.lineNumber);
issue.setColumn(locationData.column);
issue.setOffset(locationData.offset);
issue.setLength(locationData.length);
}
final EObject causer = getCauser(diagnostic);
if (causer != null)
issue.setUriToProblem(EcoreUtil.getURI(causer));
issue.setCode(getIssueCode(diagnostic));
issue.setType(getIssueType(diagnostic));
issue.setData(getIssueData(diagnostic));
// marker.put(IXtextResourceChecker.DIAGNOSTIC_KEY, diagnostic);
issue.setMessage(diagnostic.getMessage());
// marker.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_LOW));
acceptor.accept(issue);
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-core by eclipse.
the class XtextDiagnosticConverter method getSeverity.
@Override
protected Severity getSeverity(Diagnostic diagnostic) {
Severity result = super.getSeverity(diagnostic);
String issueCode = getIssueCode(diagnostic);
if (result == Severity.WARNING && issueCode != null) {
// only warnings can be suppressed
EObject causer = getCauser(diagnostic);
if (causer != null) {
if (isMarkedAsIgnored(causer, issueCode)) {
return null;
}
if (!(causer instanceof AbstractRule)) {
AbstractRule rule = GrammarUtil.containingRule(causer);
if (rule != null && isMarkedAsIgnored(rule, issueCode)) {
return null;
}
}
Grammar grammar = GrammarUtil.getGrammar(causer);
if (grammar != null && isMarkedAsIgnored(grammar, issueCode)) {
return null;
}
}
}
return result;
}
Aggregations