use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testBug322875_03.
@Test
public void testBug322875_03() throws Exception {
String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " + " import 'http://www.eclipse.org/emf/2002/Ecore' " + "Model returns EClass: name=ID;";
XtextResource resource = getResourceFromString(testGrammar);
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
assertNotNull("diag", diag);
assertEquals(diag.toString(), 0, diag.getChildren().size());
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testBug_293110.
@Test
public void testBug_293110() throws Exception {
XtextResource resource = doGetResource(new org.eclipse.xtext.util.StringInputStream("A: value=B; B: name=ID;"), URI.createURI("testBug_293110"));
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
Collection<Diagnostic> runtimeExceptions = Collections2.filter(diagnostic.getChildren(), new Predicate<Diagnostic>() {
@Override
public boolean apply(Diagnostic input) {
return input.getException() instanceof RuntimeException;
}
});
assertTrue(runtimeExceptions.isEmpty());
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class Serializer method serialize.
public TreeConstructionReport serialize(EObject obj, ITokenStream tokenStream, SaveOptions options) throws IOException {
if (options.isValidating()) {
List<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
validator.validateRecursive(obj, new IConcreteSyntaxValidator.DiagnosticListAcceptor(diagnostics), new HashMap<Object, Object>());
if (!diagnostics.isEmpty())
throw new IConcreteSyntaxValidator.InvalidConcreteSyntaxException("These errors need to be fixed before the model can be serialized.", diagnostics);
}
ITokenStream formatterTokenStream;
if (formatter instanceof IFormatterExtension)
formatterTokenStream = ((IFormatterExtension) formatter).createFormatterStream(obj, null, tokenStream, !options.isFormatting());
else
formatterTokenStream = formatter.createFormatterStream(null, tokenStream, !options.isFormatting());
TreeConstructionReport report = parseTreeReconstructor.serializeSubtree(obj, formatterTokenStream);
formatterTokenStream.flush();
return report;
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testLeftRecursion_Bug_285605_03.
@Test
public void testLeftRecursion_Bug_285605_03() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate foo 'http://foo/bar'\n" + "RuleA : ruleC=RuleC;\n" + "Unused : something=Unused;\n" + "RuleC : ruleA=RuleA;\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(), 3, 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 testLeftRecursion_Bug_285605_06.
@Test
public void testLeftRecursion_Bug_285605_06() 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);
}
Aggregations