org.eclipse.xtext.service.OperationCanceledError Java Examples

The following examples show how to use org.eclipse.xtext.service.OperationCanceledError. 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: FutureUtil.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Obtains the given future's result via {@link Future#get()}, but converts <code>java.util.concurrent</code>'s
 * {@link CancellationException} to Xtext's {@link OperationCanceledException} and wraps checked exceptions in a
 * {@link RuntimeException}.
 */
public static <T> T getCancellableResult(Future<T> future) {
	try {
		return future.get();
	} catch (Throwable e) {
		Throwable cancellation = getCancellation(e);
		if (cancellation instanceof OperationCanceledError) {
			throw (OperationCanceledError) cancellation;
		} else if (cancellation instanceof OperationCanceledException) {
			throw (OperationCanceledException) cancellation;
		} else if (cancellation instanceof CancellationException) {
			String msg = e.getMessage();
			if (msg != null) {
				throw new OperationCanceledException(e.getMessage());
			}
			throw new OperationCanceledException();
		}
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example #2
Source File: ComparisonExpressionValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public IStatus validateXtextResource(final Injector injector, Resource resource, ResourceSet resourceSet) throws OperationCanceledError {
      final IResourceValidator xtextResourceChecker = injector.getInstance(IResourceValidator.class);
final MultiStatus status = new MultiStatus(ExpressionEditorPlugin.PLUGIN_ID, 0, "", null);
      final ConditionModelJavaValidator validator = injector.getInstance(ConditionModelJavaValidator.class);
      validator.setCurrentResourceSet(resourceSet);
final List<Issue> issues = xtextResourceChecker.validate(resource, CheckMode.FAST_ONLY, null);
if(issues.isEmpty()){
	updateDependencies(resource);
}
for(final Issue issue : issues){
	int severity = IStatus.ERROR;
	final Severity issueSeverity = issue.getSeverity();
	if(issueSeverity == Severity.WARNING){
		severity = IStatus.WARNING;
	}
	status.add(new Status(severity, ExpressionEditorPlugin.PLUGIN_ID, issue.getMessage()));
}

return status;
  }
 
Example #3
Source File: NamesAreUniqueValidationHelperTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCreatedErrors_06_context() {
	maxCallCount = 1;
	ImmutableList<ENamedElement> elements = ImmutableList.of(
			createEPackage(),
			createEDataType(),
			createEPackage()
			);
	for(ENamedElement classifier: elements) {
		classifier.setName("Same");
	}
	try {
		helper.checkUniqueNames(
				new LocalUniqueNameContext(elements, this), this);
		fail("cancellation expected");
	} catch (OperationCanceledError e) {
	}
	assertEquals(1, callCount);
}
 
Example #4
Source File: NamesAreUniqueValidationHelperTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@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);
}
 
Example #5
Source File: CompositeEValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: CompositeEValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: CompositeEValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: DefaultResourceUIValidatorExtension.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void addMarkers(IFile file, Resource resource, CheckMode mode, IProgressMonitor monitor) throws OperationCanceledException {
	try {
		List<Issue> list = resourceValidator.validate(resource, mode, getCancelIndicator(monitor));
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		deleteMarkers(file, mode, monitor);
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		createMarkers(file, list, monitor);
	} catch (OperationCanceledError error) {
		throw error.getWrapped();
	} catch (CoreException e) {
		log.error(e.getMessage(), e);
	}
}
 
Example #9
Source File: ResourceUIValidatorExtension.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
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, resource, list);
	} catch (OperationCanceledError error) {
		throw error.getWrapped();
	} catch (CoreException e) {
		LOGGER.error(e.getMessage(), e);
	}
}
 
Example #10
Source File: XtextDocument.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void notifyModelListeners(final XtextResource res) {
	if (res == null || res != this.resource)
		return;
	List<IXtextModelListener> modelListenersCopy;
	synchronized (modelListeners) {
		modelListenersCopy = newArrayList(modelListeners);
	}
	CancelIndicator cancelIndicator = getCancelIndicator();
	for (IXtextModelListener listener : modelListenersCopy){
		try {
			if (res != this.resource) {
				return;
			}
			
			operationCanceledManager.checkCanceled(cancelIndicator);
			if (listener instanceof IXtextModelListenerExtension) {
				((IXtextModelListenerExtension)listener).modelChanged(res, cancelIndicator);
			} else {
				listener.modelChanged(res);
			}
		
		} catch(Exception exc) {
			operationCanceledManager.propagateIfCancelException(exc);
			log.error("Error in IXtextModelListener", exc);
		} catch (OperationCanceledError e) {
			throw e.getWrapped();
		}
	}
}
 
Example #11
Source File: XtendResourceValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<Issue> validate(final Resource resource, final CheckMode mode, final CancelIndicator mon) throws OperationCanceledError {
  List<Issue> _xtrycatchfinallyexpression = null;
  try {
    _xtrycatchfinallyexpression = super.validate(resource, mode, mon);
  } finally {
    boolean _isEditor = ResourceSetContext.get(resource).isEditor();
    if (_isEditor) {
      final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(resource.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
      resource.eAdapters().remove(adapter);
    }
  }
  return _xtrycatchfinallyexpression;
}
 
Example #12
Source File: CachingResourceValidatorImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<Issue> validate(final Resource resource, final CheckMode mode, final CancelIndicator mon) throws OperationCanceledError {
  final Provider<List<Issue>> _function = () -> {
    this.operationCanceledManager.checkCanceled(mon);
    return super.validate(resource, mode, mon);
  };
  return this.cache.<List<Issue>>get(mode, resource, _function);
}
 
Example #13
Source File: ResourceValidatorImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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();
	}
}
 
Example #14
Source File: TypeResolutionCancelTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRunTypeResolution() throws Exception {
	XExpression exp = expression("true");
	try {
		resolver.resolveTypes(exp, () -> false);
	} catch (OperationCanceledError e) {
		Assert.fail("Type resolution should not have been canceled");
	}
}
 
Example #15
Source File: TypeResolutionCancelTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCancelTypeResolution() throws Exception {
	XExpression exp = expression("true");
	try {
		resolver.resolveTypes(exp, () -> true);
		Assert.fail("Type resolution should have been canceled");
	} catch (OperationCanceledError e) {
		// ok, expected
	}
}
 
Example #16
Source File: NamesAreUniqueValidationHelperTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@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);
}
 
Example #17
Source File: IssuesProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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, ci);
	if (!issues.contains(null)) {
		operationCanceledManager.checkCanceled(ci);
		return issues;
	}
	ArrayList<Issue> result = new ArrayList<>(issues);
	result.removeAll(Collections.<Issue> singleton(null));
	operationCanceledManager.checkCanceled(ci);
	return result;
}
 
Example #18
Source File: FutureUtil.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static Throwable getCancellation(Throwable e) {
	while (e != null) {
		if (e instanceof OperationCanceledError
				|| e instanceof OperationCanceledException
				|| e instanceof CancellationException) {
			return e;
		}
		e = e.getCause();
	}
	return null;
}
 
Example #19
Source File: OutdatedStateManagerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test(expected = OperationCanceledError.class)
public void testCancellation2() {
	outdatedStateManager.exec((r) -> {
		throw new OperationCanceledError(null);
	}, resource);
}
 
Example #20
Source File: IResourceValidator.java    From xtext-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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;
 
Example #21
Source File: IReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
IResolvedTypes reentrantResolve(CancelIndicator monitor) throws OperationCanceledError;