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