use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class UTF8ParserErrorTest method testInvalidReference_01.
@Test
public void testInvalidReference_01() throws Exception {
XtendFunction func = function("def m() { \\u0020invalidStart }");
XBlockExpression block = (XBlockExpression) func.getExpression();
XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
String featureName = featureCall.getConcreteSyntaxFeatureName();
assertEquals("\\u0020invalidStart", featureName);
assertTrue(featureCall.getFeature().eIsProxy());
List<Diagnostic> errorList = func.eResource().getErrors();
assertEquals(2, errorList.size());
XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errorList.get(1);
assertTrue(diagnostic.getMessage().contains("invalidStart"));
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class LinkingTest method testBug464264_01.
@Test
public void testBug464264_01() throws Exception {
XtendFile file = file("import java.util.List\n" + "class C {\n" + " def m(I i, List<CharSequence> list) {\n" + " i.strings += list.map[it]\n" + " }\n" + " interface I {\n" + " def List<String> getStrings()\n" + " }\n" + "}");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XBinaryOperation featureCall = (XBinaryOperation) body.getExpressions().get(0);
JvmIdentifiableElement feature = featureCall.getFeature();
assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.operator_add(java.util.Collection,java.lang.Iterable)", feature.getIdentifier());
assertNull(featureCall.getImplicitReceiver());
assertNull(featureCall.getImplicitFirstArgument());
List<Diagnostic> errors = c.eResource().getErrors();
assertEquals(1, errors.size());
assertEquals("Type mismatch: cannot convert from List<CharSequence> to Iterable<? extends String>", errors.get(0).getMessage());
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class PartialParserTest method validateWithoutException.
protected void validateWithoutException(XtextResource resource) {
ResourceValidatorImpl validator = resourceValidatorProvider.get();
assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
validator.setDiagnosticConverter(new IDiagnosticConverter() {
@Override
public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof BasicDiagnostic) {
List<?> data = diagnostic.getData();
if (!data.isEmpty() && data.get(0) instanceof Throwable) {
Throwable t = (Throwable) data.get(0);
// and AssertionError does not take a throwable as argument
throw new Error(t);
}
if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
throw new Error(new RuntimeException("Dangling reference found."));
}
}
}
@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof ExceptionDiagnostic) {
Exception e = ((ExceptionDiagnostic) diagnostic).getException();
// and AssertionError does not take a throwable as argument
throw new Error(new RuntimeException(e));
}
}
});
validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class LinkingErrorTest method assertNoExceptions.
protected void assertNoExceptions(EObject object) {
Resource resource = object.eResource();
if (resource instanceof LazyLinkingResource)
((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
List<Diagnostic> errors = object.eResource().getErrors();
for (Diagnostic error : errors) {
if (error instanceof ExceptionDiagnostic) {
((ExceptionDiagnostic) error).getException().printStackTrace();
}
assertFalse(error.toString(), error instanceof ExceptionDiagnostic);
}
validateWithoutException((XtextResource) resource);
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class NoJRESmokeTester method checkNoErrorsInValidator.
protected void checkNoErrorsInValidator(final String model, XtextResource resource) {
ResourceValidatorImpl validator = resourceValidatorProvider.get();
Assert.assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
validator.setDiagnosticConverter(new IDiagnosticConverter() {
@Override
public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof BasicDiagnostic) {
List<?> data = diagnostic.getData();
if (!data.isEmpty() && data.get(0) instanceof Throwable) {
Throwable t = (Throwable) data.get(0);
throwError(t);
}
if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
throwError(new RuntimeException("Dangling reference found."));
}
}
}
private void throwError(Throwable e) {
ComparisonFailure result = new ComparisonFailure(e.getMessage(), model, "");
result.setStackTrace(e.getStackTrace());
throw result;
}
@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof ExceptionDiagnostic) {
Exception e = ((ExceptionDiagnostic) diagnostic).getException();
throwError(e);
}
}
});
validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Aggregations