use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testWarning.
@Test
public void testWarning() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
warning("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.WARNING, diag.getSeverity());
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class InjectableValidatorTest method testArbitraryEPackage.
@Test
public void testArbitraryEPackage() throws Exception {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
xtextResource.getContents().add(ePackage);
assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), null));
assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), context));
assertEquals(xtextResource.getLanguageName(), context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
context.clear();
assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), null));
assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), context));
assertNull(context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class InjectableValidatorTest method testWrongResource.
@Test
public void testWrongResource() throws Exception {
Main main = LangATestLanguageFactory.eINSTANCE.createMain();
XMIResource xmiResource = new XMIResourceImpl();
xmiResource.getContents().add(main);
assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), null));
assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
assertFalse(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
context.clear();
assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), null));
assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class ResourceValidatorImplTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
with(new LangATestLanguageStandaloneSetup());
EValidator.Registry.INSTANCE.put(LangATestLanguagePackage.eINSTANCE, new EValidator() {
@Override
public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
if (eObject instanceof Type) {
String name = ((Type) eObject).getName();
if (name.equals("Foo"))
diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, "", 12, "Foo", null));
if (name.equals("Bar"))
diagnostics.add(new BasicDiagnostic(Diagnostic.WARNING, "", 12, "Foo", null));
}
return true;
}
@Override
public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
return validate(eObject, diagnostics, context);
}
@Override
public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) {
return false;
}
});
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.
the class ValidatorTester method validator.
public T validator() {
State s = validator.setMessageAcceptor(validator).getState();
if (s.chain == null)
s.chain = new BasicDiagnostic();
validatorCalled = true;
return validator;
}
Aggregations