use of org.eclipse.xtext.diagnostics.ExceptionDiagnostic in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method testNoException_01.
@Test
public void testNoException_01() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore generate test \'http://test\'");
_builder.newLine();
_builder.append("CompositeModel: (model+=Model)+;");
_builder.newLine();
_builder.append("Model: id=NestedModelId (\':\' value=Fraction)? (\'#\' vector=Vector)? (\'+\' dots=Dots)? \';\'");
_builder.newLine();
_builder.append("ModelId returns ecore::EString: ID \'.\' ID;");
_builder.newLine();
_builder.append("NestedModelId : ModelId \'.\' ModelId;");
_builder.newLine();
_builder.append("Fraction returns EBigDecimal: INT (\'/\' INT)?;");
_builder.newLine();
_builder.append("Vector : \'(\' INT I");
String grammar = _builder.toString();
final XtextResource resource = this.getResourceFromStringAndExpect(grammar, 10);
EList<Resource.Diagnostic> _errors = resource.getErrors();
for (final Resource.Diagnostic d : _errors) {
Assert.assertFalse((d instanceof ExceptionDiagnostic));
}
}
use of org.eclipse.xtext.diagnostics.ExceptionDiagnostic 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.xtext.diagnostics.ExceptionDiagnostic 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.xtext.diagnostics.ExceptionDiagnostic in project xtext-core by eclipse.
the class DerivedStateAwareResourceTest method testOperationCanceledExceptionOnInstallAndDiscard.
@Test
public void testOperationCanceledExceptionOnInstallAndDiscard() {
TestedResource resource = new TestedResource();
resource.setIsLoaded();
resource.setDerivedStateComputer(new IDerivedStateComputer() {
@Override
public void installDerivedState(DerivedStateAwareResource resource, boolean resolve) {
resource.getContents().add(EcoreFactory.eINSTANCE.createEObject());
throw new OperationCanceledException();
}
@Override
public void discardDerivedState(DerivedStateAwareResource resource) {
throw new OperationCanceledException();
}
});
assertFalse(resource.isFullyInitialized());
try {
resource.getContents();
fail("exception expected");
} catch (IllegalStateException e) {
// expected
}
assertTrue(resource.isFullyInitialized());
assertFalse(resource.getContents().isEmpty());
assertEquals(1, resource.getErrors().size());
assertTrue(((ExceptionDiagnostic) resource.getErrors().get(0)).getException() instanceof IllegalStateException);
}
use of org.eclipse.xtext.diagnostics.ExceptionDiagnostic in project xtext-core 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)) {
SerializerTestHelper tester = get(SerializerTestHelper.class);
EObject obj = resource.getContents().get(0);
tester.assertSerializeWithNodeModel(obj);
tester.assertSerializeWithoutNodeModel(obj);
}
return resource;
}
Aggregations