Search in sources :

Example 11 with BasicDiagnostic

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

the class DeclarativeValidatorTest method testWarning.

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

        @Check
        public void foo(Object x) {
            warning("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.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 12 with BasicDiagnostic

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

the class InjectableValidatorTest method testArbitraryEPackage.

@Test
public void testArbitraryEPackage() throws Exception {
    EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
    xtextResource.getContents().add(ePackage);
    assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), null));
    assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), context));
    assertEquals(xtextResource.getLanguageName(), context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
    context.clear();
    assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), null));
    assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), context));
    assertNull(context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 13 with BasicDiagnostic

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

the class InjectableValidatorTest method testWrongResource.

@Test
public void testWrongResource() throws Exception {
    Main main = LangATestLanguageFactory.eINSTANCE.createMain();
    XMIResource xmiResource = new XMIResourceImpl();
    xmiResource.getContents().add(main);
    assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), null));
    assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
    context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
    assertFalse(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
    context.clear();
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), null));
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
    context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) Test(org.junit.Test)

Example 14 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic 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 15 with BasicDiagnostic

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

the class ValidatorTester method validator.

public T validator() {
    State s = validator.setMessageAcceptor(validator).getState();
    if (s.chain == null)
        s.chain = new BasicDiagnostic();
    validatorCalled = true;
    return validator;
}
Also used : State(org.eclipse.xtext.validation.AbstractDeclarativeValidator.State) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic)

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