use of org.eclipse.xtext.diagnostics.ExceptionDiagnostic in project xtext-eclipse 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.ExceptionDiagnostic in project n4js by eclipse.
the class ExceptionAnalyser method getScriptErrors.
@Override
protected List<Diagnostic> getScriptErrors(Script script) {
EcoreUtil.resolveAll(script.eResource());
List<Diagnostic> diagnostics = super.getScriptErrors(script);
Iterator<Expression> expressions = Iterators.filter(EcoreUtil2.eAll(script), Expression.class);
List<Diagnostic> result = Lists.<Diagnostic>newArrayList(Iterables.filter(diagnostics, ExceptionDiagnostic.class));
while (expressions.hasNext()) {
Expression expression = expressions.next();
RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(expression);
Result<TypeRef> type = typeSystem.type(ruleEnvironment, expression);
if (type.getRuleFailedException() != null) {
Throwable cause = Throwables.getRootCause(type.getRuleFailedException());
if (!(cause instanceof RuleFailedException)) {
if (cause instanceof Exception) {
result.add(new ExceptionDiagnostic((Exception) cause));
} else {
throw new RuntimeException(cause);
}
}
}
}
validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
return result;
}
use of org.eclipse.xtext.diagnostics.ExceptionDiagnostic 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.ExceptionDiagnostic in project xtext-xtend by eclipse.
the class LinkingErrorTest method assertNoExceptions.
protected void assertNoExceptions(EObject object) {
Resource resource = object.eResource();
if (resource instanceof LazyLinkingResource)
((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
List<Diagnostic> errors = object.eResource().getErrors();
for (Diagnostic error : errors) {
if (error instanceof ExceptionDiagnostic) {
((ExceptionDiagnostic) error).getException().printStackTrace();
}
assertFalse(error.toString(), error instanceof ExceptionDiagnostic);
}
validateWithoutException((XtextResource) resource);
}
use of org.eclipse.xtext.diagnostics.ExceptionDiagnostic 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);
}
Aggregations