Search in sources :

Example 1 with XtextSyntaxDiagnostic

use of org.eclipse.xtext.resource.XtextSyntaxDiagnostic in project xtext-core by eclipse.

the class DiagnosticConverterImpl method convertResourceDiagnostic.

@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
    IssueImpl issue = new Issue.IssueImpl();
    issue.setSyntaxError(diagnostic instanceof XtextSyntaxDiagnostic);
    issue.setSeverity(severity);
    issue.setLineNumber(diagnostic.getLine());
    issue.setColumn(diagnostic.getColumn());
    issue.setMessage(diagnostic.getMessage());
    if (diagnostic instanceof org.eclipse.xtext.diagnostics.Diagnostic) {
        org.eclipse.xtext.diagnostics.Diagnostic xtextDiagnostic = (org.eclipse.xtext.diagnostics.Diagnostic) diagnostic;
        issue.setOffset(xtextDiagnostic.getOffset());
        issue.setLength(xtextDiagnostic.getLength());
    }
    if (diagnostic instanceof AbstractDiagnostic) {
        AbstractDiagnostic castedDiagnostic = (AbstractDiagnostic) diagnostic;
        issue.setUriToProblem(castedDiagnostic.getUriToProblem());
        issue.setCode(castedDiagnostic.getCode());
        issue.setData(castedDiagnostic.getData());
    }
    issue.setType(CheckType.FAST);
    acceptor.accept(issue);
}
Also used : XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) IssueImpl(org.eclipse.xtext.validation.Issue.IssueImpl) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic)

Example 2 with XtextSyntaxDiagnostic

use of org.eclipse.xtext.resource.XtextSyntaxDiagnostic in project xtext-core by eclipse.

the class ParserTest method testParseWithFractionErrorAndSyntaxError.

@SuppressWarnings("unchecked")
@Test
public void testParseWithFractionErrorAndSyntaxError() throws Exception {
    String model = "a.b.c.d: 1/0 ";
    Resource r = getResourceFromStringAndExpect(model, 2);
    EObject parsedModel = r.getContents().get(0);
    assertNotNull(parsedModel);
    EObject firstModel = ((List<EObject>) parsedModel.eGet(modelFeature)).get(0);
    assertFalse(firstModel.eIsSet(valueFeature));
    assertEquals(2, r.getErrors().size());
    XtextSyntaxDiagnostic diag = (XtextSyntaxDiagnostic) r.getErrors().get(0);
    assertEquals(model.indexOf("1/0"), diag.getOffset());
    assertEquals(3, diag.getLength());
    diag = (XtextSyntaxDiagnostic) r.getErrors().get(1);
    assertEquals(model.length() - 1, diag.getOffset());
    assertEquals(1, diag.getLength());
}
Also used : XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) List(java.util.List) Test(org.junit.Test)

Example 3 with XtextSyntaxDiagnostic

use of org.eclipse.xtext.resource.XtextSyntaxDiagnostic in project xtext-core by eclipse.

the class ParserTest method testParseWithFractionError.

@SuppressWarnings("unchecked")
@Test
public void testParseWithFractionError() throws Exception {
    String model = "a.b.c.d: 1/0;";
    Resource r = getResourceFromStringAndExpect(model, 1);
    EObject parsedModel = r.getContents().get(0);
    assertNotNull(parsedModel);
    EObject firstModel = ((List<EObject>) parsedModel.eGet(modelFeature)).get(0);
    assertFalse(firstModel.eIsSet(valueFeature));
    assertEquals(1, r.getErrors().size());
    XtextSyntaxDiagnostic diag = (XtextSyntaxDiagnostic) r.getErrors().get(0);
    assertEquals(model.indexOf("1/0"), diag.getOffset());
    assertEquals(3, diag.getLength());
}
Also used : XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) List(java.util.List) Test(org.junit.Test)

Example 4 with XtextSyntaxDiagnostic

use of org.eclipse.xtext.resource.XtextSyntaxDiagnostic in project xtext-core by eclipse.

the class ParserTest method testParseWithFractionErrorAndSpaces.

@SuppressWarnings("unchecked")
@Test
public void testParseWithFractionErrorAndSpaces() throws Exception {
    String model = "a.b.c.d:  1 / 0 ; ";
    Resource r = getResourceFromStringAndExpect(model, 1);
    EObject parsedModel = r.getContents().get(0);
    assertNotNull(parsedModel);
    EObject firstModel = ((List<EObject>) parsedModel.eGet(modelFeature)).get(0);
    assertFalse(firstModel.eIsSet(valueFeature));
    assertEquals(1, r.getErrors().size());
    XtextSyntaxDiagnostic diag = (XtextSyntaxDiagnostic) r.getErrors().get(0);
    assertEquals(model.indexOf("1 / 0"), diag.getOffset());
    assertEquals(5, diag.getLength());
}
Also used : XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) List(java.util.List) Test(org.junit.Test)

Example 5 with XtextSyntaxDiagnostic

use of org.eclipse.xtext.resource.XtextSyntaxDiagnostic in project xtext-core by eclipse.

the class Bug362902Test method testNoExceptionUncaught.

@Test
public void testNoExceptionUncaught() throws Exception {
    String modelAsString = "Hello max ! Hello peter! favourite peter";
    Model model = (Model) getModelAndExpect(modelAsString, 2);
    EList<Diagnostic> errors = model.eResource().getErrors();
    Diagnostic diagnosticSyntax = errors.get(0);
    Diagnostic diagnosticLinking = errors.get(1);
    assertTrue(diagnosticSyntax instanceof XtextSyntaxDiagnostic);
    assertTrue(diagnosticLinking instanceof XtextLinkingDiagnostic);
}
Also used : XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) Model(org.eclipse.xtext.linking.bug362902.Model) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Aggregations

XtextSyntaxDiagnostic (org.eclipse.xtext.resource.XtextSyntaxDiagnostic)5 Test (org.junit.Test)4 List (java.util.List)3 EObject (org.eclipse.emf.ecore.EObject)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)2 AbstractDiagnostic (org.eclipse.xtext.diagnostics.AbstractDiagnostic)1 Model (org.eclipse.xtext.linking.bug362902.Model)1 XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)1 IssueImpl (org.eclipse.xtext.validation.Issue.IssueImpl)1