Search in sources :

Example 31 with OperationCanceledException

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

the class Resource method delete.

@Override
public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        //            String message = NLS.bind(Messages.resources_deleting, getFullPath());
        //            monitor.beginTask("", Policy.totalWork * 1000); //$NON-NLS-1$
        //            monitor.subTask(message);
        final ISchedulingRule rule = workspace.getRuleFactory().deleteRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            // if there is no resource then there is nothing to delete so just return
            if (!exists())
                return;
            workspace.beginOperation(true);
            //                broadcastPreDeleteEvent();
            // when a project is being deleted, flush the build order in case there is a problem
            //                if (this.getType() == IResource.PROJECT)
            //                    workspace.flushBuildOrder();
            //                final IFileStore originalStore = getStore();
            //                boolean wasLinked = isLinked();
            //                message = Messages.resources_deleteProblem;
            //                MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_DELETE_LOCAL, message, null);
            WorkManager workManager = workspace.getWorkManager();
            //                ResourceTree tree = new ResourceTree(workspace.getFileSystemManager(), workManager.getLock(), status, updateFlags);
            int depth = 0;
            try {
                depth = workManager.beginUnprotected();
                workspace.delete(this);
            //                    unprotectedDelete(tree, updateFlags, monitor);
            } finally {
                workManager.endUnprotected(depth);
            }
            if (getType() == ROOT) {
            //                    // need to clear out the root info
            //                    workspace.getMarkerManager().removeMarkers(this, IResource.DEPTH_ZERO);
            //                    getPropertyManager().deleteProperties(this, IResource.DEPTH_ZERO);
            //                    getResourceInfo(false, false).clearSessionProperties();
            }
        // Invalidate the tree for further use by clients.
        //                tree.makeInvalid();
        //                if (!tree.getStatus().isOK())
        //                    throw new ResourceException(tree.getStatus());
        //update any aliases of this resource
        //note that deletion of a linked resource cannot affect other resources
        //                if (!wasLinked)
        //                    workspace.getAliasManager().updateAliases(this, originalStore, IResource.DEPTH_INFINITE, monitor);
        //                if (getType() == PROJECT) {
        //                     make sure the rule factory is cleared on project deletion
        //                    ((Rules) workspace.getRuleFactory()).setRuleFactory((IProject) this, null);
        //                     make sure project deletion is remembered
        //                    workspace.getSaveManager().requestSnapshot();
        //                }
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork * 1000));
        }
    } finally {
        monitor.done();
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 32 with OperationCanceledException

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

the class Workspace method delete.

@Override
public IStatus delete(IResource[] resources, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        int opWork = Math.max(resources.length, 1);
        int totalWork = Policy.totalWork * opWork / Policy.opWork;
        String message = Messages.resources_deleting_0;
        monitor.beginTask(message, totalWork);
        message = Messages.resources_deleteProblem;
        MultiStatus result = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.INTERNAL_ERROR, message, null);
        if (resources.length == 0)
            return result;
        // to avoid concurrent changes to this array
        resources = resources.clone();
        try {
            prepareOperation(getRoot(), monitor);
            beginOperation(true);
            for (int i = 0; i < resources.length; i++) {
                Policy.checkCanceled(monitor);
                Resource resource = (Resource) resources[i];
                if (resource == null) {
                    monitor.worked(1);
                    continue;
                }
                try {
                    resource.delete(updateFlags, Policy.subMonitorFor(monitor, 1));
                } catch (CoreException e) {
                    // Don't really care about the exception unless the resource is still around.
                    ResourceInfo info = resource.getResourceInfo(false, false);
                    if (resource.exists(resource.getFlags(info), false)) {
                        message = NLS.bind(Messages.resources_couldnotDelete, resource.getFullPath());
                        result.merge(new org.eclipse.core.internal.resources.ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, resource.getFullPath(), message));
                        result.merge(e.getStatus());
                    }
                }
            }
            if (result.matches(IStatus.ERROR))
                throw new ResourceException(result);
            return result;
        } catch (OperationCanceledException e) {
            getWorkManager().operationCanceled();
            throw e;
        } finally {
            endOperation(getRoot(), true, Policy.subMonitorFor(monitor, totalWork - opWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResource(org.eclipse.core.resources.IResource) MultiStatus(org.eclipse.core.runtime.MultiStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException)

Example 33 with OperationCanceledException

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

the class JavaCompletionProposalComputer method internalComputeCompletionProposals.

private List<ICompletionProposal> internalComputeCompletionProposals(int offset, JavaContentAssistInvocationContext context) {
    ICompilationUnit unit = context.getCompilationUnit();
    if (unit == null)
        return Collections.emptyList();
    ITextViewer viewer = context.getViewer();
    CompletionProposalCollector collector = createCollector(context);
    collector.setInvocationContext(context);
    // Allow completions for unresolved types - since 3.3
    collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.TYPE_REF, CompletionProposal.TYPE_REF, true);
    // Set the favorite list to propose static members - since 3.3
    collector.setFavoriteReferences(getFavoriteStaticMembers());
    try {
        Point selection = viewer.getSelectedRange();
        if (selection.y > 0)
            collector.setReplacementLength(selection.y);
        unit.codeComplete(offset, collector, fTimeoutProgressMonitor);
    } catch (OperationCanceledException x) {
        //			IBindingService bindingSvc= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
        //			String keyBinding= bindingSvc.getBestActiveBindingFormattedFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
        //			fErrorMessage= Messages.format(JavaTextMessages.CompletionProcessor_error_javaCompletion_took_too_long_message, keyBinding);
        JavaPlugin.log(x);
    } catch (JavaModelException x) {
        //			Shell shell= viewer.getTextWidget().getShell();
        //			if (x.isDoesNotExist() && !unit.getJavaProject().isOnClasspath(unit))
        //				MessageDialog.openInformation(shell, JavaTextMessages.CompletionProcessor_error_notOnBuildPath_title, JavaTextMessages.CompletionProcessor_error_notOnBuildPath_message);
        //			else
        //				ErrorDialog.openError(shell, JavaTextMessages.CompletionProcessor_error_accessing_title, JavaTextMessages.CompletionProcessor_error_accessing_message, x.getStatus());
        JavaPlugin.log(x);
    }
    ICompletionProposal[] javaProposals = collector.getJavaCompletionProposals();
    int contextInformationOffset = guessMethodContextInformationPosition(context);
    if (contextInformationOffset != offset) {
        for (int i = 0; i < javaProposals.length; i++) {
            if (javaProposals[i] instanceof JavaMethodCompletionProposal) {
                JavaMethodCompletionProposal jmcp = (JavaMethodCompletionProposal) javaProposals[i];
                jmcp.setContextInformationPosition(contextInformationOffset);
            }
        }
    }
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(Arrays.asList(javaProposals));
    if (proposals.size() == 0) {
        String error = collector.getErrorMessage();
        if (error.length() > 0)
            fErrorMessage = error;
    }
    return proposals;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) ITextViewer(org.eclipse.che.jface.text.ITextViewer) CompletionProposalCollector(org.eclipse.jdt.ui.text.java.CompletionProposalCollector) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal)

Example 34 with OperationCanceledException

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

the class IntroduceFactoryRefactoring method createChange.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.IntroduceFactory_createChanges, fAllCallsTo.length);
        final ITypeBinding binding = fFactoryOwningClass.resolveBinding();
        final Map<String, String> arguments = new HashMap<String, String>();
        String project = null;
        IJavaProject javaProject = fCUHandle.getJavaProject();
        if (javaProject != null)
            project = javaProject.getElementName();
        int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
        if (binding.isNested() && !binding.isMember())
            flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
        final String description = Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fCtorOwningClass.getName().getIdentifier()));
        final String header = Messages.format(RefactoringCoreMessages.IntroduceFactory_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fNewMethodName), BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(fCtorBinding, JavaElementLabels.ALL_FULLY_QUALIFIED) });
        final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
        comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(fCtorBinding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_factory_pattern, BasicElementLabels.getJavaElementName(fNewMethodName)));
        comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_owner_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        if (fProtectConstructor)
            comment.addSetting(RefactoringCoreMessages.IntroduceFactoryRefactoring_declare_private);
        final IntroduceFactoryDescriptor descriptor = RefactoringSignatureDescriptorFactory.createIntroduceFactoryDescriptor(project, description, comment.asString(), arguments, flags);
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCUHandle));
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fNewMethodName);
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + 1, JavaRefactoringDescriptorUtil.elementToHandle(project, binding.getJavaElement()));
        //$NON-NLS-1$
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
        arguments.put(ATTRIBUTE_PROTECT, Boolean.valueOf(fProtectConstructor).toString());
        final DynamicValidationStateChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.IntroduceFactory_name);
        boolean hitInFactoryClass = false;
        boolean hitInCtorClass = false;
        for (int i = 0; i < fAllCallsTo.length; i++) {
            SearchResultGroup rg = fAllCallsTo[i];
            ICompilationUnit unitHandle = rg.getCompilationUnit();
            CompilationUnitChange cuChange = new CompilationUnitChange(getName(), unitHandle);
            if (addAllChangesFor(rg, unitHandle, cuChange))
                result.add(cuChange);
            if (unitHandle.equals(fFactoryUnitHandle))
                hitInFactoryClass = true;
            if (unitHandle.equals(ASTCreator.getCu(fCtorOwningClass)))
                hitInCtorClass = true;
            pm.worked(1);
            if (pm.isCanceled())
                throw new OperationCanceledException();
        }
        if (!hitInFactoryClass) {
            // Handle factory class if no search hits there
            CompilationUnitChange cuChange = new CompilationUnitChange(getName(), fFactoryUnitHandle);
            addAllChangesFor(null, fFactoryUnitHandle, cuChange);
            result.add(cuChange);
        }
        if (!hitInCtorClass && !fFactoryUnitHandle.equals(ASTCreator.getCu(fCtorOwningClass))) {
            // Handle constructor-owning class if no search hits there
            CompilationUnitChange cuChange = new CompilationUnitChange(getName(), ASTCreator.getCu(fCtorOwningClass));
            addAllChangesFor(null, ASTCreator.getCu(fCtorOwningClass), cuChange);
            result.add(cuChange);
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HashMap(java.util.HashMap) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) IntroduceFactoryDescriptor(org.eclipse.jdt.core.refactoring.descriptors.IntroduceFactoryDescriptor) IJavaProject(org.eclipse.jdt.core.IJavaProject) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 35 with OperationCanceledException

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

the class ExtractMethodRefactoring method checkFinalConditions.

/* (non-Javadoc)
	 * Method declared in Refactoring
	 */
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    pm.beginTask(RefactoringCoreMessages.ExtractMethodRefactoring_checking_new_name, 2);
    pm.subTask(EMPTY);
    RefactoringStatus result = checkMethodName();
    result.merge(checkParameterNames());
    result.merge(checkVarargOrder());
    pm.worked(1);
    if (pm.isCanceled())
        throw new OperationCanceledException();
    BodyDeclaration node = fAnalyzer.getEnclosingBodyDeclaration();
    if (node != null) {
        fAnalyzer.checkInput(result, fMethodName, fDestination);
        pm.worked(1);
    }
    pm.done();
    return result;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration)

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