Search in sources :

Example 1 with EValidator

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);
}
Also used : EValidator(org.eclipse.emf.ecore.EValidator)

Example 2 with EValidator

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));
}
Also used : EValidatorEqualitySupport(org.eclipse.xtext.validation.CompositeEValidator.EValidatorEqualitySupport) EValidator(org.eclipse.emf.ecore.EValidator) Test(org.junit.Test)

Example 3 with EValidator

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;
        }
    });
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Type(org.eclipse.xtext.linking.langATestLanguage.Type) EClass(org.eclipse.emf.ecore.EClass) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EDataType(org.eclipse.emf.ecore.EDataType) EObject(org.eclipse.emf.ecore.EObject) EValidator(org.eclipse.emf.ecore.EValidator) DiagnosticChain(org.eclipse.emf.common.util.DiagnosticChain) EObject(org.eclipse.emf.ecore.EObject) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)

Example 4 with EValidator

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) EValidator(org.eclipse.emf.ecore.EValidator) DiagnosticChain(org.eclipse.emf.common.util.DiagnosticChain) EObject(org.eclipse.emf.ecore.EObject)

Example 5 with EValidator

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);
}
Also used : AbstractDeclarativeValidator(org.eclipse.xtext.validation.AbstractDeclarativeValidator) ArrayList(java.util.ArrayList) EValidator(org.eclipse.emf.ecore.EValidator) CompositeEValidator(org.eclipse.xtext.validation.CompositeEValidator)

Aggregations

EValidator (org.eclipse.emf.ecore.EValidator)9 Test (org.junit.Test)4 EValidatorEqualitySupport (org.eclipse.xtext.validation.CompositeEValidator.EValidatorEqualitySupport)3 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)2 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)2 EObject (org.eclipse.emf.ecore.EObject)2 CompositeEValidator (org.eclipse.xtext.validation.CompositeEValidator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 EClass (org.eclipse.emf.ecore.EClass)1 EDataType (org.eclipse.emf.ecore.EDataType)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Model (org.eclipse.xtext.enumrules.enumRulesTestLanguage.Model)1 LangATestLanguageStandaloneSetup (org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)1 Type (org.eclipse.xtext.linking.langATestLanguage.Type)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 AbstractDeclarativeValidator (org.eclipse.xtext.validation.AbstractDeclarativeValidator)1