Search in sources :

Example 26 with Diagnostic

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());
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 27 with Diagnostic

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());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 28 with Diagnostic

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;
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.emf.common.util.Diagnostic) IFormatterExtension(org.eclipse.xtext.formatting.IFormatterExtension) EObject(org.eclipse.emf.ecore.EObject) TreeConstructionReport(org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor.TreeConstructionReport) IConcreteSyntaxValidator(org.eclipse.xtext.validation.IConcreteSyntaxValidator)

Example 29 with Diagnostic

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);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 30 with Diagnostic

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);
}
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