Search in sources :

Example 6 with Diagnostic

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

the class DeclarativeValidatorTest method testWarning.

@Test
public void testWarning() {
    AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {

        @Check
        public void foo(Object x) {
            warning("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME);
        }
    };
    BasicDiagnostic chain = new BasicDiagnostic();
    test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
    assertEquals(1, chain.getChildren().size());
    Diagnostic diag = chain.getChildren().get(0);
    assertEquals("Error Message", diag.getMessage());
    assertEquals(EcorePackage.eINSTANCE.getEClass().toString(), diag.getSource());
    assertEquals(Diagnostic.WARNING, diag.getSeverity());
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 7 with Diagnostic

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

the class ImportUriValidatorTest method testInvalidURI.

@Test
public void testInvalidURI() throws Exception {
    String model = "import 'classpath:/org/eclipse/xtext/linking/ImportUriTestLanguage.unknown'";
    Resource resource = getResourceFromString(model);
    Diagnostic diagnostics = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertEquals(Diagnostic.ERROR, diagnostics.getSeverity());
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Test(org.junit.Test)

Example 8 with Diagnostic

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

the class ImportUriValidatorTest method testValidURI.

@Test
public void testValidURI() throws Exception {
    String model = "import 'classpath:/org/eclipse/xtext/linking/ImportUriTestLanguage.xtext'";
    Resource resource = getResourceFromString(model);
    Diagnostic diagnostics = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertEquals(Diagnostic.OK, diagnostics.getSeverity());
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Test(org.junit.Test)

Example 9 with Diagnostic

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

the class Bug456789Test method doesNotHang_01.

@Test(timeout = 5000)
public void doesNotHang_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("grammar com.acme.G with org.eclipse.xtext.common.Terminals");
        _builder.newLine();
        _builder.newLine();
        _builder.append("generate g \"bug456789\"");
        _builder.newLine();
        _builder.newLine();
        _builder.append("CompoundStatement: Declaration;");
        _builder.newLine();
        _builder.append("suite: simpleStatement | NL INDENT stmt+ DEDENT;");
        _builder.newLine();
        _builder.newLine();
        _builder.append("test: or_test (\'if\' or_test \'else\' test)? | lambdef;");
        _builder.newLine();
        _builder.append("or_test: and_test (\'or\' and_test)*;");
        _builder.newLine();
        _builder.append("and_test: not_test (\'and\' not_test)*;");
        _builder.newLine();
        _builder.append("not_test: \'not\' not_test | comparison;");
        _builder.newLine();
        _builder.append("comparison: expr (comp_op expr)*;");
        _builder.newLine();
        _builder.append("comp_op: \'<\'|\'>\'|\'==\'|\'>=\'|\'<=\'|\'<>\'|\'!=\'|\'in\'|\'not\' \'in\'|\'is\'|\'is\' \'not\';");
        _builder.newLine();
        _builder.append("expr: xorExpression (\'|\' xorExpression)*;");
        _builder.newLine();
        _builder.append("xorExpression: andExpression (\'^\' andExpression)*;");
        _builder.newLine();
        _builder.append("andExpression: shiftExpression (\'&\' shiftExpression)*;");
        _builder.newLine();
        _builder.append("shiftExpression: arithExpression ((\'<<\'|\'>>\') arithExpression)*;");
        _builder.newLine();
        _builder.append("arithExpression: term ((\'+\'|\'-\') term)*;");
        _builder.newLine();
        _builder.append("term: factor ((\'*\'|\'/\'|\'%\'|\'//\') factor)*;");
        _builder.newLine();
        _builder.append("factor: (\'+\'|\'-\'|\'~\') factor | power;");
        _builder.newLine();
        _builder.append("power: atom trailer* (\'**\' factor)?;");
        _builder.newLine();
        _builder.append("atom: (\'(\' (yieldExpression|testlist_comp)? \')\' |");
        _builder.newLine();
        _builder.append("       ");
        _builder.append("\'(\' (listmaker)? \')?\' |");
        _builder.newLine();
        _builder.append("       ");
        _builder.append("\'{\' (dictorsetmaker)? \'}\' |");
        _builder.newLine();
        _builder.append("       ");
        _builder.append("\'`\' testlist1 \'`\' |");
        _builder.newLine();
        _builder.append("       ");
        _builder.append("ID | NUMBER | STRING+);");
        _builder.newLine();
        _builder.append("listmaker: test ( list_for | (\',\' test)* (\',\')? );");
        _builder.newLine();
        _builder.append("testlist_comp: test ( comp_for | (\',\' test)* (\',\')? );");
        _builder.newLine();
        _builder.append("lambdef: \'lambda\' (varargslist)? \':\' test;");
        _builder.newLine();
        _builder.append("trailer: \'(\' (arglist)? \')\' | \'(\' subscriptlist \')?\' | \'.\' ID;");
        _builder.newLine();
        _builder.append("subscriptlist: subscript (\',\' subscript)* (\',\')?;");
        _builder.newLine();
        _builder.append("subscript: \'.\' \'.\' \'.\' | test | (test)? \':\' (test)? (sliceop)?;");
        _builder.newLine();
        _builder.append("sliceop: \':\' (test)?;");
        _builder.newLine();
        _builder.append("exprlist: expr (\',\' expr)* (\',\')?;");
        _builder.newLine();
        _builder.append("testlist: test (\',\' test)* (\',\')?;");
        _builder.newLine();
        _builder.append("dictorsetmaker: ( (test \':\' test (comp_for | (\',\' test \':\' test)* (\',\')?)) |");
        _builder.newLine();
        _builder.append("                  ");
        _builder.append("(test (comp_for | (\',\' test)* (\',\')?)) );");
        _builder.newLine();
        final XtextResource resource = this.getResourceFromStringAndExpect(_builder.toString(), AbstractXtextTests.UNKNOWN_EXPECTATION);
        final Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
        Assert.assertNotNull("diag", diag);
        Assert.assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 10 with Diagnostic

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

the class XtextValidationTest method testBug_283534_03.

@Test
public void testBug_283534_03() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "terminal TERMINAL: ID;\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)

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