Search in sources :

Example 41 with Diagnostic

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

the class AbstractDeclarativeValidator method createDiagnostic.

protected Diagnostic createDiagnostic(Severity severity, String message, EObject object, int offset, int length, String code, String... issueData) {
    int diagnosticSeverity = toDiagnosticSeverity(severity);
    Diagnostic result = new RangeBasedDiagnostic(diagnosticSeverity, message, object, offset, length, state.get().currentCheckType, code, issueData);
    return result;
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic)

Example 42 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic 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)

Example 43 with Diagnostic

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

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

the class ImportUriValidatorTest method emptyImportURIStringShouldBeInvalid.

/**
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=385620
 */
@Test
public void emptyImportURIStringShouldBeInvalid() throws Exception {
    String model = "import ''";
    Resource resource = getResourceFromString(model);
    Diagnostic diagnostics = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertEquals(Diagnostic.ERROR, diagnostics.getSeverity());
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Test(org.junit.Test)

Example 45 with Diagnostic

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

the class AbstractDeclarativeValidator method createDiagnostic.

protected Diagnostic createDiagnostic(Severity severity, String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
    int diagnosticSeverity = toDiagnosticSeverity(severity);
    Diagnostic result = new FeatureBasedDiagnostic(diagnosticSeverity, message, object, feature, index, state.get().currentCheckType, code, issueData);
    return result;
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic)

Aggregations

Diagnostic (org.eclipse.emf.common.util.Diagnostic)73 Test (org.junit.Test)63 XtextResource (org.eclipse.xtext.resource.XtextResource)56 EObject (org.eclipse.emf.ecore.EObject)11 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)5 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 EPackage (org.eclipse.emf.ecore.EPackage)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 AbstractValidationDiagnostic (org.eclipse.xtext.validation.AbstractValidationDiagnostic)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Generator (org.eclipse.emf.codegen.ecore.generator.Generator)1