use of org.eclipse.xtext.diagnostics.Severity in project dsl-devkit by dsldevkit.
the class ModelValidator method logIssue.
/**
* Log issue.
*
* @param resource
* the resource
* @param issue
* the issue
* @param logger
* the logger
*/
private void logIssue(final Resource resource, final Issue issue, final Logger logger) {
final String message = NLS.bind(MESSAGE_TEMPLATE, new Object[] { resource.getURI().lastSegment(), issue.getLineNumber(), issue.getMessage() });
final Severity severity = issue.getSeverity();
switch(severity) {
case ERROR:
logger.error(message);
break;
case WARNING:
logger.warn(message);
break;
case INFO:
if (logger.isInfoEnabled()) {
logger.info(message);
}
break;
default:
break;
}
}
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-xtend by eclipse.
the class NoJRESmokeTester method checkNoErrorsInValidator.
protected void checkNoErrorsInValidator(final String model, XtextResource resource) {
ResourceValidatorImpl validator = resourceValidatorProvider.get();
Assert.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);
throwError(t);
}
if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
throwError(new RuntimeException("Dangling reference found."));
}
}
}
private void throwError(Throwable e) {
ComparisonFailure result = new ComparisonFailure(e.getMessage(), model, "");
result.setStackTrace(e.getStackTrace());
throw result;
}
@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof ExceptionDiagnostic) {
Exception e = ((ExceptionDiagnostic) diagnostic).getException();
throwError(e);
}
}
});
validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-eclipse by eclipse.
the class IssueUtil method createIssue.
/**
* Creates an Issue out of a Marker.
* setSyntaxError is unset since the current API does not allow fixing systax errors anyway.
*
* @param marker The marker to create an issue from
* @return an issue created out of the given marker or <code>null</code>
*/
public Issue createIssue(IMarker marker) {
Issue.IssueImpl issue = new Issue.IssueImpl();
try {
Map<String, Object> attributes = marker.getAttributes();
String markerType = marker.getType();
Object message = attributes.get(IMarker.MESSAGE);
issue.setMessage(message instanceof String ? (String) message : null);
Object lineNumber = attributes.get(IMarker.LINE_NUMBER);
issue.setLineNumber(lineNumber instanceof Integer ? (Integer) lineNumber : null);
Object column = attributes.get(Issue.COLUMN_KEY);
issue.setColumn(column instanceof Integer ? (Integer) column : null);
Object offset = attributes.get(IMarker.CHAR_START);
Object endOffset = attributes.get(IMarker.CHAR_END);
if (offset instanceof Integer && endOffset instanceof Integer) {
issue.setOffset((Integer) offset);
issue.setLength((Integer) endOffset - (Integer) offset);
} else {
issue.setOffset(-1);
issue.setLength(0);
}
Object code = attributes.get(Issue.CODE_KEY);
issue.setCode(code instanceof String ? (String) code : null);
Object data = attributes.get(Issue.DATA_KEY);
issue.setData(data instanceof String ? Strings.unpack((String) data) : null);
Object uri = attributes.get(Issue.URI_KEY);
issue.setUriToProblem(uri instanceof String ? URI.createURI((String) uri) : null);
Object severity = attributes.get(IMarker.SEVERITY);
Severity translatedSeverity = translateSeverity(severity instanceof Integer ? (Integer) severity : 0);
if (translatedSeverity == null)
throw new IllegalArgumentException(marker.toString());
issue.setSeverity(translatedSeverity);
if (markerTypeProvider != null)
issue.setType(markerTypeProvider.getCheckType(markerType));
else
issue.setType(MarkerTypes.toCheckType(markerType));
} catch (CoreException e) {
return null;
}
return issue;
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-eclipse by eclipse.
the class XtextEditorErrorTickUpdater method updateEditorImage.
protected void updateEditorImage(XtextEditor xtextEditor) {
Severity severity = getSeverity(xtextEditor);
if (severity != null && severity != Severity.INFO) {
ImageDescriptor descriptor = severity == Severity.ERROR ? XtextPluginImages.DESC_OVR_ERROR : XtextPluginImages.DESC_OVR_WARNING;
DecorationOverlayIcon decorationOverlayIcon = new DecorationOverlayIcon(defaultImage, descriptor, IDecoration.BOTTOM_LEFT);
scheduleUpdateEditor(decorationOverlayIcon);
} else {
scheduleUpdateEditor(defaultImage);
}
}
Aggregations