Search in sources :

Example 16 with Diagnostic

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

the class XtextValidationTest method testBug_283534_02.

@Test
public void testBug_283534_02() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "enum EnumRule: Zonk;\n" + "Model: name=STRING;\n");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertNotNull("diag", diag);
    assertEquals(diag.getChildren().toString(), 1, diag.getChildren().size());
    assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 17 with Diagnostic

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

the class XtextValidationTest method testBug_283534_07.

@Test
public void testBug_283534_07() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "Model: ID;\n");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertNotNull("diag", diag);
    assertEquals(diag.getChildren().toString(), 0, diag.getChildren().size());
    assertEquals("diag.isOk", diag.getSeverity(), Diagnostic.OK);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 18 with Diagnostic

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

the class XtextValidationTest method assertBug322875.

protected void assertBug322875(XtextResource resource) {
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertNotNull("diag", diag);
    assertEquals(diag.toString(), 0, diag.getChildren().size());
    assertEquals("diag.isOk", Diagnostic.OK, diag.getSeverity());
    int xtextPackageCounter = 0;
    int validationTestCounter = 0;
    for (Resource packResource : resource.getResourceSet().getResources()) {
        EObject object = packResource.getContents().get(0);
        if (object instanceof EPackage) {
            String nsURI = ((EPackage) object).getNsURI();
            if (nsURI.equals("http://www.eclipse.org/2008/Xtext"))
                xtextPackageCounter++;
            if (nsURI.equals("http://XtextValidationBugs")) {
                validationTestCounter++;
            }
        }
    }
    assertEquals(1, xtextPackageCounter);
    assertEquals(1, validationTestCounter);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) XtextResource(org.eclipse.xtext.resource.XtextResource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EPackage(org.eclipse.emf.ecore.EPackage)

Example 19 with Diagnostic

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

the class XtextValidationTest method testLeftRecursion_Bug_285605_04.

@Test
public void testLeftRecursion_Bug_285605_04() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate foo 'http://foo/bar'\n" + "RuleA : ruleB=RuleB;\n" + "RuleB : ruleC=RuleC;\n" + "RuleC : RuleA|RuleB;\n");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertNotNull("diag", diag);
    assertEquals(diag.getChildren().toString(), 6, diag.getChildren().size());
    assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 20 with Diagnostic

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

the class XtextValidationTest method testBug_283534_04.

@Test
public void testBug_283534_04() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: ID;\n" + "SecondModel: name=STRING;\n");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertNotNull("diag", diag);
    assertEquals(diag.getChildren().toString(), 1, diag.getChildren().size());
    assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

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