Search in sources :

Example 1 with ISourceManipulation

use of org.eclipse.jdt.core.ISourceManipulation in project che by eclipse.

the class DeleteSourceManipulationChange method doDelete.

/*
	 * @see DeleteChange#doDelete(IProgressMonitor)
	 */
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
    ISourceManipulation element = getSourceManipulation();
    // since the primary working copy still exists.
    if (element instanceof ICompilationUnit) {
        //$NON-NLS-1$
        pm.beginTask("", 2);
        ICompilationUnit unit = (ICompilationUnit) element;
        saveCUnitIfNeeded(unit, new SubProgressMonitor(pm, 1));
        IResource resource = unit.getResource();
        ResourceDescription resourceDescription = ResourceDescription.fromResource(resource);
        element.delete(false, new SubProgressMonitor(pm, 1));
        resourceDescription.recordStateFromHistory(resource, new SubProgressMonitor(pm, 1));
        return new UndoDeleteResourceChange(resourceDescription);
    } else if (element instanceof IPackageFragment) {
        ICompilationUnit[] units = ((IPackageFragment) element).getCompilationUnits();
        //$NON-NLS-1$
        pm.beginTask("", units.length + 1);
        for (int i = 0; i < units.length; i++) {
            // fix https://bugs.eclipse.org/bugs/show_bug.cgi?id=66835
            saveCUnitIfNeeded(units[i], new SubProgressMonitor(pm, 1));
        }
        element.delete(false, new SubProgressMonitor(pm, 1));
        // caveat: real undo implemented by UndoablePackageDeleteChange
        return new NullChange();
    } else {
        element.delete(false, pm);
        //should not happen
        return null;
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) ISourceManipulation(org.eclipse.jdt.core.ISourceManipulation) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Aggregations

IResource (org.eclipse.core.resources.IResource)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ISourceManipulation (org.eclipse.jdt.core.ISourceManipulation)1 NullChange (org.eclipse.ltk.core.refactoring.NullChange)1 ResourceDescription (org.eclipse.ui.ide.undo.ResourceDescription)1