Search in sources :

Example 61 with BasicDiagnostic

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

the class ValidatorTester method diagnose.

public AssertableDiagnostics diagnose() {
    if (!validatorCalled)
        throw new IllegalStateException("You have to call validator() before you call diagnose()");
    validatorCalled = false;
    AssertableDiagnostics ad = new AssertableDiagnostics((Diagnostic) validator.setMessageAcceptor(validator).getState().chain);
    validator.setMessageAcceptor(validator).getState().chain = new BasicDiagnostic();
    return ad;
}
Also used : AssertableDiagnostics(org.eclipse.xtext.testing.validation.AssertableDiagnostics) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic)

Example 62 with BasicDiagnostic

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

the class AbstractCompositeValidatorTest method testBug_279962.

@Test
public void testBug_279962() {
    EValidator validator = registry.getEValidator(pack);
    assertTrue(validator instanceof CompositeEValidator);
    CompositeEValidator composite = (CompositeEValidator) validator;
    int prevSize = composite.getContents().size();
    get(Val_279962_01.class);
    get(Val_279962_04.class);
    assertEquals(prevSize + 2, composite.getContents().size());
    assertNotNull(validator);
    Resource resource = get(XtextResource.class);
    Model model = EnumRulesTestLanguageFactory.eINSTANCE.createModel();
    resource.getContents().add(model);
    // do not expect an exception
    validator.validate(model, new BasicDiagnostic(), null);
    assertEquals(prevSize + 4, composite.getContents().size());
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.xtext.enumrules.enumRulesTestLanguage.Model) EValidator(org.eclipse.emf.ecore.EValidator) Test(org.junit.Test)

Example 63 with BasicDiagnostic

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

the class DeclarativeValidatorTest method testExceptionWhenGivenWrongEObject.

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

        @Check
        public void foo(Object x) {
            warning("Error Message", EcorePackage.Literals.EANNOTATION, EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
        }
    };
    BasicDiagnostic chain = new BasicDiagnostic();
    Resource r = new ResourceImpl(URI.createURI("http://foo"));
    EObject x = EcoreFactory.eINSTANCE.createEAttribute();
    r.getContents().add(x);
    try {
        test.validate(x, chain, Collections.emptyMap());
        fail("expected exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 64 with BasicDiagnostic

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

the class DeclarativeValidatorTest method testErrorWithCode.

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

        @Check
        public void foo(Object x) {
            error("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
        }
    };
    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(0, diag.getCode());
    assertTrue(diag instanceof FeatureBasedDiagnostic);
    assertEquals("42", ((FeatureBasedDiagnostic) diag).getIssueCode());
    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 65 with BasicDiagnostic

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

the class DeclarativeValidatorTest method testWarningWithCode.

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

        @Check
        public void foo(Object x) {
            warning("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
        }
    };
    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(0, diag.getCode());
    assertTrue(diag instanceof FeatureBasedDiagnostic);
    assertEquals("42", ((FeatureBasedDiagnostic) diag).getIssueCode());
    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)

Aggregations

BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)107 Diagnostic (org.eclipse.emf.common.util.Diagnostic)50 EObject (org.eclipse.emf.ecore.EObject)43 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)20 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