Search in sources :

Example 56 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project AutoRefactor by JnRouvignac.

the class AggregateASTVisitor method logFaultyVisitor.

private void logFaultyVisitor(ASTVisitor v, ASTNode node, Exception e) {
    if (e instanceof OperationCanceledException) {
        // let the user cancel the current operation
        throw (OperationCanceledException) e;
    }
    String message = "Visitor " + v.getClass().getName() + " is faulty," + " it will be disabled for the rest of this run.";
    ctx.getLogger().error(message, new UnhandledException(node, message, e));
}
Also used : UnhandledException(org.autorefactor.util.UnhandledException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 57 with OperationCanceledException

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

the class ExtractMethodRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    StatusWrapper status = statusProvider.get();
    try {
        status.merge(validateMethodName(methodName));
        status.merge(validateParameters());
        ITextRegion expressionsRegion = getExpressionsRegion();
        ITextRegion predecessorRegion = locationInFileProvider.getFullTextRegion(originalMethod);
        if (pm.isCanceled()) {
            throw new OperationCanceledException();
        }
        Section expressionSection = rewriter.newSection(expressionsRegion.getOffset(), expressionsRegion.getLength());
        Section declarationSection = rewriter.newSection(predecessorRegion.getOffset() + predecessorRegion.getLength(), 0);
        createMethodCallEdit(expressionSection, expressionsRegion);
        if (pm.isCanceled()) {
            throw new OperationCanceledException();
        }
        createMethodDeclarationEdit(declarationSection, expressionSection.getBaseIndentLevel(), expressionsRegion);
        if (pm.isCanceled()) {
            throw new OperationCanceledException();
        }
        textEdit = replaceConverter.convertToTextEdit(rewriter.getChanges());
    } catch (OperationCanceledException e) {
        throw e;
    } catch (Exception exc) {
        handleException(exc, status);
    }
    return status.getRefactoringStatus();
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) StatusWrapper(org.eclipse.xtext.ui.refactoring.impl.StatusWrapper) Section(org.eclipse.xtext.xbase.ui.document.DocumentRewriter.Section) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 58 with OperationCanceledException

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

the class OverrideIndicatorModelListener method asyncUpdateAnnotationModel.

private void asyncUpdateAnnotationModel() {
    if (currentJob != null) {
        currentJob.cancel();
    }
    currentJob = new Job(JOB_NAME) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            try {
                return updateAnnotationModel(monitor);
            } catch (OperationCanceledException e) {
                return Status.CANCEL_STATUS;
            } catch (Exception e) {
                LOG.error("Error updating override indicator", e);
                return Status.OK_STATUS;
            }
        }
    };
    currentJob.setRule(SCHEDULING_RULE);
    currentJob.setPriority(Job.DECORATE);
    currentJob.setSystem(true);
    currentJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Job(org.eclipse.core.runtime.jobs.Job) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 59 with OperationCanceledException

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

the class AbstractTest method buildProject.

protected void buildProject(IProject proj) throws CoreException {
    IWorkspace wsp = ResourcesPlugin.getWorkspace();
    final IProject curProject = proj;
    ISchedulingRule rule = wsp.getRuleFactory().buildRule();
    Job buildJob = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "project build job") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                curProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
            } catch (CoreException e) {
                fail(e.getStatus().getMessage());
            } catch (OperationCanceledException e) {
                fail(NLS.bind(Messages.getString("AbstractTest.Build_cancelled"), curProject.getName(), // $NON-NLS-1$
                e.getMessage()));
            }
            return Status.OK_STATUS;
        }
    };
    buildJob.setRule(rule);
    buildJob.schedule();
    try {
        buildJob.join();
    } catch (InterruptedException e) {
        fail(NLS.bind(Messages.getString("AbstractTest.Build_interrupted"), curProject.getName(), // $NON-NLS-1$
        e.getMessage()));
    }
    IStatus status = buildJob.getResult();
    if (status.getCode() != IStatus.OK) {
        fail(NLS.bind(Messages.getString("AbstractTest.Build_failed"), curProject.getName(), // $NON-NLS-1$
        status.getMessage()));
    }
    IWorkspaceRunnable runnable = monitor -> curProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    wsp.run(runnable, wsp.getRoot(), IWorkspace.AVOID_UPDATE, null);
}
Also used : DebugPlugin(org.eclipse.debug.core.DebugPlugin) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) CProjectHelper(org.eclipse.linuxtools.internal.profiling.tests.CProjectHelper) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) ManagedCProjectNature(org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IPath(org.eclipse.core.runtime.IPath) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) EFS(org.eclipse.core.filesystem.EFS) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) NLS(org.eclipse.osgi.util.NLS) Status(org.eclipse.core.runtime.Status) IBinary(org.eclipse.cdt.core.model.IBinary) EFSExtensionManager(org.eclipse.cdt.utils.EFSExtensionManager) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ScannerConfigNature(org.eclipse.cdt.build.core.scannerconfig.ScannerConfigNature) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) FileSystemStructureProvider(org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ICProject(org.eclipse.cdt.core.model.ICProject) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) IDebugUIConstants(org.eclipse.debug.ui.IDebugUIConstants) FileLocator(org.eclipse.core.runtime.FileLocator) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Job(org.eclipse.core.runtime.jobs.Job) IProject(org.eclipse.core.resources.IProject) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 60 with OperationCanceledException

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

the class ChangeLogAction method createChangeLog.

protected IFile createChangeLog(IPath changelog) {
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    IWorkbench ws = PlatformUI.getWorkbench();
    final IFile changelog_File = myWorkspaceRoot.getFile(changelog);
    final InputStream initialContents = new ByteArrayInputStream(new byte[0]);
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        @Override
        public void execute(IProgressMonitor monitor) throws CoreException {
            try {
                // $NON-NLS-1$
                monitor.beginTask(Messages.getString("ChangeLog.AddingChangeLog"), 2000);
                changelog_File.create(initialContents, false, monitor);
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
            } finally {
                monitor.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(ws.getActiveWorkbenchWindow().getShell()).run(true, true, operation);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInterrupted"), e);
        return null;
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInvocation"), e);
        return null;
    }
    // FIXME:  we should put this refreshLocal call into a thread (filed as bug #256180)
    try {
        IContainer changelogContainer = myWorkspaceRoot.getContainerForLocation(changelog);
        if (changelogContainer != null)
            changelogContainer.refreshLocal(2, null);
    } catch (CoreException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrRefresh"), e);
        return null;
    }
    return changelog_File;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IContainer(org.eclipse.core.resources.IContainer)

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