Search in sources :

Example 1 with DiagnosticChain

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;
        }
    });
}
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 2 with DiagnosticChain

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);
        }
    }
}
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)

Aggregations

DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)2 EObject (org.eclipse.emf.ecore.EObject)2 EValidator (org.eclipse.emf.ecore.EValidator)2 HashMap (java.util.HashMap)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 EClass (org.eclipse.emf.ecore.EClass)1 EDataType (org.eclipse.emf.ecore.EDataType)1 LangATestLanguageStandaloneSetup (org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)1 Type (org.eclipse.xtext.linking.langATestLanguage.Type)1