public List<Issue> createIssues(final IProgressMonitor monitor) { final List<Issue> issues = xtextDocument .readOnly(new IUnitOfWork<List<Issue>, XtextResource>() { public List<Issue> exec(XtextResource resource) throws Exception { if (resource == null || resource.isValidationDisabled()) return Collections.emptyList(); return resourceValidator.validate(resource, getCheckMode(), new CancelIndicator() { public boolean isCanceled() { return monitor.isCanceled(); } }); } }); return issues; }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * * @param work Work to execute on the State * * @return The result of executing {@code work}, or * null if the State is null * @since 2.15 */ default <Result> Result tryReadOnly(IUnitOfWork<Result, State> work) { return tryReadOnly(work, () -> null); }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * * @param work Work to execute on the State * @param defaultResult Supplies a result in case the State is null * * @return The result of executing {@code work}, or * the result of querying {@code defaultResult} if the State is null * @since 2.14 */ default <Result> Result tryReadOnly( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult ) { // Some implementations rely on the type of {@code work} if (work instanceof CancelableUnitOfWork<?, ?>) { return readOnly(new WrappingCancelableUnitOfWork<>(defaultResult, work)); } return readOnly((state) -> { if (state == null) { return defaultResult.get(); } return work.exec(state); }); }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * * @param work Work to execute on the State * @param defaultResult Supplies a result in case the State is null * @param exceptionHandler Supplies a result in case an exception is raised during execution * * @return The result of executing {@code work}, * the result of querying {@code defaultResult} if the State is null, or * the result of executing {@code exceptionHandler} in case an exception is raised * @since 2.14 */ default <Result> Result tryReadOnly( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult, Function<? super Exception, ? extends Result> exceptionHandler ) { try { return tryReadOnly(work, defaultResult); } catch (Exception e) { return exceptionHandler.apply(e); } }