use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-eclipse 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);
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-eclipse by eclipse.
the class ValidatorTester method diagnose.
public AssertableDiagnostics diagnose() {
if (!validatorCalled)
throw new IllegalStateException("You have to call validator() before you call diagnose()");
validatorCalled = false;
AssertableDiagnostics ad = new AssertableDiagnostics((Diagnostic) validator.setMessageAcceptor(validator).getState().chain);
validator.setMessageAcceptor(validator).getState().chain = new BasicDiagnostic();
return ad;
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project iobserve-analysis by research-iobserve.
the class cloudprofileEditor method analyzeResourceProblems.
/**
* Returns a diagnostic describing the errors and warnings listed in the resource
* and the specified exception (if any).
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) {
boolean hasErrors = !resource.getErrors().isEmpty();
if (hasErrors || !resource.getWarnings().isEmpty()) {
BasicDiagnostic basicDiagnostic = new BasicDiagnostic(hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "org.iobserve.planning.cloudprofile.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception == null ? (Object) resource : exception });
basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
return basicDiagnostic;
} else if (exception != null) {
return new BasicDiagnostic(Diagnostic.ERROR, "org.iobserve.planning.cloudprofile.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception });
} else {
return Diagnostic.OK_INSTANCE;
}
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project iobserve-analysis by research-iobserve.
the class systemadaptationEditor method analyzeResourceProblems.
/**
* Returns a diagnostic describing the errors and warnings listed in the resource
* and the specified exception (if any).
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) {
boolean hasErrors = !resource.getErrors().isEmpty();
if (hasErrors || !resource.getWarnings().isEmpty()) {
BasicDiagnostic basicDiagnostic = new BasicDiagnostic(hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "planning.systemadaptation.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception == null ? (Object) resource : exception });
basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
return basicDiagnostic;
} else if (exception != null) {
return new BasicDiagnostic(Diagnostic.ERROR, "planning.systemadaptation.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception });
} else {
return Diagnostic.OK_INSTANCE;
}
}
use of org.eclipse.emf.common.util.BasicDiagnostic in project n4js by eclipse.
the class AutomaticCancelationTest method testCancelIndicatorGetsInvokedAutomatically.
@Test
public void testCancelIndicatorGetsInvokedAutomatically() throws Exception {
String program = " class X { \n\t a: any; \n\t a: any; } } ";
Script s;
try {
s = ph.parse(program);
N4ClassDeclaration clazz = (N4ClassDeclaration) s.getScriptElements().get(0);
Map<Object, Object> context = new HashMap<>();
context.put(CancelableDiagnostician.CANCEL_INDICATOR, new TraceLeavingCancelIndicator());
// the cancel indicator in use sets a flag in case its isCanceled() was queried
assertTrue(!(wasChecked.get()));
DiagnosticChain chain = new BasicDiagnostic();
try {
v.validate(clazz, chain, context);
fail("expected OperationCanceledException or OperationCanceledError was not thrown");
} catch (Throwable th) {
assertTrue("wrong kind of throwable; expected: OperationCanceledException or OperationCanceledError, actual: " + th.getClass().getSimpleName(), operationCanceledManager.isOperationCanceledException(th));
}
assertTrue(wasChecked.get());
// now validate with a cancel indicator that never cancels,
// upon which validation methods run and errors are recorded.
context.put(CancelableDiagnostician.CANCEL_INDICATOR, CancelIndicator.NullImpl);
final boolean isValid02 = v.validate(clazz, chain, context);
assertTrue(!isValid02);
// validate again (this time with the default cancel indicator, which never cancels),
// check expected errors one by one.
String[] expectedErrorMsgs = { "The field a (line 2) duplicates field a (line 3).", "The field a (line 3) duplicates field a (line 2)." };
for (String expectedErrorMsg : expectedErrorMsgs) {
vth.assertError(s, N4JSPackage.Literals.N4_MEMBER_DECLARATION, IssueCodes.CLF_DUP_MEMBER, expectedErrorMsg);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Aggregations