use of org.eclipse.emf.ecore.EValidator in project xtext-core by eclipse.
the class EValidatorRegistrar method register.
public void register(EPackage ePackage, EValidator registerMe) {
EValidator validator = getRegistry().getEValidator(ePackage);
if (validator == null) {
validator = compositeProvider.get();
} else if (!(validator instanceof CompositeEValidator)) {
CompositeEValidator newValidator = compositeProvider.get();
newValidator.addValidator(validator);
validator = newValidator;
}
((CompositeEValidator) validator).addValidator(registerMe);
getRegistry().put(ePackage, validator);
}
use of org.eclipse.emf.ecore.EValidator in project xtext-core by eclipse.
the class AbstractCompositeValidatorTest method testFirstAndSecond.
@Test
public void testFirstAndSecond() {
EValidator validator = registry.getEValidator(pack);
assertNotNull(validator);
assertTrue(validator instanceof CompositeEValidator);
CompositeEValidator composite = (CompositeEValidator) validator;
Collection<EValidatorEqualitySupport> contents = composite.getContents();
EValidatorEqualitySupport equalitySupport = get(EValidatorEqualitySupport.class);
equalitySupport.setDelegate(first);
assertTrue(contents.contains(equalitySupport));
equalitySupport.setDelegate(second);
assertTrue(contents.contains(equalitySupport));
}
use of org.eclipse.emf.ecore.EValidator 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.ecore.EValidator 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);
}
}
}
use of org.eclipse.emf.ecore.EValidator in project ow by vtst.
the class ValidatorPageHelper method getValidator.
/**
* @return The validator configured by the property page.
* The default package looks for an AbstractDeclarativeValidator associated with the package.
*/
protected AbstractDeclarativeValidator getValidator() {
if (ePackage == null) {
showErrorMessageDuringInit("EPackage not injected");
return null;
}
EValidator validator = eValidatorRegistry.getEValidator(ePackage);
if (validator == null) {
showErrorMessageDuringInit("No validator found for the current package");
return null;
}
ArrayList<AbstractDeclarativeValidator> declarativeValidators = new ArrayList<AbstractDeclarativeValidator>(1);
getValidatorRec(validator, declarativeValidators);
if (declarativeValidators.size() != 1) {
showErrorMessageDuringInit("Found the following declarative validators: ");
for (AbstractDeclarativeValidator v : declarativeValidators) showErrorMessageDuringInit(v.getClass().getName());
return null;
}
return declarativeValidators.get(0);
}
Aggregations