@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; } }
public Class<? extends CancelableDiagnostician> bindCancelableDiagnostician() { return XbaseDiagnostician.class; }
@SingletonBinding public Class<? extends Diagnostician> bindDiagnostician() { return CancelableDiagnostician.class; }