Search in sources :

Example 31 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.

the class AbstractXtextTests method getResourceAndExpect.

public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception {
    XtextResource resource = doGetResource(in, uri);
    checkNodeModel(resource);
    if (expectedErrors != UNKNOWN_EXPECTATION) {
        if (expectedErrors == EXPECT_ERRORS)
            assertFalse(Joiner.on('\n').join(resource.getErrors()), resource.getErrors().isEmpty());
        else
            assertEquals(Joiner.on('\n').join(resource.getErrors()), expectedErrors, resource.getErrors().size());
    }
    for (Diagnostic d : resource.getErrors()) {
        if (d instanceof ExceptionDiagnostic)
            fail(d.getMessage());
    }
    if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) {
        SerializerTestHelper tester = get(SerializerTestHelper.class);
        EObject obj = resource.getContents().get(0);
        tester.assertSerializeWithNodeModel(obj);
        tester.assertSerializeWithoutNodeModel(obj);
    }
    return resource;
}
Also used : SerializerTestHelper(org.eclipse.xtext.testing.serializer.SerializerTestHelper) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 32 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.

the class Bug362902Test method testNoExceptionUncaught.

@Test
public void testNoExceptionUncaught() throws Exception {
    String modelAsString = "Hello max ! Hello peter! favourite peter";
    Model model = (Model) getModelAndExpect(modelAsString, 2);
    EList<Diagnostic> errors = model.eResource().getErrors();
    Diagnostic diagnosticSyntax = errors.get(0);
    Diagnostic diagnosticLinking = errors.get(1);
    assertTrue(diagnosticSyntax instanceof XtextSyntaxDiagnostic);
    assertTrue(diagnosticLinking instanceof XtextLinkingDiagnostic);
}
Also used : XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) Model(org.eclipse.xtext.linking.bug362902.Model) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Aggregations

Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)32 Test (org.junit.Test)12 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 XtextResource (org.eclipse.xtext.resource.XtextResource)8 XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)7 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)6 Issue (org.eclipse.xtext.validation.Issue)6 List (java.util.List)5 EObject (org.eclipse.emf.ecore.EObject)5 Severity (org.eclipse.xtext.diagnostics.Severity)5 IDiagnosticConverter (org.eclipse.xtext.validation.IDiagnosticConverter)5 ResourceValidatorImpl (org.eclipse.xtext.validation.ResourceValidatorImpl)5 IOException (java.io.IOException)4 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)3 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)3 ComparisonFailure (org.junit.ComparisonFailure)3 ArrayList (java.util.ArrayList)2 URI (org.eclipse.emf.common.util.URI)2