org.eclipse.xtext.validation.CancelableDiagnostician Java Examples
The following examples show how to use
org.eclipse.xtext.validation.CancelableDiagnostician.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SemverResourceValidator.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** 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); } }
Example #2
Source File: AutomaticCancelationTest.java From n4js with Eclipse Public License 1.0 | 4 votes |
@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; } }
Example #3
Source File: N4JSFlowgraphValidator.java From n4js with Eclipse Public License 1.0 | 4 votes |
private Void checkCancelled() { CancelIndicator cancelIndicator = (CancelIndicator) getContext().get(CancelableDiagnostician.CANCEL_INDICATOR); operationCanceledManager.checkCanceled(cancelIndicator); return null; }
Example #4
Source File: DefaultXbaseRuntimeModule.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@SuppressWarnings("deprecation") public Class<? extends CancelableDiagnostician> bindCancelableDiagnostician() { return org.eclipse.xtext.xbase.validation.XbaseDiagnostician.class; }
Example #5
Source File: DefaultRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@SingletonBinding public Class<? extends Diagnostician> bindDiagnostician() { return CancelableDiagnostician.class; }