Search in sources :

Example 1 with Diagnostic

use of org.eclipse.xtext.diagnostics.Diagnostic in project xtext-core by eclipse.

the class Bug437669Test method testUnresolved_01.

@Test
public void testUnresolved_01() {
    Type type = resolve("BlaBlaBla");
    Resource resource = type.eResource();
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    Diagnostic diagnostic = (Diagnostic) resource.getErrors().get(0);
    assertEquals(0, diagnostic.getOffset());
    assertEquals(1, diagnostic.getLength());
    assertEquals(1, diagnostic.getLine());
    assertEquals(1, diagnostic.getColumn());
    assertEquals("Couldn't resolve reference to Type 'BlaBlaBla'.", diagnostic.getMessage());
}
Also used : Type(org.eclipse.xtext.linking.importedURI.Type) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) Test(org.junit.Test)

Example 2 with Diagnostic

use of org.eclipse.xtext.diagnostics.Diagnostic in project xtext-core by eclipse.

the class Bug437669Test method testUnresolved_02.

@Test
public void testUnresolved_02() {
    Type type = getContext();
    INode nameNode = NodeModelUtils.findNodesForFeature(type, ImportedURIPackage.Literals.TYPE__NAME).get(0);
    resolve(type, "BlaBlaBla", nameNode.getOffset(), nameNode.getLength());
    Resource resource = type.eResource();
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    LineAndColumn lineAndColumn = NodeModelUtils.getLineAndColumn(nameNode, nameNode.getOffset());
    Diagnostic diagnostic = (Diagnostic) resource.getErrors().get(0);
    assertEquals(nameNode.getOffset(), diagnostic.getOffset());
    assertEquals(nameNode.getLength(), diagnostic.getLength());
    assertEquals(lineAndColumn.getLine(), diagnostic.getLine());
    assertEquals(lineAndColumn.getColumn(), diagnostic.getColumn());
    assertEquals("Couldn't resolve reference to Type 'BlaBlaBla'.", diagnostic.getMessage());
}
Also used : Type(org.eclipse.xtext.linking.importedURI.Type) INode(org.eclipse.xtext.nodemodel.INode) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) LineAndColumn(org.eclipse.xtext.util.LineAndColumn) Test(org.junit.Test)

Example 3 with Diagnostic

use of org.eclipse.xtext.diagnostics.Diagnostic in project xtext-core by eclipse.

the class LinkingErrorTest method testLinkError.

@Test
public void testLinkError() throws Exception {
    XtextResource resource = getResourceFromStringAndExpect(" type A extends B \n type B extends C", 1);
    Main model = (Main) getModel(resource);
    assertEquals(2, model.getTypes().size());
    assertEquals(1, resource.getErrors().size());
    assertEquals(0, resource.getWarnings().size());
    Diagnostic error = (Diagnostic) resource.getErrors().get(0);
    assertEquals(2, error.getLine());
    Diagnostic verboseError = error;
    assertEquals(35, verboseError.getOffset());
    assertEquals(1, verboseError.getLength());
}
Also used : Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Example 4 with Diagnostic

use of org.eclipse.xtext.diagnostics.Diagnostic in project xtext-core by eclipse.

the class LinkingErrorTest method testLinkingErrorMessage.

@Test
public void testLinkingErrorMessage() throws Exception {
    XtextResource resource = getResourceFromStringAndExpect("type A extends B", 1);
    assertEquals(1, resource.getErrors().size());
    Diagnostic error = (Diagnostic) resource.getErrors().get(0);
    assertEquals(1, error.getLine());
    assertEquals("Couldn't resolve reference to Type 'B'.", error.getMessage());
}
Also used : Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 5 with Diagnostic

use of org.eclipse.xtext.diagnostics.Diagnostic in project xtext-core by eclipse.

the class LinkingWarningsTest method testLinkingProblemAsWarning.

@Test
public void testLinkingProblemAsWarning() throws Exception {
    String modelAsText = "type A extends B \n type B extends C";
    XtextResource resource = getResourceFromStringAndExpect(modelAsText, 0);
    assertTrue(resource.getErrors().isEmpty());
    assertEquals(1, resource.getWarnings().size());
    Diagnostic warning = (Diagnostic) resource.getWarnings().get(0);
    assertEquals(2, warning.getLine());
    assertEquals(expected, warning.getMessage());
}
Also used : Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

Diagnostic (org.eclipse.xtext.diagnostics.Diagnostic)5 Test (org.junit.Test)5 XtextResource (org.eclipse.xtext.resource.XtextResource)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 Type (org.eclipse.xtext.linking.importedURI.Type)2 Main (org.eclipse.xtext.linking.langATestLanguage.Main)1 INode (org.eclipse.xtext.nodemodel.INode)1 LineAndColumn (org.eclipse.xtext.util.LineAndColumn)1