Search in sources :

Example 66 with Diagnostic

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

the class XtextValidationTest method testLeftRecursion_Bug_285605_07.

@Test
public void testLeftRecursion_Bug_285605_07() 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+=RuleA | '_')* name=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(), 4, 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 67 with Diagnostic

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

the class XtextValidationTest method testLeftRecursion_Bug_285605_11.

@Test
public void testLeftRecursion_Bug_285605_11() 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=RuleA & ruleB=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 68 with Diagnostic

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

the class XtextValidationTest method testLeftRecursion_Bug_285605_01.

@Test
public void testLeftRecursion_Bug_285605_01() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate foo 'http://foo/bar'\n" + "RuleA : ruleA=RuleA;");
    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(), 2, 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 69 with Diagnostic

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

the class XtextValidationTest method testOverrideFinal_1.

@Test
public void testOverrideFinal_1() throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" + "generate supergrammar \"http://org.xtext.supergrammar\"\n" + "@Final\n" + "RuleFinal:name=ID;\n" + "Rule: name=ID;", "superGrammar.xtext", rs);
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.xtext.Supergrammar\n" + "generate bar \"http://org.xtext.Bar\"\n" + "@Override Rule: name=ID;", "foo.xtext", rs);
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    List<Diagnostic> issues = diag.getChildren();
    assertEquals(issues.toString(), 0, issues.size());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 70 with Diagnostic

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

the class XtextValidationTest method testGrammarHasNoNamespace.

/**
 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=348052
 */
@Test
public void testGrammarHasNoNamespace() throws Exception {
    XtextResource resource = getResourceFromString("grammar Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: name=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(), 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