Search in sources :

Example 1 with OperationCanceledError

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);
    }
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) OperationCanceledError(org.eclipse.xtext.service.OperationCanceledError) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XtextResource(org.eclipse.xtext.resource.XtextResource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) Job(org.eclipse.core.runtime.jobs.Job) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 2 with OperationCanceledError

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);
}
Also used : OperationCanceledError(org.eclipse.xtext.service.OperationCanceledError) ENamedElement(org.eclipse.emf.ecore.ENamedElement) Test(org.junit.Test)

Example 3 with OperationCanceledError

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());
}
Also used : OperationCanceledError(org.eclipse.xtext.service.OperationCanceledError) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Test(org.junit.Test)

Example 4 with OperationCanceledError

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();
        }
    }
}
Also used : OperationCanceledError(org.eclipse.xtext.service.OperationCanceledError) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BadLocationException(org.eclipse.jface.text.BadLocationException) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) IOException(java.io.IOException) WrappedException(org.eclipse.emf.common.util.WrappedException)

Example 5 with OperationCanceledError

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();
}
Also used : ProgressMonitorWrapper(org.eclipse.core.runtime.ProgressMonitorWrapper) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledError(org.eclipse.xtext.service.OperationCanceledError) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) StoppedTask(org.eclipse.xtext.util.internal.Stopwatches.StoppedTask) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

OperationCanceledError (org.eclipse.xtext.service.OperationCanceledError)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 CoreException (org.eclipse.core.runtime.CoreException)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 ProgressMonitorWrapper (org.eclipse.core.runtime.ProgressMonitorWrapper)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 ENamedElement (org.eclipse.emf.ecore.ENamedElement)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)1 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1 StoppedTask (org.eclipse.xtext.util.internal.Stopwatches.StoppedTask)1