From 229beeac63ed66d85bef3aeb18d0a623149781bb Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Thu, 5 Oct 2023 13:33:46 -0400 Subject: [PATCH] Clean up new o.e.core.resources.undo.snapshot API to make it more usable Signed-off-by: Rob Stryker --- .../undo/snapshot/AbstractResourceSnapshot.java | 2 +- .../resources/undo/snapshot/ContainerSnapshot.java | 12 +++--------- .../resources/undo/snapshot/FileSnapshot.java | 7 ++++--- .../resources/undo/snapshot/FolderSnapshot.java | 4 ++-- .../resources/undo/snapshot/ProjectSnapshot.java | 3 ++- .../resources/undo/snapshot/IResourceSnapshot.java | 8 ++------ 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/AbstractResourceSnapshot.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/AbstractResourceSnapshot.java index 0e00f2fdc24..5149d97a5b0 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/AbstractResourceSnapshot.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/AbstractResourceSnapshot.java @@ -83,7 +83,7 @@ protected AbstractResourceSnapshot(T resource) { @Override public T createResource(IProgressMonitor monitor) throws CoreException { T resource = createResourceHandle(); - createExistentResourceFromHandle(resource, monitor); + createExistentResourceFromHandle(monitor); restoreResourceAttributes(resource); return resource; } diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ContainerSnapshot.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ContainerSnapshot.java index 9b2bc6d18b4..89536121c25 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ContainerSnapshot.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ContainerSnapshot.java @@ -19,9 +19,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; - import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceFilterDescription; @@ -183,20 +181,16 @@ protected final void createChildResources(IContainer parentHandle, } @Override - public void recordStateFromHistory(T resource, IProgressMonitor mon) throws CoreException { + public void recordStateFromHistory(IProgressMonitor mon) throws CoreException { if (members != null) { SubMonitor subMonitor = SubMonitor.convert(mon, ResourceSnapshotMessages.FolderDescription_SavingUndoInfoProgress, members.size()); for (IResourceSnapshot member : members) { SubMonitor iterationMonitor = subMonitor.split(1); if (member instanceof FileSnapshot fileSnapshot) { - IPath path = resource.getFullPath().append(fileSnapshot.name); - IFile fileHandle = resource.getWorkspace().getRoot().getFile(path); - fileSnapshot.recordStateFromHistory(fileHandle, iterationMonitor); + fileSnapshot.recordStateFromHistory(iterationMonitor); } else if (member instanceof FolderSnapshot folderSnapshot) { - IPath path = resource.getFullPath().append(folderSnapshot.name); - IFolder folderHandle = resource.getWorkspace().getRoot().getFolder(path); - folderSnapshot.recordStateFromHistory(folderHandle, iterationMonitor); + folderSnapshot.recordStateFromHistory(iterationMonitor); } } } diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FileSnapshot.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FileSnapshot.java index 7ada4b15001..d03bc3a24de 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FileSnapshot.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FileSnapshot.java @@ -94,8 +94,8 @@ public FileSnapshot(IFile file, URI linkLocation, } @Override - public void recordStateFromHistory(IFile resource, - IProgressMonitor monitor) throws CoreException { + public void recordStateFromHistory(IProgressMonitor monitor) throws CoreException { + IFile resource = createResourceHandle(); Assert.isLegal(resource.getType() == IResource.FILE); if (location != null) { // file is linked, no need to record any history @@ -131,7 +131,8 @@ public IFile createResourceHandle() { } @Override - public void createExistentResourceFromHandle(IFile fileHandle, IProgressMonitor mon) throws CoreException { + public void createExistentResourceFromHandle(IProgressMonitor mon) throws CoreException { + IFile fileHandle = createResourceHandle(); if (fileHandle.exists()) { return; } diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FolderSnapshot.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FolderSnapshot.java index bb06251a2a6..8b4454b3001 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FolderSnapshot.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/FolderSnapshot.java @@ -16,7 +16,6 @@ package org.eclipse.core.internal.resources.undo.snapshot; import java.net.URI; - import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceFilterDescription; @@ -74,7 +73,8 @@ public IFolder createResourceHandle() { } @Override - public void createExistentResourceFromHandle(final IFolder folderHandle, IProgressMonitor mon) throws CoreException { + public void createExistentResourceFromHandle(IProgressMonitor mon) throws CoreException { + IFolder folderHandle = createResourceHandle(); if (folderHandle.exists()) { return; } diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ProjectSnapshot.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ProjectSnapshot.java index 65e01f8410b..8a46d55079d 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ProjectSnapshot.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/undo/snapshot/ProjectSnapshot.java @@ -78,7 +78,8 @@ public IProject createResourceHandle() { } @Override - public void createExistentResourceFromHandle(IProject projectHandle, IProgressMonitor monitor) throws CoreException { + public void createExistentResourceFromHandle(IProgressMonitor monitor) throws CoreException { + IProject projectHandle = createResourceHandle(); SubMonitor subMonitor = SubMonitor.convert(monitor, 200); if (projectHandle.exists()) { return; diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/undo/snapshot/IResourceSnapshot.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/undo/snapshot/IResourceSnapshot.java index 0ba394767d9..fc0f97b5f36 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/undo/snapshot/IResourceSnapshot.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/undo/snapshot/IResourceSnapshot.java @@ -61,13 +61,11 @@ public interface IResourceSnapshot { * Given a resource handle, create an actual resource with the attributes of * the receiver resource description. * - * @param resource - * the resource handle * @param monitor * the progress monitor to be used when creating the resource * @throws CoreException if creation failed */ - public void createExistentResourceFromHandle(T resource, IProgressMonitor monitor) throws CoreException; + public void createExistentResourceFromHandle(IProgressMonitor monitor) throws CoreException; /** * Return a boolean indicating whether this resource description has enough @@ -82,13 +80,11 @@ public interface IResourceSnapshot { * Record the appropriate state of this resource description using * any available resource history. * - * @param resource - * the resource whose state is to be recorded. * @param monitor * the progress monitor to be used * @throws CoreException in case of error */ - public void recordStateFromHistory(T resource, IProgressMonitor monitor) throws CoreException; + public void recordStateFromHistory(IProgressMonitor monitor) throws CoreException; /** * Return a boolean indicating whether this description represents an