Search in sources :

Example 66 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project xtext-core by eclipse.

the class ReferenceFinder method findReferences.

@Override
public void findReferences(TargetURIs targetURIs, Set<URI> candidates, IResourceAccess resourceAccess, IResourceDescriptions descriptions, Acceptor acceptor, IProgressMonitor monitor) {
    if (!targetURIs.isEmpty() && !candidates.isEmpty()) {
        SubMonitor subMonitor = SubMonitor.convert(monitor, targetURIs.size() / MONITOR_CHUNK_SIZE + 1);
        IProgressMonitor useMe = subMonitor.newChild(1);
        int i = 0;
        for (URI candidate : candidates) {
            if (subMonitor.isCanceled())
                throw new OperationCanceledException();
            IReferenceFinder languageSpecific = getLanguageSpecificReferenceFinder(candidate);
            doFindReferencesWith(languageSpecific, targetURIs, candidate, resourceAccess, descriptions, acceptor, useMe);
            i++;
            if (i % MONITOR_CHUNK_SIZE == 0) {
                useMe = subMonitor.newChild(1);
            }
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(org.eclipse.emf.common.util.URI)

Example 67 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project xtext-core by eclipse.

the class FileSystemAccessQueue method send.

protected FileSystemAccessRequest send(final FileSystemAccessRequest request) {
    try {
        boolean _isCanceled = this.monitor.isCanceled();
        if (_isCanceled) {
            throw new OperationCanceledException();
        }
        this.requestQueue.put(request);
        return request;
    } catch (final Throwable _t) {
        if (_t instanceof InterruptedException) {
            throw new OperationCanceledException();
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 68 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class CheckConditionsContext method check.

/**
	 * Checks the condition of all registered condition checkers and returns a
	 * merge status result.
	 *
	 * @param pm a progress monitor or <code>null</code> if no progress
	 *  reporting is desired
	 *
	 * @return the combined status result
	 *
	 * @throws CoreException if an error occurs during condition checking
	 */
public RefactoringStatus check(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    RefactoringStatus result = new RefactoringStatus();
    mergeResourceOperationAndValidateEdit();
    List values = new ArrayList(fCheckers.values());
    Collections.sort(values, new Comparator() {

        public int compare(Object o1, Object o2) {
            // ResourceOperationChecker
            if (o1 instanceof ResourceChangeChecker)
                return -1;
            if (o2 instanceof ResourceChangeChecker)
                return 1;
            return 0;
        }
    });
    //$NON-NLS-1$
    pm.beginTask("", values.size());
    for (Iterator iter = values.iterator(); iter.hasNext(); ) {
        IConditionChecker checker = (IConditionChecker) iter.next();
        result.merge(checker.check(new SubProgressMonitor(pm, 1)));
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ArrayList(java.util.ArrayList) List(java.util.List) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) Comparator(java.util.Comparator)

Example 69 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class ProcessorBasedRefactoring method checkFinalConditions.

/**
	 * {@inheritDoc}
	 */
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    RefactoringStatus result = new RefactoringStatus();
    CheckConditionsContext context = createCheckConditionsContext();
    //$NON-NLS-1$
    pm.beginTask("", 9);
    pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_final_conditions);
    result.merge(getProcessor().checkFinalConditions(new SubProgressMonitor(pm, 5), context));
    if (result.hasFatalError()) {
        pm.done();
        return result;
    }
    if (pm.isCanceled())
        throw new OperationCanceledException();
    // must not be shared when checkFinalConditions is called again
    SharableParticipants sharableParticipants = new SharableParticipants();
    RefactoringParticipant[] loadedParticipants = getProcessor().loadParticipants(result, sharableParticipants);
    if (loadedParticipants == null || loadedParticipants.length == 0) {
        fParticipants = EMPTY_PARTICIPANTS;
    } else {
        fParticipants = new ArrayList();
        for (int i = 0; i < loadedParticipants.length; i++) {
            fParticipants.add(loadedParticipants[i]);
        }
    }
    if (result.hasFatalError()) {
        pm.done();
        return result;
    }
    IProgressMonitor sm = new SubProgressMonitor(pm, 2);
    //$NON-NLS-1$
    sm.beginTask("", fParticipants.size());
    for (Iterator iter = fParticipants.iterator(); iter.hasNext() && !result.hasFatalError(); ) {
        RefactoringParticipant participant = (RefactoringParticipant) iter.next();
        //$NON-NLS-1$
        final PerformanceStats stats = PerformanceStats.getStats(PERF_CHECK_CONDITIONS, getName() + ", " + participant.getName());
        stats.startRun();
        try {
            result.merge(participant.checkConditions(new SubProgressMonitor(sm, 1), context));
        } catch (OperationCanceledException e) {
            throw e;
        } catch (RuntimeException e) {
            // remove the participant so that it will be ignored during change execution.
            RefactoringCorePlugin.log(e);
            result.merge(RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.ProcessorBasedRefactoring_check_condition_participant_failed, participant.getName())));
            iter.remove();
        }
        stats.endRun();
        if (sm.isCanceled())
            throw new OperationCanceledException();
    }
    sm.done();
    if (result.hasFatalError()) {
        pm.done();
        return result;
    }
    result.merge(context.check(new SubProgressMonitor(pm, 1)));
    pm.done();
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) Iterator(java.util.Iterator)

Example 70 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class PerformChangeOperation method run.

/**
	 * {@inheritDoc}
	 */
public void run(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    try {
        fChangeExecuted = false;
        if (createChange()) {
            //$NON-NLS-1$
            pm.beginTask("", 4);
            //$NON-NLS-1$
            pm.subTask("");
            fCreateChangeOperation.run(new SubProgressMonitor(pm, 3));
            // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=187265 ):
            if (pm.isCanceled())
                throw new OperationCanceledException();
            fChange = fCreateChangeOperation.getChange();
            if (fChange != null) {
                executeChange(new SubProgressMonitor(pm, 1));
            } else {
                pm.worked(1);
            }
        } else {
            executeChange(pm);
        }
    } finally {
        pm.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)134 CoreException (org.eclipse.core.runtime.CoreException)38 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)34 ArrayList (java.util.ArrayList)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)24 IOException (java.io.IOException)21 IFile (org.eclipse.core.resources.IFile)21 IStatus (org.eclipse.core.runtime.IStatus)21 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 Status (org.eclipse.core.runtime.Status)16 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)16 File (java.io.File)15 SubMonitor (org.eclipse.core.runtime.SubMonitor)10 Job (org.eclipse.core.runtime.jobs.Job)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)9 IProject (org.eclipse.core.resources.IProject)8 HashSet (java.util.HashSet)7 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)7