use of org.eclipse.xtext.service.OperationCanceledError in project xtext-eclipse by eclipse.
the class SyncUtil method waitForReconciler.
/**
* this methods blocks until the following jobs have finished,
* - the reconciler
* - the editor validation job
* - the dirty state editor updater job
*/
public void waitForReconciler(XtextEditor editor) {
try {
editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
// this doesn't execute before the reconciler has finished
}
});
// reconciling schedules both, validation and dirty state
Job validationJob = ((XtextDocument) editor.getDocument()).getValidationJob();
if (validationJob != null) {
validationJob.join();
}
editor.getDirtyStateEditorSupport().waitForUpdateEditorJob();
} catch (OperationCanceledException e) {
} catch (OperationCanceledError e) {
} catch (InterruptedException e) {
LOG.error(e.getMessage(), e);
}
}
use of org.eclipse.xtext.service.OperationCanceledError in project xtext-core by eclipse.
the class NamesAreUniqueValidationHelperTest method testCreatedErrors_06.
@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);
}
use of org.eclipse.xtext.service.OperationCanceledError in project xtext-core by eclipse.
the class DerivedStateAwareResourceTest method testOperationCanceledExceptionOnInstall.
@Test
public void testOperationCanceledExceptionOnInstall() {
TestedResource resource = new TestedResource();
resource.setIsLoaded();
resource.setDerivedStateComputer(new IDerivedStateComputer() {
private boolean canceled = true;
@Override
public void installDerivedState(DerivedStateAwareResource resource, boolean resolve) {
resource.getContents().add(EcoreFactory.eINSTANCE.createEObject());
if (canceled) {
canceled = false;
throw new OperationCanceledException();
}
}
@Override
public void discardDerivedState(DerivedStateAwareResource resource) {
resource.getContents().clear();
}
});
assertFalse(resource.isFullyInitialized());
try {
resource.getContents();
fail("exception expected");
} catch (OperationCanceledError e) {
// expected
}
assertFalse(resource.isFullyInitialized());
assertTrue(resource.getErrors().isEmpty());
assertFalse(resource.getContents().isEmpty());
assertTrue(resource.isFullyInitialized());
assertTrue(resource.getErrors().isEmpty());
}
use of org.eclipse.xtext.service.OperationCanceledError in project xtext-eclipse by eclipse.
the class XtextDocument method notifyModelListeners.
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();
}
}
}
use of org.eclipse.xtext.service.OperationCanceledError in project xtext-eclipse by eclipse.
the class XtextBuilder method build.
@SuppressWarnings("rawtypes")
@Override
protected IProject[] build(final int kind, Map args, IProgressMonitor monitor) throws CoreException {
if (IBuildFlag.FORGET_BUILD_STATE_ONLY.isSet(args)) {
forgetLastBuiltState();
return getProject().getReferencedProjects();
}
Job.getJobManager().addJobChangeListener(MAKE_EGIT_JOB_SYSTEM);
long startTime = System.currentTimeMillis();
StoppedTask task = Stopwatches.forTask(String.format("XtextBuilder.build[%s]", getKindAsString(kind)));
try {
queuedBuildData.createCheckpoint();
if (shouldCancelBuild(kind)) {
throw new OperationCanceledException("Build has been interrupted");
}
task.start();
if (monitor != null) {
// $NON-NLS-1$
final String taskName = Messages.XtextBuilder_Building + getProject().getName() + ": ";
monitor = new ProgressMonitorWrapper(monitor) {
@Override
public void subTask(String name) {
super.subTask(taskName + name);
}
@Override
public boolean isCanceled() {
boolean shouldCancelBuild = shouldCancelBuild(kind);
if (shouldCancelBuild)
buildLogger.log("interrupted");
return shouldCancelBuild || super.isCanceled();
}
};
}
SubMonitor progress = SubMonitor.convert(monitor, 1);
if (kind == FULL_BUILD) {
fullBuild(progress.newChild(1), IBuildFlag.RECOVERY_BUILD.isSet(args));
} else {
IResourceDelta delta = getDelta(getProject());
if (delta == null || isOpened(delta)) {
fullBuild(progress.newChild(1), IBuildFlag.RECOVERY_BUILD.isSet(args));
} else {
incrementalBuild(delta, progress.newChild(1));
}
}
} catch (CoreException e) {
log.error(e.getMessage(), e);
throw e;
} catch (OperationCanceledException e) {
handleCanceled(e);
} catch (OperationCanceledError err) {
handleCanceled(err);
} catch (Exception e) {
log.error(e.getMessage(), e);
buildLogger.log(e.getClass().getSimpleName() + " while building " + getProject().getName() + ": " + e.getMessage() + " (see logs for details)");
forgetLastBuiltState();
} finally {
queuedBuildData.discardCheckpoint();
if (monitor != null)
monitor.done();
String message = "Build " + getProject().getName() + " in " + (System.currentTimeMillis() - startTime) + " ms";
log.info(message);
buildLogger.log(message);
task.stop();
Job.getJobManager().removeJobChangeListener(MAKE_EGIT_JOB_SYSTEM);
}
return getProject().getReferencedProjects();
}
Aggregations