Search in sources :

Example 6 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-xtend by eclipse.

the class NoJRESmokeTester method checkNoErrorsInValidator.

protected void checkNoErrorsInValidator(final String model, XtextResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    Assert.assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
    validator.setDiagnosticConverter(new IDiagnosticConverter() {

        @Override
        public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof BasicDiagnostic) {
                List<?> data = diagnostic.getData();
                if (!data.isEmpty() && data.get(0) instanceof Throwable) {
                    Throwable t = (Throwable) data.get(0);
                    throwError(t);
                }
                if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
                    throwError(new RuntimeException("Dangling reference found."));
                }
            }
        }

        private void throwError(Throwable e) {
            ComparisonFailure result = new ComparisonFailure(e.getMessage(), model, "");
            result.setStackTrace(e.getStackTrace());
            throw result;
        }

        @Override
        public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof ExceptionDiagnostic) {
                Exception e = ((ExceptionDiagnostic) diagnostic).getException();
                throwError(e);
            }
        }
    });
    validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ComparisonFailure(org.junit.ComparisonFailure) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 7 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-xtend by eclipse.

the class PartialParserTest method validateWithoutException.

protected void validateWithoutException(XtextResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
    validator.setDiagnosticConverter(new IDiagnosticConverter() {

        @Override
        public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof BasicDiagnostic) {
                List<?> data = diagnostic.getData();
                if (!data.isEmpty() && data.get(0) instanceof Throwable) {
                    Throwable t = (Throwable) data.get(0);
                    // and AssertionError does not take a throwable as argument
                    throw new Error(t);
                }
                if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
                    throw new Error(new RuntimeException("Dangling reference found."));
                }
            }
        }

        @Override
        public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof ExceptionDiagnostic) {
                Exception e = ((ExceptionDiagnostic) diagnostic).getException();
                // and AssertionError does not take a throwable as argument
                throw new Error(new RuntimeException(e));
            }
        }
    });
    validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) IOException(java.io.IOException) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 8 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.

the class DeclarativeValidatorTest method testWarningWithSource.

@Test
public void testWarningWithSource() {
    AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {

        @Check
        public void foo(Object x) {
            warning("Error Message", EcorePackage.eINSTANCE.getEAnnotation(), EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
        }
    };
    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.getEAnnotation().toString(), diag.getSource());
    assertEquals(Diagnostic.WARNING, diag.getSeverity());
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 9 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.

the class DeclarativeValidatorTest method testError.

@Test
public void testError() {
    AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {

        @Check
        public void foo(Object x) {
            error("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.ERROR, diag.getSeverity());
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 10 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-core by eclipse.

the class DeclarativeValidatorTest method testErrorWithSource.

@Test
public void testErrorWithSource() {
    AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {

        @Check
        public void foo(Object x) {
            error("Error Message", EcorePackage.eINSTANCE.getEAnnotation(), EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
        }
    };
    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.getEAnnotation().toString(), diag.getSource());
    assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Aggregations

BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)103 Diagnostic (org.eclipse.emf.common.util.Diagnostic)48 EObject (org.eclipse.emf.ecore.EObject)41 EventObject (java.util.EventObject)30 CoreException (org.eclipse.core.runtime.CoreException)30 ProblemEditorPart (org.eclipse.emf.common.ui.editor.ProblemEditorPart)30 Point (org.eclipse.swt.graphics.Point)30 PartInitException (org.eclipse.ui.PartInitException)30 Test (org.junit.Test)16 List (java.util.List)13 Iterator (java.util.Iterator)8 BasicEList (org.eclipse.emf.common.util.BasicEList)8 EList (org.eclipse.emf.common.util.EList)8 WrappedException (org.eclipse.emf.common.util.WrappedException)8 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)5 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)5 Severity (org.eclipse.xtext.diagnostics.Severity)5 IDiagnosticConverter (org.eclipse.xtext.validation.IDiagnosticConverter)5 Issue (org.eclipse.xtext.validation.Issue)5 ResourceValidatorImpl (org.eclipse.xtext.validation.ResourceValidatorImpl)5