private void addMarkers(IFile file, Resource resource, CheckMode mode, IProgressMonitor monitor) throws OperationCanceledException { try { List<Issue> list = getValidator(resource).validate(resource, mode, getCancelIndicator(monitor)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } deleteMarkers(file, mode, monitor); if (monitor.isCanceled()) { throw new OperationCanceledException(); } createMarkers(file, list, getMarkerCreator(resource), getMarkerTypeProvider(resource)); } catch (OperationCanceledError error) { throw error.getWrapped(); } catch (CoreException e) { LOGGER.error(e.getMessage(), e); } }
@Test public void testCancelTypeResolution() { try { final XExpression exp = this.expression("true"); try { final CancelIndicator _function = () -> { return true; }; this.resolver.resolveTypes(exp, _function); Assert.fail("Type resolution should have been canceled"); } catch (final Throwable _t) { if (_t instanceof OperationCanceledError) { } else { throw Exceptions.sneakyThrow(_t); } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testRunTypeResolution() { try { final XExpression exp = this.expression("true"); try { final CancelIndicator _function = () -> { return false; }; this.resolver.resolveTypes(exp, _function); } catch (final Throwable _t) { if (_t instanceof OperationCanceledError) { Assert.fail("Type resolution should not have been canceled"); } else { throw Exceptions.sneakyThrow(_t); } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Override public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) throws OperationCanceledError { boolean result = true; for (int i = 0; i < getContents().size(); i++) { EValidatorEqualitySupport val = getContents().get(i); try { result &= val.getDelegate().validate(eObject, diagnostics, context); } catch (Throwable e) { operationCanceledManager.propagateAsErrorIfCancelException(e); logger.error("Error executing EValidator", e); diagnostics.add(createExceptionDiagnostic("Error executing EValidator", eObject, e)); } } return result; }
@Override public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) throws OperationCanceledError { boolean result = true; for (int i = 0; i < getContents().size(); i++) { EValidatorEqualitySupport val = getContents().get(i); try { result &= val.getDelegate().validate(eClass, eObject, diagnostics, context); } catch (Throwable e) { operationCanceledManager.propagateAsErrorIfCancelException(e); logger.error("Error executing EValidator", e); diagnostics.add(createExceptionDiagnostic("Error executing EValidator", eClass, e)); } } return result; }
@Override public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) throws OperationCanceledError { boolean result = true; for (int i = 0; i < getContents().size(); i++) { EValidatorEqualitySupport val = getContents().get(i); try { result &= val.getDelegate().validate(eDataType, value, diagnostics, context); } catch (Throwable e) { operationCanceledManager.propagateAsErrorIfCancelException(e); logger.error("Error executing EValidator", e); diagnostics.add(createExceptionDiagnostic("Error executing EValidator", eDataType, e)); } } return result; }
@Test public void testCreatedErrors_06() { maxCallCount = 1; ImmutableList<ENamedElement> elements = ImmutableList.of( createEPackage(), createEDataType(), createEPackage() ); for(ENamedElement classifier: elements) { classifier.setName("Same"); } try { helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); fail("cancellation expected"); } catch (OperationCanceledError e) { } assertEquals(1, callCount); }
private boolean tryDocumentSave(CooperateXtextDocument cooperateXtextDocument) throws OperationCanceledError { List<Issue> detectedIssues = getAllIssues(cooperateXtextDocument); if (!detectedIssues.isEmpty()) { openErrorDialog("Save Error", "Can't save because of semantic errors.", detectedIssues); return false; } Job job = getDiagramSaveJob(); job.setUser(true); job.schedule(); try { job.join(); } catch (InterruptedException e) { LOGGER.error("Error during save operation.", e); return false; } return true; }
private void performIssueValidationFixingTransactional(Collection<TransactionalEditingDomain> domains, Resource documentResource) throws OperationCanceledError { final Collection<Issue> detectedIssues = new ArrayList<>(); domains.stream().filter(TransactionalEditingDomainImpl.class::isInstance) .map(TransactionalEditingDomainImpl.class::cast).forEach(d -> setValidatorFactory(d, detectedIssues)); Runnable lastCommandStackAction = null; for (TransactionalEditingDomain domain : domains) { if (lastCommandStackAction == null) { lastCommandStackAction = createFixingRecordingCommand(domain, documentResource, detectedIssues); } else { lastCommandStackAction = createDelegatingRecordingCommand(domain, lastCommandStackAction); } } Optional.ofNullable(lastCommandStackAction).ifPresent(Runnable::run); }
/** * Why does this method resort to returning via exceptional-control-flow upon detecting a cancellation request? * Didn't the validation method already handle it? * <p> * Upon cancellation, some validators (for example, {@code ManifestAwareResourceValidator}) may decide to stop all * work and return only the issues found thus far (or even an empty list of issues). That's a valid realization of * the cancellation contract. Thus the {@code validate()} method returned normally. If we were to return those * partial results, the caller of this method would proceed to pollute the cache with them. That's prevented by * throwing a fabricated {@link OperationCanceledError} */ @Override public List<Issue> get() throws OperationCanceledError { operationCanceledManager.checkCanceled(ci); List<Issue> issues = rv.validate(r, CheckMode.ALL, ci); if (!issues.contains(null)) { operationCanceledManager.checkCanceled(ci); return issues; } ArrayList<Issue> result = new ArrayList<>(issues); result.removeAll(Collections.singleton(null)); operationCanceledManager.checkCanceled(ci); return result; }
@Override public List<Issue> validate(Resource resource, final CheckMode mode, CancelIndicator mon) throws OperationCanceledError { StoppedTask task = Stopwatches.forTask("ResourceValidatorImpl.validation"); try { task.start(); final CancelIndicator monitor = mon == null ? CancelIndicator.NullImpl : mon; resolveProxies(resource, monitor); operationCanceledManager.checkCanceled(monitor); final List<Issue> result = Lists.newArrayListWithExpectedSize(resource.getErrors().size() + resource.getWarnings().size()); try { IAcceptor<Issue> acceptor = createAcceptor(result); if (mode.shouldCheck(CheckType.FAST)) { collectResourceDiagnostics(resource, monitor, acceptor); } operationCanceledManager.checkCanceled(monitor); boolean syntaxDiagFail = !result.isEmpty(); logCheckStatus(resource, syntaxDiagFail, "Syntax"); validate(resource, mode, monitor, acceptor); operationCanceledManager.checkCanceled(monitor); } catch (RuntimeException e) { operationCanceledManager.propagateAsErrorIfCancelException(e); log.error(e.getMessage(), e); } return result; } finally { task.stop(); } }
protected RuntimeException getPlatformOperationCanceledException(final Throwable t) { RuntimeException _switchResult = null; boolean _matched = false; if (t instanceof OperationCanceledException) { _matched=true; _switchResult = ((RuntimeException)t); } if (!_matched) { if (t instanceof RuntimeException) { String _name = ((RuntimeException)t).getClass().getName(); boolean _equals = Objects.equal(_name, "com.intellij.openapi.progress.ProcessCanceledException"); if (_equals) { _matched=true; _switchResult = ((RuntimeException)t); } } } if (!_matched) { if (t instanceof OperationCanceledError) { _matched=true; _switchResult = ((OperationCanceledError)t).getWrapped(); } } if (!_matched) { _switchResult = null; } return _switchResult; }
/** * Rethrows OperationCanceledErrors and wraps platform specific OperationCanceledExceptions. Does nothing for any other type of Throwable. */ public void propagateAsErrorIfCancelException(final Throwable t) { if ((t instanceof OperationCanceledError)) { throw ((OperationCanceledError)t); } final RuntimeException opCanceledException = this.getPlatformOperationCanceledException(t); if ((opCanceledException != null)) { throw new OperationCanceledError(opCanceledException); } }
protected Error asWrappingOperationCanceledException(final Throwable throwable) { if ((throwable instanceof OperationCanceledError)) { return ((Error)throwable); } final RuntimeException platform = this.getPlatformOperationCanceledException(throwable); if ((platform != null)) { return new OperationCanceledError(platform); } return null; }
@Test public void testCancel_01() { maxCallCount = 1; try { helper.checkUniqueNames( Scopes.scopedElementsFor(ImmutableList.of( createEClass(), createEClass() )), this, this); fail("should be canceled"); } catch (OperationCanceledError e) { } assertEquals(maxCallCount, callCount); }
@Override public List<Issue> validate(Resource resource, CheckMode mode, CancelIndicator mon) throws OperationCanceledError { List<Issue> issues = super.validate(resource, mode, mon); Map<IssueCoordinate, List<Issue>> issueCluster = issues.stream() .collect(Collectors.groupingBy(IssueCoordinate::create)); Set<Issue> customIssues = issues.stream().filter(issue -> issueCodeRegistry.hasIssueCode(issue.getCode())) .collect(Collectors.toSet()); return issueCluster.entrySet().stream() .flatMap(g -> filterIssueGroup(g.getKey(), g.getValue(), customIssues).stream()) .collect(Collectors.toList()); }
protected void processModelImports(Ontology modelOntology, URI importingResourceUri, SadlModel model) throws OperationCanceledError { EList<SadlImport> implist = model.getImports(); Iterator<SadlImport> impitr = implist.iterator(); while (impitr.hasNext()) { SadlImport simport = impitr.next(); SadlModel importedResource = simport.getImportedResource(); if (importedResource != null) { // URI importingResourceUri = resource.getURI(); String importUri = importedResource.getBaseUri(); String importPrefix = simport.getAlias(); Resource eResource = importedResource.eResource(); if (eResource instanceof XtextResource) { XtextResource xtrsrc = (XtextResource) eResource; URI importedResourceUri = xtrsrc.getURI(); OntModel importedOntModel = OntModelProvider.find(xtrsrc); if (importedOntModel == null) { logger.debug("JenaBasedSadlModelProcessor failed to resolve null OntModel for Resource '" + importedResourceUri + "' while processing Resource '" + importingResourceUri + "'"); } else { addImportToJenaModel(modelName, importUri, importPrefix, importedOntModel); } } else if (eResource instanceof ExternalEmfResource) { ExternalEmfResource emfResource = (ExternalEmfResource) eResource; addImportToJenaModel(modelName, importUri, importPrefix, emfResource.getOntModel()); } } } }
private List<Issue> getAllIssues(CooperateXtextDocument document) throws OperationCanceledError { return resourceValidator.validate(document.getResource(), CheckMode.ALL, CancelIndicator.NullImpl); }
/** * Validates the given resource according to the {@link CheckMode mode}. An optional {@link CancelIndicator} * may be provide to allow the method to exit early in case the long running validation was canceled by the * user. * * @return all issues of the underlying resources (includes syntax errors as well as semantic problems) * @throws OperationCanceledError if the validation was cancelled, the method may exit with an {@link OperationCanceledError} */ List<Issue> validate(Resource resource, CheckMode mode, CancelIndicator indicator) throws OperationCanceledError;
IResolvedTypes reentrantResolve(CancelIndicator monitor) throws OperationCanceledError;