org.eclipse.xtext.service.OperationCanceledManager Java Examples

The following examples show how to use org.eclipse.xtext.service.OperationCanceledManager. 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: EclipseUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Same as {@link #runInModalDialog(OperationCanceledManager, IRunnableWithProgress)}, but allows reacting to
 * exceptions.
 *
 * @param throwableHandler
 *            will be invoked on the runnable's thread in case the runnable throws an exception other than a
 *            {@link OperationCanceledManager#isOperationCanceledException(Throwable) cancellation exception}. May
 *            be <code>null</code> if no handling of exceptions is required.
 */
public static void runInModalDialog(OperationCanceledManager ocm, IRunnableWithProgress runnable,
		Consumer<Throwable> throwableHandler) {
	try {
		final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		final ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
		dlg.run(true, true, monitor -> {
			try {
				runnable.run(monitor);
			} catch (Throwable th) {
				// translate cancellation exceptions from Eclipse/Xtext to SWT/JFace world
				if (ocm.isOperationCanceledException(th)) {
					throw new InterruptedException();
				}
				if (throwableHandler != null) {
					throwableHandler.accept(th);
				}
				throw th;
			}
		});
	} catch (InvocationTargetException | InterruptedException e) {
		// ignore
	}
}
 
Example #2
Source File: TypeResource.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOException {
	try {
		if (getURI() != null && mirror != null) {
			if (mirror instanceof IMirrorOptionsAware) {
				((IMirrorOptionsAware)mirror).initialize(this, options);
			} else {
				mirror.initialize(this);
			}
		}
	} catch(Exception e) {
		if (typeResourceServices != null) {
			OperationCanceledManager operationCanceledManager = typeResourceServices.getOperationCanceledManager();
			if (operationCanceledManager.isOperationCanceledException(e)) {
				unload();
			}
			operationCanceledManager.propagateAsErrorIfCancelException(e);
		}	
		throw new CannotLoadTypeResourceException(e);
	}
}
 
Example #3
Source File: XtextDocumentModifyTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private IXtextDocument createDocument(String model) throws Exception {
	resource = getResource(new StringInputStream(model));
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	
	final XtextDocument document = new XtextDocument(tokenSource, get(ITextEditComposer.class), new OutdatedStateManager(), new OperationCanceledManager()) {
		@Override
		public <T> T internalModify(IUnitOfWork<T, XtextResource> work) {
			try {
				return work.exec((XtextResource) resource);
			}
			catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	};
	document.set(model);
	return document;
}
 
Example #4
Source File: DocumentPartitionerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public XtextDocument getDocument(String s) {
	TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {{
		setTokenDefProvider(new AntlrTokenDefProvider() {
			{
				setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
			}
		});
	}};
	PartitionTokenScanner scanner = new PartitionTokenScanner();
	scanner.setMapper(mapper);
	DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.setDocumentPartitioner(partitioner);
	partitioner.connect(document);
	document.set(s);
	return document;
}
 
Example #5
Source File: IssuesProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("javadoc")
public IssuesProvider(IResourceValidator resourceValidator, Resource res, CheckMode checkMode,
		OperationCanceledManager operationCanceledManager, CancelIndicator ci) {
	this.rv = resourceValidator;
	this.r = res;
	this.checkMode = checkMode;
	this.operationCanceledManager = operationCanceledManager;
	this.ci = ci;
}
 
Example #6
Source File: InferenceContext.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new, empty inference context for the given inference variables. The cancellation manager and indicator
 * may be <code>null</code>.
 *
 * @param G
 *            a rule environment used for subtype checking, etc. during constraint resolution. This rule environment
 *            will not be changed by the inference context AND it is expected to <b>not</b> be changed by anyone
 *            else during the life-time of the inference context.
 * @param inferenceVariables
 *            the meta variables to be inferred.
 */
public InferenceContext(N4JSTypeSystem ts, TypeSystemHelper tsh, OperationCanceledManager operationCanceledManager,
		CancelIndicator cancelIndicator, RuleEnvironment G, InferenceVariable... inferenceVariables) {
	Objects.requireNonNull(ts);
	Objects.requireNonNull(tsh);
	Objects.requireNonNull(G);
	this.ts = ts;
	this.tsh = tsh;
	this.operationCanceledManager = operationCanceledManager;
	this.cancelIndicator = cancelIndicator;
	this.G = G;
	addInferenceVariables(false, inferenceVariables);
	this.reducer = new Reducer(this, G, ts, tsh);
	this.currentBounds = new BoundSet(this, G, ts);
}
 
Example #7
Source File: OutlineTreeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected XtextDocument createXtextDocument(String modelAsText) throws Exception {
	final XtextResource resource = getResource(modelAsText, "test.outlinetestlanguage");
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	XtextDocument xtextDocument = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	xtextDocument.setInput(resource);
	xtextDocument.set(modelAsText);
	return xtextDocument;	
}
 
Example #8
Source File: DamagerRepairerPerformanceTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Document createDocument(String before) {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.set(before);
	return document;
}
 
Example #9
Source File: RequestManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected final OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
Example #10
Source File: SourceContainerAwareResourceValidator.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Inject
private SourceContainerAwareResourceValidator(IN4JSEclipseCore eclipseCore,
		OperationCanceledManager operationCanceledManager) {
	this.eclipseCore = eclipseCore;
	this.operationCanceledManager = operationCanceledManager;
}
 
Example #11
Source File: RequestManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public RequestManager(ExecutorService parallel, OperationCanceledManager operationCanceledManager) {
	this.parallel = parallel;
	this.operationCanceledManager = operationCanceledManager;
}
 
Example #12
Source File: DerivedStateAwareResourceTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TestedResource() {
	operationCanceledManager = new OperationCanceledManager();
}
 
Example #13
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public DirectRequestManager(final OperationCanceledManager operationCanceledManager) {
  super(null, operationCanceledManager);
}
 
Example #14
Source File: CompositeEValidator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.18
 */
public void setOperationCanceledManager(OperationCanceledManager operationCanceledManager) {
	this.operationCanceledManager = operationCanceledManager;
}
 
Example #15
Source File: CompositeEValidator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.18
 */
public OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
Example #16
Source File: ResourceValidatorImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.9
 */
protected OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
Example #17
Source File: DefaultQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public CancelableResolutionAcceptor(IssueResolutionAcceptor delegate, CancelIndicator monitor, OperationCanceledManager manager) {
	super(null);
	this.delegate = delegate;
	this.monitor = monitor;
	this.manager = manager;
}
 
Example #18
Source File: DefaultQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.8
 */
protected OperationCanceledManager getCancelManager() {
	return cancelManager;
}
 
Example #19
Source File: XtextDocument.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.8
 * @noreference This constructor is not intended to be referenced by clients. Only for testing
 */
public XtextDocument(DocumentTokenSource tokenSource, ITextEditComposer composer, OutdatedStateManager outdatedStateManager, OperationCanceledManager operationCanceledManager) {
	this(tokenSource, composer);
	this.outdatedStateManager = outdatedStateManager;
	this.operationCanceledManager = operationCanceledManager;
}
 
Example #20
Source File: TypeResourceServices.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
Example #21
Source File: DefaultReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
Example #22
Source File: EclipseUtils.java    From n4js with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Runs the given runnable in a {@link ProgressMonitorDialog}. Must be called from the UI thread.
 * <p>
 * <b>Before using this method</b>, ensure that in your use case it makes sense to have a modal dialog instead of
 * using an Eclipse {@link Job} (by default, always use the job framework!) and that this method's exact behavior is
 * appropriate for your use case (e.g. calling the <code>run()</code> method with 'fork' set to <code>true</code>,
 * ignoring invocation target exceptions).
 *
 * @param ocm
 *            an operation canceled manager as obtained via injection.
 * @param runnable
 *            the runnable to execute.
 */
public static void runInModalDialog(OperationCanceledManager ocm, IRunnableWithProgress runnable) {
	runInModalDialog(ocm, runnable, null);
}