Java源码示例:org.eclipse.xtext.validation.CancelableDiagnostician

示例1
/** Copied from parent class to change language to {@code SemverGlobals.LANGUAGE_NAME} */
@Override
protected void validate(Resource resource, EObject eObject, CheckMode mode, CancelIndicator monitor,
		IAcceptor<Issue> acceptor) {
	try {
		Map<Object, Object> options = Maps.newHashMap();
		options.put(CheckMode.KEY, mode);
		options.put(CancelableDiagnostician.CANCEL_INDICATOR, monitor);
		// disable concrete syntax validation, since a semantic model that has been parsed
		// from the concrete syntax always complies with it - otherwise there are parse errors.
		options.put(ConcreteSyntaxEValidator.DISABLE_CONCRETE_SYNTAX_EVALIDATOR, Boolean.TRUE);
		// see EObjectValidator.getRootEValidator(Map<Object, Object>)
		options.put(EValidator.class, diagnostician);
		options.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, SemverGlobals.LANGUAGE_NAME);

		Diagnostic diagnostic = diagnostician.validate(eObject, options);
		if (!diagnostic.getChildren().isEmpty()) {
			for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
				issueFromEValidatorDiagnostic(childDiagnostic, acceptor);
			}
		} else {
			issueFromEValidatorDiagnostic(diagnostic, acceptor);
		}
	} catch (RuntimeException e) {
		operationCanceledManager.propagateAsErrorIfCancelException(e);
	}
}
 
示例2
@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;
	}
}
 
示例3
private Void checkCancelled() {
	CancelIndicator cancelIndicator = (CancelIndicator) getContext().get(CancelableDiagnostician.CANCEL_INDICATOR);
	operationCanceledManager.checkCanceled(cancelIndicator);
	return null;
}
 
示例4
@SuppressWarnings("deprecation")
public Class<? extends CancelableDiagnostician> bindCancelableDiagnostician() {
	return org.eclipse.xtext.xbase.validation.XbaseDiagnostician.class;
}
 
示例5
@SingletonBinding
public Class<? extends Diagnostician> bindDiagnostician() {
	return CancelableDiagnostician.class;
}