use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.
the class OnChangeEvictingCacheAdapterTest method testCacheSurvivesChangeToDiagnostics.
@Test
public void testCacheSurvivesChangeToDiagnostics() throws Exception {
EcoreFactory factory = EcoreFactory.eINSTANCE;
EClass eClass = factory.createEClass();
Resource resource = new ResourceImpl();
resource.getContents().add(eClass);
CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
setValue(ca);
List<Diagnostic> errors = resource.getErrors();
assertIsSet(ca);
errors.clear();
assertIsSet(ca);
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.
the class ParseErrorHandlingTest method testTrailingRecoverableError.
@Test
public void testTrailingRecoverableError() throws Exception {
with(TreeTestLanguageStandaloneSetup.class);
String model = "parent ('Teststring') { \n" + " child ('Teststring'){};\n" + " child ('Teststring'){};\n" + "};\n" + "};\n" + "\n";
Resource res = getResourceFromStringAndExpect(model, 1);
assertEquals(res.getErrors().size(), 1, res.getErrors().size());
Diagnostic diag = res.getErrors().get(0);
assertNotNull(diag);
assertEquals(5, diag.getLine());
Model parsedModel = (Model) res.getContents().get(0);
assertNotNull(parsedModel);
ICompositeNode composite = NodeModelUtils.getNode(parsedModel);
assertNotNull(composite);
List<ILeafNode> leafs = Lists.newArrayList(composite.getLeafNodes());
ILeafNode lastWs = leafs.get(leafs.size() - 1);
assertTrue(lastWs.isHidden());
assertNull(lastWs.getSyntaxErrorMessage());
ILeafNode lastNode = leafs.get(leafs.size() - 2);
assertFalse(lastNode.isHidden());
assertNotNull(lastNode);
assertEquals("};", lastNode.getText());
assertNotNull(lastNode.getSyntaxErrorMessage());
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic 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.setLineNumberEnd(castedDiagnostic.getLineEnd());
issue.setColumnEnd(castedDiagnostic.getColumnEnd());
}
issue.setType(CheckType.FAST);
acceptor.accept(issue);
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.
the class ToEcoreTrafoTest method testAbstractLanguageToMetamodel.
@Test
public void testAbstractLanguageToMetamodel() throws Exception {
XtextResource r = getResource("classpath:/" + AbstractTestLanguage.class.getName().replace('.', '/') + ".xtext");
Grammar element = (Grammar) r.getParseResult().getRootASTElement();
if (!r.getErrors().isEmpty()) {
EList<Diagnostic> errors = r.getErrors();
for (Diagnostic syntaxError : errors) {
logger.debug(syntaxError.getMessage() + " - " + syntaxError.getLine());
}
fail(errors.toString());
}
List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element);
assertEquals(8, lexerRules.size());
List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element);
assertNotNull(list);
assertEquals(0, list.size());
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-eclipse by eclipse.
the class AbstractXtextTests method getResourceAndExpect.
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception {
XtextResource resource = doGetResource(in, uri);
checkNodeModel(resource);
if (expectedErrors != UNKNOWN_EXPECTATION) {
if (expectedErrors == EXPECT_ERRORS)
assertFalse(Joiner.on('\n').join(resource.getErrors()), resource.getErrors().isEmpty());
else
assertEquals(Joiner.on('\n').join(resource.getErrors()), expectedErrors, resource.getErrors().size());
}
for (Diagnostic d : resource.getErrors()) {
if (d instanceof ExceptionDiagnostic)
fail(d.getMessage());
}
if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) {
SerializerTester tester = get(SerializerTester.class);
EObject obj = resource.getContents().get(0);
tester.assertSerializeWithNodeModel(obj);
tester.assertSerializeWithoutNodeModel(obj);
}
return resource;
}
Aggregations