Search in sources :

Example 51 with SubProgressMonitor

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

the class MoveCuUpdateCreator method addUpdates.

private void addUpdates(TextChangeManager changeManager, ICompilationUnit movedUnit, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 3);
        pm.subTask(Messages.format(RefactoringCoreMessages.MoveCuUpdateCreator_searching, BasicElementLabels.getFileName(movedUnit)));
        if (isInAnotherFragmentOfSamePackage(movedUnit, fDestination)) {
            pm.worked(3);
            return;
        }
        addImportToSourcePackageTypes(movedUnit, new SubProgressMonitor(pm, 1));
        removeImportsToDestinationPackageTypes(movedUnit);
        addReferenceUpdates(changeManager, movedUnit, new SubProgressMonitor(pm, 2), status);
    } finally {
        pm.done();
    }
}
Also used : SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 52 with SubProgressMonitor

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

the class RippleMethodFinder2 method getCachedHierarchy.

private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
    IType rep = fUnionFind.find(type);
    if (rep != null) {
        Collection<IType> collection = fRootReps.get(rep);
        for (Iterator<IType> iter = collection.iterator(); iter.hasNext(); ) {
            IType root = iter.next();
            ITypeHierarchy hierarchy = fRootHierarchies.get(root);
            if (hierarchy == null) {
                hierarchy = root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1));
                fRootHierarchies.put(root, hierarchy);
            }
            if (hierarchy.contains(type))
                return hierarchy;
        }
    }
    return null;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 53 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor 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 54 with SubProgressMonitor

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

the class ChangeSignatureProcessor method checkFinalConditions.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
	 */
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException {
    try {
        pm.beginTask(RefactoringCoreMessages.ChangeSignatureRefactoring_checking_preconditions, 8);
        RefactoringStatus result = new RefactoringStatus();
        clearManagers();
        fBaseCuRewrite.clearASTAndImportRewrites();
        fBaseCuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer());
        if (isSignatureSameAsInitial())
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeSignatureRefactoring_unchanged);
        result.merge(checkSignature(true));
        if (result.hasFatalError())
            return result;
        if (fDelegateUpdating && isSignatureClashWithInitial())
            result.merge(RefactoringStatus.createErrorStatus(RefactoringCoreMessages.ChangeSignatureRefactoring_old_and_new_signatures_not_sufficiently_different));
        String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(getMethodName()));
        ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
        fRippleMethods = RippleMethodFinder2.getRelatedMethods(fMethod, binaryRefs, new SubProgressMonitor(pm, 1), null);
        result.merge(checkVarargs());
        if (result.hasFatalError())
            return result;
        fOccurrences = findOccurrences(new SubProgressMonitor(pm, 1), binaryRefs, result);
        binaryRefs.addErrorIfNecessary(result);
        result.merge(checkVisibilityChanges());
        result.merge(checkTypeVariables());
        if (!isOrderSameAsInitial())
            result.merge(checkReorderings(new SubProgressMonitor(pm, 1)));
        else
            pm.worked(1);
        if (!areNamesSameAsInitial())
            result.merge(checkRenamings(new SubProgressMonitor(pm, 1)));
        else
            pm.worked(1);
        if (result.hasFatalError())
            return result;
        //			resolveTypesWithoutBindings(new SubProgressMonitor(pm, 1)); // already done in checkSignature(true)
        createChangeManager(new SubProgressMonitor(pm, 1), result);
        fCachedTypeHierarchy = null;
        if (mustAnalyzeAstOfDeclaringCu())
            //TODO: should also check in ripple methods (move into createChangeManager)
            result.merge(checkCompilationofDeclaringCu());
        if (result.hasFatalError())
            return result;
        Checks.addModifiedFilesToChecker(getAllFilesToModify(), context);
        return result;
    } finally {
        pm.done();
    }
}
Also used : TightSourceRangeComputer(org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer) ReferencesInBinaryContext(org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 55 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor 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)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)217 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)54 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)40 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 ArrayList (java.util.ArrayList)36 IFile (org.eclipse.core.resources.IFile)33 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)30 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IPath (org.eclipse.core.runtime.IPath)17 IResource (org.eclipse.core.resources.IResource)16 IProject (org.eclipse.core.resources.IProject)15 File (java.io.File)14 List (java.util.List)13 IMethod (org.eclipse.jdt.core.IMethod)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 HashMap (java.util.HashMap)12