use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testDuplicateEnumLiterals.
@Test
public void testDuplicateEnumLiterals() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/validation/literal/1'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName | DifferentName='SameName';");
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);
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testTerminalAnnotation.
@Test
public void testTerminalAnnotation() throws Exception {
Resource resource = getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" + "generate supergrammar \"http://org.xtext.supergrammar\"\n" + "Rule: name=ID;\n" + "@Deprecated\n" + "terminal TERMINAL: ID;");
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
List<Diagnostic> issues = diag.getChildren();
assertEquals(issues.toString(), 1, issues.size());
assertEquals("TerminalRule cannot be deprecated!", issues.get(0).getMessage());
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testBug322875_04.
@Test
public void testBug322875_04() throws Exception {
String testGrammarNsURI = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " + " import 'http://www.eclipse.org/emf/2002/Ecore' " + "Model returns EClass: name=ID;";
String testGrammarPlatformPlugin = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " + " import 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore' " + "Model returns EClass: name=ID;";
XtextResource resourceOk = getResourceFromString(testGrammarNsURI);
XtextResource resourceOk2 = (XtextResource) resourceOk.getResourceSet().createResource(URI.createURI("unused.xtext"));
resourceOk2.load(new StringInputStream(testGrammarPlatformPlugin), null);
Diagnostic diagOK = Diagnostician.INSTANCE.validate(resourceOk.getContents().get(0));
assertNotNull("diag", diagOK);
assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
diagOK = Diagnostician.INSTANCE.validate(resourceOk2.getContents().get(0));
assertNotNull("diag", diagOK);
assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testBug_283534_01.
@Test
public void testBug_283534_01() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.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(), 0, diag.getChildren().size());
assertEquals("diag.isOk", diag.getSeverity(), Diagnostic.OK);
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testEnumWithEmptyLiteralGenerated.
@Test
public void testEnumWithEmptyLiteralGenerated() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/validation/literal/2'\n" + "Model: enumValue=GeneratedEnum;\n" + "enum GeneratedEnum: NoLiteral | ValidLiteral='literal' | EmptyLiteral='';");
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);
}
Aggregations