use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class ValidatorTester method diagnose.
public AssertableDiagnostics diagnose() {
if (!validatorCalled)
throw new IllegalStateException("You have to call validator() before you call diagnose()");
validatorCalled = false;
AssertableDiagnostics ad = new AssertableDiagnostics((Diagnostic) validator.setMessageAcceptor(validator).getState().chain);
validator.setMessageAcceptor(validator).getState().chain = new BasicDiagnostic();
return ad;
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class AbstractCompositeValidatorTest method testBug_279962.
@Test
public void testBug_279962() {
EValidator validator = registry.getEValidator(pack);
assertTrue(validator instanceof CompositeEValidator);
CompositeEValidator composite = (CompositeEValidator) validator;
int prevSize = composite.getContents().size();
get(Val_279962_01.class);
get(Val_279962_04.class);
assertEquals(prevSize + 2, composite.getContents().size());
assertNotNull(validator);
Resource resource = get(XtextResource.class);
Model model = EnumRulesTestLanguageFactory.eINSTANCE.createModel();
resource.getContents().add(model);
// do not expect an exception
validator.validate(model, new BasicDiagnostic(), null);
assertEquals(prevSize + 4, composite.getContents().size());
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testExceptionWhenGivenWrongEObject.
@Test
public void testExceptionWhenGivenWrongEObject() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
warning("Error Message", EcorePackage.Literals.EANNOTATION, EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
}
};
BasicDiagnostic chain = new BasicDiagnostic();
Resource r = new ResourceImpl(URI.createURI("http://foo"));
EObject x = EcoreFactory.eINSTANCE.createEAttribute();
r.getContents().add(x);
try {
test.validate(x, chain, Collections.emptyMap());
fail("expected exception");
} catch (IllegalArgumentException e) {
// expected
}
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testErrorWithCode.
@Test
public void testErrorWithCode() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
error("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
}
};
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(0, diag.getCode());
assertTrue(diag instanceof FeatureBasedDiagnostic);
assertEquals("42", ((FeatureBasedDiagnostic) diag).getIssueCode());
assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testWarningWithCode.
@Test
public void testWarningWithCode() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
warning("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
}
};
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(0, diag.getCode());
assertTrue(diag instanceof FeatureBasedDiagnostic);
assertEquals("42", ((FeatureBasedDiagnostic) diag).getIssueCode());
assertEquals(Diagnostic.WARNING, diag.getSeverity());
}
Aggregations