Search in sources :

Example 26 with OperationCanceledException

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

the class InferTypeArgumentsConstraintsSolver method runSolver.

private void runSolver(SubProgressMonitor pm) {
    //$NON-NLS-1$
    pm.beginTask("", fWorkList.size() * 3);
    while (!fWorkList.isEmpty()) {
        // Get a variable whose type estimate has changed
        ConstraintVariable2 cv = fWorkList.removeFirst();
        List<ITypeConstraint2> usedIn = fTCModel.getUsedIn(cv);
        processConstraints(usedIn);
        pm.worked(1);
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    pm.done();
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2)

Example 27 with OperationCanceledException

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

the class ChangeSignatureProcessor method createChangeManager.

private TextChangeManager createChangeManager(IProgressMonitor pm, RefactoringStatus result) throws CoreException {
    pm.beginTask(RefactoringCoreMessages.ChangeSignatureRefactoring_preview, 2);
    fChangeManager = new TextChangeManager();
    boolean isNoArgConstructor = isNoArgConstructor();
    Map<ICompilationUnit, Set<IType>> namedSubclassMapping = null;
    if (isNoArgConstructor) {
        //create only when needed;
        namedSubclassMapping = createNamedSubclassMapping(new SubProgressMonitor(pm, 1));
    } else {
        pm.worked(1);
    }
    for (int i = 0; i < fOccurrences.length; i++) {
        if (pm.isCanceled())
            throw new OperationCanceledException();
        SearchResultGroup group = fOccurrences[i];
        ICompilationUnit cu = group.getCompilationUnit();
        if (cu == null)
            continue;
        CompilationUnitRewrite cuRewrite;
        if (cu.equals(getCu())) {
            cuRewrite = fBaseCuRewrite;
        } else {
            cuRewrite = new CompilationUnitRewrite(cu);
            cuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer());
        }
        ASTNode[] nodes = ASTNodeSearchUtil.findNodes(group.getSearchResults(), cuRewrite.getRoot());
        //IntroduceParameterObjectRefactoring needs to update declarations first:
        List<OccurrenceUpdate<? extends ASTNode>> deferredUpdates = new ArrayList<OccurrenceUpdate<? extends ASTNode>>();
        for (int j = 0; j < nodes.length; j++) {
            OccurrenceUpdate<? extends ASTNode> update = createOccurrenceUpdate(nodes[j], cuRewrite, result);
            if (update instanceof DeclarationUpdate) {
                update.updateNode();
            } else {
                deferredUpdates.add(update);
            }
        }
        for (Iterator<OccurrenceUpdate<? extends ASTNode>> iter = deferredUpdates.iterator(); iter.hasNext(); ) {
            iter.next().updateNode();
        }
        if (isNoArgConstructor && namedSubclassMapping.containsKey(cu)) {
            //only non-anonymous subclasses may have noArgConstructors to modify - see bug 43444
            Set<IType> subtypes = namedSubclassMapping.get(cu);
            for (Iterator<IType> iter = subtypes.iterator(); iter.hasNext(); ) {
                IType subtype = iter.next();
                AbstractTypeDeclaration subtypeNode = ASTNodeSearchUtil.getAbstractTypeDeclarationNode(subtype, cuRewrite.getRoot());
                if (subtypeNode != null)
                    modifyImplicitCallsToNoArgConstructor(subtypeNode, cuRewrite);
            }
        }
        TextChange change = cuRewrite.createChange(true);
        if (change != null)
            fChangeManager.manage(cu, change);
    }
    pm.done();
    return fChangeManager;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) Set(java.util.Set) HashSet(java.util.HashSet) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) TextChange(org.eclipse.ltk.core.refactoring.TextChange) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType) TightSourceRangeComputer(org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TextChangeManager(org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 28 with OperationCanceledException

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

the class TextMatchUpdater method updateTextMatches.

private void updateTextMatches(IProgressMonitor pm) throws JavaModelException {
    try {
        IProject[] projectsInScope = getProjectsInScope();
        //$NON-NLS-1$
        pm.beginTask("", projectsInScope.length);
        for (int i = 0; i < projectsInScope.length; i++) {
            if (pm.isCanceled())
                throw new OperationCanceledException();
            addTextMatches(projectsInScope[i], new SubProgressMonitor(pm, 1));
        }
    } finally {
        pm.done();
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 29 with OperationCanceledException

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

the class ChangeSignatureProcessor method checkInitialConditions.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException {
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 5);
        RefactoringStatus result = Checks.checkIfCuBroken(fMethod);
        if (result.hasFatalError())
            return result;
        if (fMethod == null || !fMethod.exists()) {
            String message = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_method_deleted, BasicElementLabels.getFileName(getCu()));
            return RefactoringStatus.createFatalErrorStatus(message);
        }
        if (fMethod.getDeclaringType().isInterface()) {
            fTopMethod = MethodChecks.overridesAnotherMethod(fMethod, fMethod.getDeclaringType().newSupertypeHierarchy(new SubProgressMonitor(monitor, 1)));
            monitor.worked(1);
        } else if (MethodChecks.isVirtual(fMethod)) {
            ITypeHierarchy hierarchy = getCachedTypeHierarchy(new SubProgressMonitor(monitor, 1));
            fTopMethod = MethodChecks.isDeclaredInInterface(fMethod, hierarchy, new SubProgressMonitor(monitor, 1));
            if (fTopMethod == null)
                fTopMethod = MethodChecks.overridesAnotherMethod(fMethod, hierarchy);
        }
        if (fTopMethod == null)
            fTopMethod = fMethod;
        if (!fTopMethod.equals(fMethod)) {
            if (fTopMethod.getDeclaringType().isInterface()) {
                RefactoringStatusContext context = JavaStatusContext.create(fTopMethod);
                String message = Messages.format(RefactoringCoreMessages.MethodChecks_implements, new String[] { JavaElementUtil.createMethodSignature(fTopMethod), BasicElementLabels.getJavaElementName(fTopMethod.getDeclaringType().getFullyQualifiedName('.')) });
                return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE, fTopMethod);
            } else {
                RefactoringStatusContext context = JavaStatusContext.create(fTopMethod);
                String message = Messages.format(RefactoringCoreMessages.MethodChecks_overrides, new String[] { JavaElementUtil.createMethodSignature(fTopMethod), BasicElementLabels.getJavaElementName(fTopMethod.getDeclaringType().getFullyQualifiedName('.')) });
                return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD, fTopMethod);
            }
        }
        if (monitor.isCanceled())
            throw new OperationCanceledException();
        if (fBaseCuRewrite == null || !fBaseCuRewrite.getCu().equals(getCu())) {
            fBaseCuRewrite = new CompilationUnitRewrite(getCu());
            fBaseCuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer());
        }
        RefactoringStatus[] status = TypeContextChecker.checkMethodTypesSyntax(fMethod, getParameterInfos(), fReturnTypeInfo);
        for (int i = 0; i < status.length; i++) {
            result.merge(status[i]);
        }
        monitor.worked(1);
        result.merge(createExceptionInfoList());
        monitor.worked(1);
        return result;
    } finally {
        monitor.done();
    }
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) TightSourceRangeComputer(org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 30 with OperationCanceledException

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

the class File method setContents.

@Override
public void setContents(InputStream content, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_settingContents, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        //            if (workspace.shouldValidate)
        //                workspace.validateSave(this);
        final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            ResourceInfo info = getResourceInfo(false, false);
            //                checkAccessible(getFlags(info));
            workspace.beginOperation(true);
            //                IFileInfo fileInfo = getStore().fetchInfo();
            internalSetContents(content, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork));
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
        FileUtil.safeClose(content);
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

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