use of org.eclipse.emf.common.util.DiagnosticChain 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.DiagnosticChain in project xtext-core by eclipse.
the class XtextGeneratorLanguage method validateGrammar.
protected void validateGrammar(final Grammar grammar) {
this.validateAllImports(grammar);
final EValidator validator = EValidator.Registry.INSTANCE.getEValidator(XtextPackage.eINSTANCE);
if ((validator != null)) {
final DiagnosticChain chain = new DiagnosticChain() {
@Override
public void add(final Diagnostic diagnostic) {
int _severity = diagnostic.getSeverity();
boolean _equals = (_severity == Diagnostic.ERROR);
if (_equals) {
String _name = grammar.getName();
String _plus = ("Validation Error in " + _name);
final String grammarName = (_plus + ": ");
Throwable _exception = diagnostic.getException();
boolean _tripleEquals = (_exception == null);
if (_tripleEquals) {
String _message = diagnostic.getMessage();
String _plus_1 = (grammarName + _message);
throw new IllegalStateException(_plus_1);
} else {
String _message_1 = diagnostic.getMessage();
String _plus_2 = (grammarName + _message_1);
Throwable _exception_1 = diagnostic.getException();
throw new IllegalStateException(_plus_2, _exception_1);
}
}
}
@Override
public void addAll(final Diagnostic diagnostic) {
this.add(diagnostic);
}
@Override
public void merge(final Diagnostic diagnostic) {
throw new UnsupportedOperationException();
}
};
validator.validate(grammar, chain, null);
final TreeIterator<EObject> iterator = grammar.eAllContents();
while (iterator.hasNext()) {
EObject _next = iterator.next();
HashMap<Object, Object> _hashMap = new HashMap<Object, Object>();
validator.validate(_next, chain, _hashMap);
}
}
}
Aggregations