use of org.eclipse.emf.common.util.BasicDiagnostic 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.emf.common.util.BasicDiagnostic 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.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testWarningWithSource.
@Test
public void testWarningWithSource() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
warning("Error Message", EcorePackage.eINSTANCE.getEAnnotation(), EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
}
};
BasicDiagnostic chain = new BasicDiagnostic();
test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
assertEquals(1, chain.getChildren().size());
Diagnostic diag = chain.getChildren().get(0);
assertEquals("Error Message", diag.getMessage());
assertEquals(EcorePackage.eINSTANCE.getEAnnotation().toString(), diag.getSource());
assertEquals(Diagnostic.WARNING, diag.getSeverity());
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testError.
@Test
public void testError() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
error("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME);
}
};
BasicDiagnostic chain = new BasicDiagnostic();
test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
assertEquals(1, chain.getChildren().size());
Diagnostic diag = chain.getChildren().get(0);
assertEquals("Error Message", diag.getMessage());
assertEquals(EcorePackage.eINSTANCE.getEClass().toString(), diag.getSource());
assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testErrorWithSource.
@Test
public void testErrorWithSource() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
error("Error Message", EcorePackage.eINSTANCE.getEAnnotation(), EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
}
};
BasicDiagnostic chain = new BasicDiagnostic();
test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
assertEquals(1, chain.getChildren().size());
Diagnostic diag = chain.getChildren().get(0);
assertEquals("Error Message", diag.getMessage());
assertEquals(EcorePackage.eINSTANCE.getEAnnotation().toString(), diag.getSource());
assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
Aggregations