Search in sources :

Example 6 with PerformanceStats

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

Aggregations

PerformanceStats (org.eclipse.core.runtime.PerformanceStats)6 CoreException (org.eclipse.core.runtime.CoreException)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IProject (org.eclipse.core.resources.IProject)1 InvalidRegistryObjectException (org.eclipse.core.runtime.InvalidRegistryObjectException)1 Status (org.eclipse.core.runtime.Status)1 ElementChangedEvent (org.eclipse.jdt.core.ElementChangedEvent)1 IElementChangedListener (org.eclipse.jdt.core.IElementChangedListener)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1