use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class SmokeTest method checkNoErrorsInValidator.
protected void checkNoErrorsInValidator(final String model, LazyLinkingResource 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);
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);
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class LinkingTest method testStaticImports_01.
@Test
public void testStaticImports_01() throws Exception {
String fileAsText = "import java.util.Collections.* class Clazz { def void method() { ''.singletonList() } }";
XtendFile file = file(fileAsText, false);
EcoreUtil.resolveAll(file);
List<Diagnostic> errors = file.eResource().getErrors();
assertEquals(1, errors.size());
assertTrue(errors.get(0) instanceof XtextLinkingDiagnostic);
XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errors.get(0);
assertEquals(fileAsText.indexOf("singletonList"), diagnostic.getOffset());
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class LinkingTest method testStaticImports_02.
@Test
public void testStaticImports_02() throws Exception {
String fileAsText = "import static java.util.Collections.* class Clazz { def void method() { ''.singletonList() } }";
XtendFile file = file(fileAsText, false);
EcoreUtil.resolveAll(file);
List<Diagnostic> errors = file.eResource().getErrors();
assertEquals(1, errors.size());
assertTrue(errors.get(0) instanceof XtextLinkingDiagnostic);
XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errors.get(0);
assertEquals(fileAsText.indexOf("singletonList"), diagnostic.getOffset());
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.
the class LinkingErrorTest 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);
}
}
}
@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 UTF8ParserErrorTest method testInvalidReference_02.
@Test
public void testInvalidReference_02() throws Exception {
XtendFunction func = function("def m() { invalid\\u0020Part }");
XBlockExpression block = (XBlockExpression) func.getExpression();
XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
String featureName = featureCall.getConcreteSyntaxFeatureName();
assertEquals("invalid\\u0020Part", 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("invalidPart"));
}
Aggregations